def test_basics(self): app = flask.Flask(__name__) b = babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010 1:46:00 PM' assert babel.format_date(d) == 'Apr 12, 2010' assert babel.format_time(d) == '1:46:00 PM' with app.test_request_context(): app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna' assert babel.format_datetime(d) == 'Apr 12, 2010 3:46:00 PM' assert babel.format_date(d) == 'Apr 12, 2010' assert babel.format_time(d) == '3:46:00 PM' with app.test_request_context(): app.config['BABEL_DEFAULT_LOCALE'] = 'de_DE' assert babel.format_datetime(d, 'long') == \ '12. April 2010 15:46:00 MESZ'
def get_readable(self, row): row_timestamp = row[self.name] yday_now = time.localtime().tm_yday tm_year_now = time.localtime().tm_year yday_row = time.localtime(row_timestamp).tm_yday tm_year_row = time.localtime(row_timestamp).tm_year if yday_now == yday_row and tm_year_now == tm_year_row: return format_time(datetime.fromtimestamp(row_timestamp)) else: return format_datetime(datetime.fromtimestamp(row_timestamp), 'short')