def test_past_datetime_str_over_years_ago(self): day = datetime.now() - timedelta(days=366) self.assertEquals(past_datetime_str(day), 'over 1 year ago') day = datetime.now() - timedelta(days=730) self.assertEquals(past_datetime_str(day), 'over 1 year ago') day = datetime.now() - timedelta(days=731) self.assertEquals(past_datetime_str(day), 'over 2 years ago') day = datetime.now() - timedelta(days=1095) self.assertEquals(past_datetime_str(day), 'over 2 years ago')
def test_past_datetime_str_today(self): now = datetime.now() t1 = datetime(now.year, now.month, now.day, 0, 0, 0) self.assertEquals(past_datetime_str(t1), 'today at 12:00 AM') t1 = datetime(now.year, now.month, now.day, 1) self.assertEquals(past_datetime_str(t1), 'today at 1:00 AM') t1 = datetime(now.year, now.month, now.day, 11) self.assertEquals(past_datetime_str(t1), 'today at 11:00 AM') t1 = datetime(now.year, now.month, now.day, 12) self.assertEquals(past_datetime_str(t1), 'today at 12:00 PM') t1 = datetime(now.year, now.month, now.day, 13) self.assertEquals(past_datetime_str(t1), 'today at 1:00 PM')
def test_past_datetime_str_days_ago(self): day = datetime.now() - timedelta(days=2) self.assertEquals(past_datetime_str(day), '2 days ago') day = datetime.now() - timedelta(days=3) self.assertEquals(past_datetime_str(day), '3 days ago') day = datetime.now() - timedelta(days=4) self.assertEquals(past_datetime_str(day), '4 days ago') day = datetime.now() - timedelta(days=5) self.assertEquals(past_datetime_str(day), '5 days ago') day = datetime.now() - timedelta(days=6) self.assertEquals(past_datetime_str(day), '6 days ago')
def get_timestamp_str(last_updated_datetime, use_custom_date_format): if last_updated_datetime is None: return None if use_custom_date_format: return past_datetime_str(last_updated_datetime) else: return str(last_updated_datetime)
def test_past_datetime_str_over_weeks_ago(self): day = datetime.now() - timedelta(days=8) self.assertEquals(past_datetime_str(day), 'over 1 week ago') day = datetime.now() - timedelta(days=14) self.assertEquals(past_datetime_str(day), 'over 1 week ago') day = last_midnight() - timedelta(days=14) self.assertEquals(past_datetime_str(day), 'over 2 weeks ago') day = datetime.now() - timedelta(days=15) self.assertEquals(past_datetime_str(day), 'over 2 weeks ago') day = datetime.now() - timedelta(days=21) self.assertEquals(past_datetime_str(day), 'over 2 weeks ago') day = last_midnight() - timedelta(days=21) self.assertEquals(past_datetime_str(day), 'over 3 weeks ago') day = datetime.now() - timedelta(days=22) self.assertEquals(past_datetime_str(day), 'over 3 weeks ago') day = datetime.now() - timedelta(days=28) self.assertEquals(past_datetime_str(day), 'over 3 weeks ago')
def test_past_datetime_str_over_months_ago(self): day = datetime.now() - timedelta(days=29) self.assertEquals(past_datetime_str(day), 'over 1 month ago') day = datetime.now() - timedelta(days=56) self.assertEquals(past_datetime_str(day), 'over 1 month ago') day = datetime.now() - timedelta(days=57) self.assertEquals(past_datetime_str(day), 'over 2 months ago') day = datetime.now() - timedelta(days=84) self.assertEquals(past_datetime_str(day), 'over 2 months ago') day = datetime.now() - timedelta(days=85) self.assertEquals(past_datetime_str(day), 'over 3 months ago') day = datetime.now() - timedelta(days=112) self.assertEquals(past_datetime_str(day), 'over 3 months ago')
def test_past_datetime_str_a_week_ago(self): day = datetime.now() - timedelta(days=7) self.assertEquals(past_datetime_str(day), '1 week ago')
def test_past_datetime_str_yesterday(self): day = datetime.now() - timedelta(days=1) t2 = datetime(day.year, day.month, day.day, 0, 0, 0) self.assertEquals(past_datetime_str(t2), 'yesterday at 12:00 AM') t2 = datetime(day.year, day.month, day.day, 1,) self.assertEquals(past_datetime_str(t2), 'yesterday at 1:00 AM')