Ejemplo n.º 1
0
 def test_convert_universal_to_local(self):  # noqa
     """Convert universal time to local time"""
     univ = self.sometime_univ
     self.assertEquals(times.to_local(univ, 'Europe/Amsterdam'),
                       self.time_in_ams)
     self.assertEquals(times.to_local(univ, 'EST'),
                       self.time_in_ny)
Ejemplo n.º 2
0
 def test_convert_universal_to_local(self):
     """Convert universal time to local time"""
     univ = self.sometime_univ
     self.assertEquals(
             times.to_local(univ, pytz.timezone('Europe/Amsterdam')),
             self.sometime_in_amsterdam)
     self.assertEquals(
             times.to_local(univ, pytz.timezone('EST')),
             self.sometime_in_newyork)
Ejemplo n.º 3
0
 def timezone(self, zone):
     """
     Change the time zone and affect the current moment's time. Note, a
     locality must already be set.
     """
     date = self._date
     try:
         date = times.to_local(times.to_universal(date), zone)
     except:
         date = times.to_local(date, zone)
     finally:
         self._date = date
     return self
Ejemplo n.º 4
0
 def timezone(self, zone):
     """
     Change the time zone and affect the current moment's time. Note, a
     locality must already be set.
     """
     date = self._date
     try:
         date = times.to_local(times.to_universal(date), zone)
     except:
         date = times.to_local(date, zone)
     finally:
         self._date = date
     return self
Ejemplo n.º 5
0
def localtime(value, tz=None):
    from engineer.conf import settings

    if tz is None:
        tz = settings.POST_TIMEZONE

    return times.to_local(value, tz)
Ejemplo n.º 6
0
def localtime(value, tz=None):
    from engineer.conf import settings

    if tz is None:
        tz = settings.POST_TIMEZONE

    return times.to_local(value, tz)
Ejemplo n.º 7
0
def create_event():
    form = EventForm()

    if form.validate_on_submit():
        event = Event()
        with db.transaction as session:
            event.name = form.name.data
            event.venue = form.venue.data
            event.description = form.description.data
            event.user = current_user
            event.starts_at = times.to_universal(form.starts_at.data, current_user.timezone)
            session.add(event)
        with db.transaction:
            event.contacts_invited_ids_str = form.contacts_invited_ids_str.data
        send_email_invites(event)
        return redirect(url_for('facebook_event', id=event.id))

    else:
        # default starts_at
        td = datetime.timedelta(days=1)
        dt = times.to_local(times.now(), current_user.timezone) + td
        dt = datetime.datetime.combine(dt.date(), datetime.time(20, 00, 00))
        form.starts_at.data = dt

    return render_template('create_event.html', form=form)
Ejemplo n.º 8
0
Archivo: todo.py Proyecto: HounD/thebot
    def now(self, request):
        """Outputs server time and user time."""

        now = times.now()
        user = request.get_user()
        tz = self._get_user_timezone(user)
        local = times.to_local(now, tz)

        request.respond(u'Server time: {}\nLocal time:{}'.format(now, local))
Ejemplo n.º 9
0
    def now(self, request):
        """Outputs server time and user time."""
        identity = self.bot.get_plugin('identity').get_identity_by_request(request)

        now = times.now()
        tz = self._get_user_timezone(identity)
        local = times.to_local(now, tz)

        request.respond('Server time: {}\nLocal time:{}'.format(now, local))
Ejemplo n.º 10
0
    def now(self, request):
        """Outputs server time and user time."""
        identity = self.bot.get_plugin('identity').get_identity_by_request(
            request)

        now = times.now()
        tz = self._get_user_timezone(identity)
        local = times.to_local(now, tz)

        request.respond('Server time: {}\nLocal time:{}'.format(now, local))
Ejemplo n.º 11
0
def main():
    anvil = Anvil("spectrum")
    anvil.create_session_by_prompting()

    print "collecting related changesets"
    changesets = find_changesets_for_authors(
        anvil, ['Paul Osborne', ], datetime.datetime(2009, 1, 1)).values()[0]

    commit_hour = [times.to_local(c.date_time, 'US/Central').hour
                   for c in changesets]
    pp.hist(commit_hour, 24)
    a = pp.gca()
    a.set_xlim([0, 23])
    pp.show()
Ejemplo n.º 12
0
    def my_tasks(self, request):
        """Show my tasks"""
        identity = self.bot.get_plugin('identity').get_identity_by_request(request)
        tasks = self._get_tasks(identity)

        if tasks:
            tz = self._get_user_timezone(identity)
            hashes, min_len = _gen_hashes(tasks)

            lines = []
            for h, (dt, about, identity_id) in zip(hashes, tasks):
                dt = times.to_local(dt, tz)
                lines.append('{0}) {1:%Y-%m-%d %H:%M} {2}'.format(h[:min_len], dt, about))

            request.respond('\n'.join(lines))
        else:
            request.respond('You have no tasks')
Ejemplo n.º 13
0
Archivo: todo.py Proyecto: HounD/thebot
    def my_tasks(self, request):
        """Show my tasks"""
        user = request.get_user()
        tasks = self._get_tasks(user)

        if tasks:
            tz = self._get_user_timezone(user)
            hashes, min_len = _gen_hashes(tasks)

            lines = []
            for h, (dt, about, request) in zip(hashes, tasks):
                dt = times.to_local(dt, tz)
                lines.append(u'{0}) {1:%Y-%m-%d %H:%M} {2}'.format(h[:min_len], dt, about))

            request.respond(u'\n'.join(lines))
        else:
            request.respond(u'You have no tasks')
