def format_time_24hour(time_val, gconf_client, display_seconds=True, show_timezone=False): """ Format a given time / datetime as a time in the 24hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object / tuple gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format_24hr", locale.nl_langinfo(locale.T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def format_time_24hour(time_val, gconf_client, display_seconds = True, show_timezone = False): """ Format a given time / datetime as a time in the 24hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object / tuple gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format_24hr", locale.nl_langinfo(locale.T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def format_date(date_val, gconf_client): """ Format a datetime as a date (without time). GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: date_val -- date / datetime object gconf_client -- gconf client instance """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/date_format", locale.nl_langinfo(locale.D_FMT)) if isinstance(date_val, tuple): return datetime.date.strftime(fmt, date_val) else: return date_val.strftime(fmt)
def format_date_time(date_val, gconf_client, display_seconds = True): """ Format a datetime as a date and a time. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: date_val -- date / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/date_time_format", locale.nl_langinfo(locale.D_T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(date_val, tuple): return datetime.datetime.strftime(fmt, date_val) else: return date_val.strftime(fmt)
def format_date_time(date_val, gconf_client, display_seconds=True): """ Format a datetime as a date and a time. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: date_val -- date / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/date_time_format", locale.nl_langinfo(locale.D_T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(date_val, tuple): return datetime.datetime.strftime(fmt, date_val) else: return date_val.strftime(fmt)
def format_time(time_val, gconf_client, display_seconds=True, show_timezone=False, compact=True): """ Format a given time / datetime as a time in the 12hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format", locale.nl_langinfo(locale.T_FMT_AMPM)) # For some locales T_FMT_AMPM is empty. # Set the format to a default value if this is the case. if fmt == "": fmt = "%r" if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") if compact: fmt = fmt.replace(" %p", "%p") fmt = fmt.replace(" %P", "%P") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def format_time(time_val, gconf_client, display_seconds = True, show_timezone = False, compact = True): """ Format a given time / datetime as a time in the 12hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format", locale.nl_langinfo(locale.T_FMT_AMPM)) # For some locales T_FMT_AMPM is empty. # Set the format to a default value if this is the case. if fmt == "": fmt = "%r" if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") if compact: fmt = fmt.replace(" %p", "%p") fmt = fmt.replace(" %P", "%P") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def get_string_or_default(gconf_client, key, default=None): return g15gconf.get_string_or_default(gconf_client, key, default)