def format_time(t, format="short", locale=None, timezone=None): """ Basically a wrapper around Babel's own format_time """ if not locale: locale = currentLocale() return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode("utf-8")
def format_timedelta(td, format='short', locale=None): """ Basically a wrapper around Babel's own format_timedelta """ if not locale: locale = currentLocale() return _format_timedelta(td, format=format, locale=locale).encode('utf-8')
def format_date(d, format='medium', locale=None): """ Basically a wrapper around Babel's own format_date """ if not locale: locale = currentLocale() return _format_date(d, format=format, locale=locale).encode('utf-8')
def format_timedelta(td, format='short', locale=None, timezone=None): """ Basically a wrapper around Babel's own format_timedelta """ if not locale: locale = currentLocale() return _format_timedelta(td, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def formatDateTime(dateTime, showWeek=False, format=None, locale=None): week = "" locale = str(locale or currentLocale()) if showWeek: week = "EEEE " if not format: return format_datetime(dateTime, week+'d/M/yyyy H:mm', locale=locale).encode('utf-8') else: return format_datetime(dateTime, format, locale=locale).encode('utf-8')
def format_time(t, format='short', locale=None, timezone=None): """ Basically a wrapper around Babel's own format_time """ if not locale: locale = currentLocale() return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def formatDateTime(dateTime, showWeek=False, format=None, locale=None): week = "" locale = str(locale or currentLocale()) if showWeek: week = "EEEE " if not format: return format_datetime(dateTime, week + 'd/M/yyyy H:mm', locale=locale).encode('utf-8') else: return format_datetime(dateTime, format, locale=locale).encode('utf-8')
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False): """ Basically a wrapper around Babel's own format_datetime """ if not locale: locale = currentLocale() if not timezone and dt.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() return _format_datetime(dt, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def getHTML( self ): res = [] divs = [] for day in self._month.getDayList(): fulldate = "%s%02d%02d" % (self._month.getYear(),self._month.getMonthNumber(),day.getDayNumber()) if day.getDayNumber() == 1: for i in range(day.getWeekDay()): res.append("<td></td>") categs = day.getCategories() if len(categs)>1: colors = [""" <table cellspacing="0" cellpadding="0" border="0" align="left"> <tr>"""] for categ in categs: colors.append("""<td bgcolor="%s"> </td>"""%self._categColors.getColor( categ )) colors.append(""" </tr> </table>""") res.append( """<td align="right" bgcolor="%s" onMouseOver="setOnAnchor('d%s')" onMouseOut="clearOnAnchor('d%s')">%s<span style="cursor: default;" id="a%s">%s</span></td>"""%( self._multipleColor, fulldate, fulldate, "\n".join(colors), fulldate, day.getDayNumber() ) ) divs.append(self._getDiv(day)) elif len(categs) == 1: res.append( """<td align="right" bgcolor="%s" onMouseOver="setOnAnchor('d%s')" onMouseOut="clearOnAnchor('d%s')"><span style="cursor: default;" id="a%s">%s</span></td>"""%( self._categColors.getColor( categs[0] ), fulldate, fulldate, fulldate, day.getDayNumber() ) ) divs.append(self._getDiv(day)) else: res.append( """<td align="right">%s</td>"""%day.getDayNumber() ) if day.getWeekDay() == 6: res.append(""" </tr> <tr>\n""") str = i18nformat(""" <table cellspacing="1" cellpadding="5"> <tr> <td colspan="7" align="center" style="font-size: 1.2em;">%s %s</b></td> </tr> <tr> %s </tr> <tr> %s </tr> </table> %s """) % (self._month.getName(), self._month.getYear(), ''.join(list('<td align="right" bgcolor="#CCCCCC">%s</td>' % currentLocale().weekday(wd)[:2] for wd in xrange(0, 7))), "\n".join(res),"\n".join(divs)) return str
def format_human_date(dt, format='medium', locale=None): """ Return the date in a human-like format for yesterday, today and tomorrow. Format the date otherwise. """ today = nowutc().date() oneday = timedelta(days=1) if not locale: locale = currentLocale() if dt == today - oneday: return _("yesterday") elif dt == today: return _("today") elif dt == today + oneday: return _("tomorrow") else: return format_date(dt, format, locale=locale)
def format_time(t, format='short', locale=None, timezone=None, server_tz=False): """ Basically a wrapper around Babel's own format_time """ if not locale: locale = currentLocale() if not timezone and t.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() if timezone: timezone = get_timezone(timezone) return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False, keep_tz=False): """ Basically a wrapper around Babel's own format_datetime """ if not locale: locale = currentLocale() if keep_tz: assert timezone is None timezone = dt.tzinfo elif not timezone and dt.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() return _format_datetime(dt, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def format_number(number, locale=None): if not locale: locale = currentLocale() return _format_number(number, locale=locale).encode('utf-8')