Ejemplo n.º 14
0
def inject_info():
    info = cache.cached_call('basic-info', BasicInfo)

    now = times.to_local(times.now(), 'Europe/Prague')
    next_ = now.year if now.month <= 6 else now.year + 1

    try:
        starts_at = info['senior']['starts_at']
    except KeyError:
        starts_at = None

    return {
        'info': info,
        'now': now,
        'volume_year': starts_at.year if starts_at else next_,
        'volume_no': (starts_at.year if starts_at else next_) - 1997,
        'is_past': now.date() >= starts_at if starts_at else True,
    }
Ejemplo n.º 15
0
    def my_tasks(self, request):
        """Show my tasks"""
        identity = self.bot.get_plugin('identity').get_identity_by_request(
            request)
        tasks = self._get_tasks(identity)

        if tasks:
            tz = self._get_user_timezone(identity)
            hashes, min_len = _gen_hashes(tasks)

            lines = []
            for h, (dt, about, identity_id) in zip(hashes, tasks):
                dt = times.to_local(dt, tz)
                lines.append('{0}) {1:%Y-%m-%d %H:%M} {2}'.format(
                    h[:min_len], dt, about))

            request.respond('\n'.join(lines))
        else:
            request.respond('You have no tasks')
Ejemplo n.º 16
0
def date(value, relative=True):
    """Simple, human-readable date."""
    date = value.date() if isinstance(value, datetime.datetime) else value
    today = times.to_local(times.now(), 'Europe/Prague').date()

    if relative:
        if today == date:
            return u'Dnes'
        if date - today == datetime.timedelta(days=1):
            return u'Zítra'

    date_str = value.strftime('%d. %m.')
    date_str = re.sub(r'0+(\d+)', r'\1', date_str)  # strip leading zeros

    weekdays = (u'pondělí', u'úterý', u'středa', u'čtvrtek',
                u'pátek', u'sobota', u'neděle')
    weekday_str = weekdays[value.weekday()].capitalize()

    result = u'{weekday} {date}'.format(weekday=weekday_str, date=date_str)
    result = result.replace(' ', u'\u00A0')  # no-break spaces
    return result
Ejemplo n.º 17
0
def date(value, relative=True):
    """Simple, human-readable date."""
    date = value.date() if isinstance(value, datetime.datetime) else value
    today = times.to_local(times.now(), 'Europe/Prague').date()

    if relative:
        if today == date:
            return u'Dnes'
        if date - today == datetime.timedelta(days=1):
            return u'Zítra'

    date_str = value.strftime('%d. %m.')
    date_str = re.sub(r'0+(\d+)', r'\1', date_str)  # strip leading zeros

    weekdays = (u'pondělí', u'úterý', u'středa', u'čtvrtek', u'pátek',
                u'sobota', u'neděle')
    weekday_str = weekdays[value.weekday()].capitalize()

    result = u'{weekday} {date}'.format(weekday=weekday_str, date=date_str)
    result = result.replace(' ', u'\u00A0')  # no-break spaces
    return result
Ejemplo n.º 18
0
 def callback(key, value):
     if key in keys:
         return times.to_local(value, self.timezone)
Ejemplo n.º 19
0
def time(value):
    """Simple, human-readable time."""
    return times.to_local(value, 'Europe/Prague').strftime('%H:%M')
Ejemplo n.º 20
0
 def test_convert_refuses_local_to_local(self):
     """Refuses to convert between timezones directly"""
     loc = self.time_in_ams
     with self.assertRaises(ValueError):
         times.to_local(loc, 'Europe/Amsterdam')
Ejemplo n.º 21
0
def make_local_timestamp(timestamp, timezone='Europe/Madrid'):
    if not timestamp:
        return None
    if isinstance(timestamp, basestring):
        timestamp = times.parse(timestamp.replace('Z', ''))
    return times.to_local(timestamp, timezone).strftime('%Y-%m-%d %H:%M:%S')
Ejemplo n.º 22
0
def make_local_timestamp(timestamp, timezone='Europe/Madrid'):
    if not timestamp:
        return None
    if isinstance(timestamp, basestring):
        timestamp = times.parse(timestamp.replace('Z', ''))
    return times.to_local(timestamp, timezone).strftime('%Y-%m-%d %H:%M:%S')
Ejemplo n.º 23
0
 def test_convert_refuses_local_to_local(self):
     """Refuses to convert between timezones directly"""
     loc = self.time_in_ams
     with self.assertRaises(ValueError):
         times.to_local(loc, pytz.timezone('Europe/Amsterdam'))
Ejemplo n.º 24
0
def localize_dt(value):
    return times.to_local(value, 'Europe/Kiev')
Ejemplo n.º 25
0
def time(value):
    """Simple, human-readable time."""
    return times.to_local(value, 'Europe/Prague').strftime('%H:%M')
Ejemplo n.º 26
0
def now():
    return times.to_local(times.now(), 'Europe/Prague')