本文整理汇总了Python中timezones.utils.adjust_datetime_to_timezone函数的典型用法代码示例。如果您正苦于以下问题:Python adjust_datetime_to_timezone函数的具体用法?Python adjust_datetime_to_timezone怎么用?Python adjust_datetime_to_timezone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了adjust_datetime_to_timezone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_model
def save_model(self, request, obj, form, change):
utz = request.user.get_profile().timezone
if obj.start:
obj.start = adjust_datetime_to_timezone(obj.start, utz, TZ)
if obj.end:
obj.end = adjust_datetime_to_timezone(obj.end, utz, TZ)
obj.save()
示例2: created_local
def created_local(self):
if hasattr(self.service.user, 'get_profile'):
return adjust_datetime_to_timezone(
self.created,
'UTC',
unicode(self.service.user.get_profile().timezone)
)
else:
return adjust_datetime_to_timezone(self.created, 'UTC', TIME_ZONE)
示例3: created_local
def created_local(self):
"""Calculate the created time using timexone to give a datetime
in the users time zone."""
if hasattr(self, 'created'):
if hasattr(self.user, 'get_profile'):
return adjust_datetime_to_timezone(self.created, 'UTC', unicode(self.user.get_profile().timezone))
else:
return adjust_datetime_to_timezone(self.created, 'UTC', TIME_ZONE)
else:
return None
示例4: get_ievent
def get_ievent(request, d, event_id):
from django.conf import settings
from timezones.utils import adjust_datetime_to_timezone
from events.models import Event
site_url = get_setting('site', 'global', 'siteurl')
event = Event.objects.get(id=event_id)
e_str = "BEGIN:VEVENT\n"
# organizer
organizers = event.organizer_set.all()
if organizers:
organizer_name_list = [organizer.name for organizer in organizers]
e_str += "ORGANIZER:%s\n" % (', '.join(organizer_name_list))
# date time
if event.start_dt:
start_dt = adjust_datetime_to_timezone(event.start_dt, settings.TIME_ZONE, 'GMT')
start_dt = start_dt.strftime('%Y%m%dT%H%M%SZ')
e_str += "DTSTART:%s\n" % (start_dt)
if event.end_dt:
end_dt = adjust_datetime_to_timezone(event.end_dt, settings.TIME_ZONE, 'GMT')
end_dt = end_dt.strftime('%Y%m%dT%H%M%SZ')
e_str += "DTEND:%s\n" % (end_dt)
# location
if event.place:
e_str += "LOCATION:%s\n" % (event.place.name)
e_str += "TRANSP:OPAQUE\n"
e_str += "SEQUENCE:0\n"
# uid
e_str += "UID:uid%[email protected]%s\n" % (event.pk, d['domain_name'])
event_url = "%s%s" % (site_url, reverse('event', args=[event.pk]))
d['event_url'] = event_url
# text description
e_str += "DESCRIPTION:%s\n" % (build_ical_text(event,d))
# html description
e_str += "X-ALT-DESC;FMTTYPE=text/html:%s\n" % (build_ical_html(event,d))
e_str += "SUMMARY:%s\n" % strip_tags(event.title)
e_str += "PRIORITY:5\n"
e_str += "CLASS:PUBLIC\n"
e_str += "BEGIN:VALARM\n"
e_str += "TRIGGER:-PT30M\n"
e_str += "ACTION:DISPLAY\n"
e_str += "DESCRIPTION:Reminder\n"
e_str += "END:VALARM\n"
e_str += "END:VEVENT\n"
return e_str
示例5: forwards
def forwards(self, orm):
all_news = orm['news.News'].objects.all()
now = datetime.datetime.now()
now_with_tz = adjust_datetime_to_timezone(now, settings.TIME_ZONE)
for news in all_news:
if news.timezone and news.release_dt and news.timezone.zone != settings.TIME_ZONE:
time_diff = adjust_datetime_to_timezone(now, news.timezone) - now_with_tz
news.release_dt_local = news.release_dt + time_diff
else:
news.release_dt_local = news.release_dt
# only update the release_dt_local field
orm['news.News'].objects.filter(id=news.id).update(release_dt_local=news.release_dt_local)
示例6: forwards
def forwards(self, orm):
articles = orm['articles.Article'].objects.all()
now = datetime.datetime.now()
now_with_tz = adjust_datetime_to_timezone(now, settings.TIME_ZONE)
for article in articles:
if article.timezone and article.release_dt and article.timezone.zone != settings.TIME_ZONE:
time_diff = adjust_datetime_to_timezone(now, article.timezone) - now_with_tz
article.release_dt_local = article.release_dt + time_diff
else:
article.release_dt_local = article.release_dt
# only update the release_dt_local field
orm['articles.Article'].objects.filter(id=article.id).update(release_dt_local=article.release_dt_local)
示例7: coerce_datetime_tz
def coerce_datetime_tz(self, datetime):
server_tz = settings.TIME_ZONE
if self.instance is None or self.instance.creator is None:
user_tz = self.creator.get_profile().timezone
else:
user_tz = self.instance.creator.get_profile().timezone
return tz_utils.adjust_datetime_to_timezone(datetime, user_tz, server_tz)
示例8: test_adjust_datetime_to_timezone
def test_adjust_datetime_to_timezone(self):
self.assertEqual(
adjust_datetime_to_timezone(
datetime(2008, 6, 25, 18, 0, 0), "UTC"
).strftime("%m/%d/%Y %H:%M:%S"),
"06/25/2008 18:00:00"
)
示例9: local_send_time
def local_send_time(self):
if self.billee.timezone:
return adjust_datetime_to_timezone(
self.send_date,
settings.TIME_ZONE,
self.billee.timezone
)
return self.send_date
示例10: clean_end
def clean_end (self):
date = self.cleaned_data["end"]
if self.timezone:
print "IN CLEAN END EDIT"
print date
date = adjust_datetime_to_timezone (date, self.timezone)
print date
return date
示例11: clean_start
def clean_start (self):
date = self.cleaned_data["start"]
if self.timezone:
print "IN CLEAN START EDIT"
print date
date = adjust_datetime_to_timezone (date, self.timezone)
print date
return date
示例12: stop_date_localized
def stop_date_localized(self):
"""
return localized stop date
"""
from timezones.utils import adjust_datetime_to_timezone
return adjust_datetime_to_timezone(
self.stop_date,
settings.TIME_ZONE,
self.user.get_profile().timezone)
示例13: clean_completed_at
def clean_completed_at(self):
value = self.cleaned_data['completed_at']
if value is None:
return value
time_zone = self.task.user.get_profile().time_zone
localtime = value.replace(tzinfo=pytz.timezone(time_zone))
utctime = adjust_datetime_to_timezone(localtime, time_zone, 'UTC')
utctime_raw = utctime.replace(tzinfo=None)
return utctime_raw
示例14: localize_date
def localize_date(value, to_tz=None):
from timezones.utils import adjust_datetime_to_timezone
try:
if to_tz is None:
to_tz = settings.UI_TIME_ZONE
from_tz = settings.TIME_ZONE
return adjust_datetime_to_timezone(value, from_tz=from_tz, to_tz=to_tz)
except AttributeError:
return ''
示例15: assign_release_dt_local
def assign_release_dt_local(self):
"""
convert release_dt to the corresponding local time
example:
if
release_dt: 2014-05-09 03:30:00
timezone: US/Pacific
settings.TIME_ZONE: US/Central
then
the corresponding release_dt_local will be: 2014-05-09 05:30:00
"""
now = datetime.now()
now_with_tz = adjust_datetime_to_timezone(now, settings.TIME_ZONE)
if self.timezone and self.release_dt and self.timezone.zone != settings.TIME_ZONE:
time_diff = adjust_datetime_to_timezone(now, self.timezone) - now_with_tz
self.release_dt_local = self.release_dt + time_diff
else:
self.release_dt_local = self.release_dt