Ejemplo n.º 1
0
    def test_countdown_24_days(self, db):
        now = dt.datetime.now()
        event_dt = now + dt.timedelta(days=24)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == event_dt.astimezone(pytz.timezone(Config.TIME_ZONE))
        assert timesince(event.countdown, until=True) == "3 weeks to go"
Ejemplo n.º 2
0
    def test_countdown_10_days(self, db):
        timezone = pytz.timezone(Config.TIME_ZONE)
        now = dt.datetime.now()
        event_dt = now + dt.timedelta(days=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == timezone.localize(event_dt)
        assert timesince(event.countdown, until=True) == "1 week to go"
Ejemplo n.º 3
0
    def test_countdown_4_hours(self, db):
        now = dt.datetime.now()
        # need to add 10 seconds to avoid timesince to compute 3.9999h
        # formated to 3 by timesince
        event_dt = now + dt.timedelta(hours=4, seconds=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == event_dt.astimezone(pytz.timezone(Config.TIME_ZONE))
        assert timesince(event.countdown, until=True) == "4 hours to go"
        
Ejemplo n.º 4
0
 def data(self):
     return {
         'id': self.id,
         'name': self.name,
         'time': int(mktime(self.timestamp.timetuple())),
         'timesince': timesince(self.timestamp),
         'date': self.timestamp,
         'content': self.content or '',
         'user_name': self.user.username,
         'user_id': self.user.id,
         'project_id': self.project.id,
         'project_name': self.project.name,
         'project_score': self.project_score or 0,
         'project_phase': getProjectPhase(self.project),
         'resource_id': self.resource_id,
         'resource_type': getResourceType(self.resource),
     }
Ejemplo n.º 5
0
    def test_countdown_4_hours(self, db):
        timezone = pytz.timezone(Config.TIME_ZONE)
        now = dt.datetime.now()
        tz_now = timezone.localize(dt.datetime.utcnow())
        # need to add 10 seconds to avoid timesince to compute 3.9999h
        # formated to 3 by timesince
        event_dt = now + dt.timedelta(hours=4, seconds=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        tz_event = timezone.localize(event_dt)
        timediff = tz_event - tz_now
        timediff_hours = timediff.total_seconds() // 3600

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == tz_event
        assert timesince(event.countdown,
                         until=True) == "%d hours to go" % timediff_hours
Ejemplo n.º 6
0
 def data(self):
     localtime = current_app.tz.localize(self.timestamp)
     a = {
         'id': self.id,
         'time': int(mktime(self.timestamp.timetuple())),
         'date': format_date(localtime, '%Y-%m-%dT%H:%M'),
         'timesince': timesince(localtime),
         'name': self.name,
         'action': self.action or '',
         'content': self.content or '',
         'ref_url': self.ref_url or '',
     }
     if self.user:
         a['user_id'] = self.user.id
         a['user_name'] = self.user.username
     if self.project:
         a['project_id'] = self.project.id
         a['project_name'] = self.project.name
         a['project_score'] = self.project_score or 0
         a['project_phase'] = getProjectPhase(self.project)
     return a
Ejemplo n.º 7
0
 def until_date(value):
     return timesince(value, default="now!", until=True)
Ejemplo n.º 8
0
 def since_date(value):
     return timesince(value)
Ejemplo n.º 9
0
 def since(self):
     return timesince(self.created_at)
Ejemplo n.º 10
0
Archivo: app.py Proyecto: loleg/dribdat
 def until_date(value):
     return timesince(value, default="now!", until=True)
Ejemplo n.º 11
0
Archivo: app.py Proyecto: loleg/dribdat
 def since_date(value):
     return timesince(value)