def _display_time_zone_helper(self, time_zone_string): """ Helper function to return all info from get_display_time_zone() """ tz_str = get_display_time_zone(time_zone_string) time_zone = timezone(time_zone_string) tz_abbr = get_time_zone_abbr(time_zone) tz_offset = get_time_zone_offset(time_zone) return {'str': tz_str, 'abbr': tz_abbr, 'offset': tz_offset}
def start_datetime_text(self, format_string="SHORT_DATE", time_zone=utc): """Returns the desired text representation of the CCX start datetime The returned value is in specified time zone, defaulted to UTC. """ i18n = self.course.runtime.service(self.course, "i18n") strftime = i18n.strftime value = strftime(self.start.astimezone(time_zone), format_string) if format_string == 'DATE_TIME': value += ' ' + get_time_zone_abbr(time_zone, self.start) return value
def end_datetime_text(self, format_string="SHORT_DATE", time_zone=utc): """Returns the desired text representation of the CCX due datetime If the due date for the CCX is not set, the value returned is the empty string. The returned value is in specified time zone, defaulted to UTC. """ if self.due is None: return '' i18n = self.course.runtime.service(self.course, "i18n") strftime = i18n.strftime value = strftime(self.due.astimezone(time_zone), format_string) if format_string == 'DATE_TIME': value += ' ' + get_time_zone_abbr(time_zone, self.due) return value
def _datetime_to_string(date_time, format_string, time_zone, strftime_localized): """ Formats the given datetime with the given function and format string. Adds time zone abbreviation to the resulting string if the format is DATE_TIME or TIME. Arguments: date_time (datetime): the datetime to be formatted format_string (str): the date format type, as passed to strftime time_zone (pytz time zone): the time zone to convert to strftime_localized ((datetime, str) -> str): a nm localized string formatting function """ result = strftime_localized(date_time.astimezone(time_zone), format_string) abbr = get_time_zone_abbr(time_zone, date_time) return (result + ' ' + abbr if format_string in ['DATE_TIME', 'TIME', 'DAY_AND_TIME'] else result)
def _datetime_to_string(date_time, format_string, time_zone, strftime_localized): """ Formats the given datetime with the given function and format string. Adds time zone abbreviation to the resulting string if the format is DATE_TIME or TIME. Arguments: date_time (datetime): the datetime to be formatted format_string (str): the date format type, as passed to strftime time_zone (pytz time zone): the time zone to convert to strftime_localized ((datetime, str) -> str): a nm localized string formatting function """ result = strftime_localized(date_time.astimezone(time_zone), format_string) abbr = get_time_zone_abbr(time_zone, date_time) return ( result + ' ' + abbr if format_string in ['DATE_TIME', 'TIME', 'DAY_AND_TIME'] else result )
def date_format(self): return u'%b %d, %Y (%H:%M {tz_abbr})'.format(tz_abbr=get_time_zone_abbr(self.time_zone))
def date_format(self): return u'%b %d, %Y (%H:%M {tz_abbr})'.format( tz_abbr=get_time_zone_abbr(self.time_zone))