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)
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)
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
def localtime(value, tz=None): from engineer.conf import settings if tz is None: tz = settings.POST_TIMEZONE return times.to_local(value, tz)
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)
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))
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))
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))
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()
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')
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')
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, }
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')
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
def callback(key, value): if key in keys: return times.to_local(value, self.timezone)
def time(value): """Simple, human-readable time.""" return times.to_local(value, 'Europe/Prague').strftime('%H:%M')
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')
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')
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'))
def localize_dt(value): return times.to_local(value, 'Europe/Kiev')
def now(): return times.to_local(times.now(), 'Europe/Prague')