Example #1
0
 def localize_datetime(self, user, datetime_in_UTC):
     day_service = DayService(user)
     local_timezone = day_service.get_timezone_at(datetime_in_UTC)
     if isinstance(datetime_in_UTC, datetime):
         return datetime_in_UTC.astimezone(local_timezone)
     else:
         return datetime(datetime_in_UTC.year, datetime_in_UTC.month, datetime_in_UTC.day, tzinfo=local_timezone)
Example #2
0
 def timezone(self):
     if hasattr(self, '_timezone'):
         return self._timezone
     service = DayService(user = self.user)
     tz = service.get_timezone_at(self.time)
     self._timezone = tz
     return self._timezone
Example #3
0
 def localize_time(self, time):
     day_service = DayService(self.__user)
     local_timezone = day_service.get_timezone_at(time)
     if isinstance(time, datetime):
         return time.astimezone(local_timezone)
     else:
         return datetime(time.year, time.month, time.day, tzinfo=local_timezone)
     return time.astimezone(local_timezone)
Example #4
0
def activity_log_updates_day(sender, instance, *args, **kwargs):
    activity_log = instance

    day_service = DayService(user=activity_log.user)
    local_timezone = day_service.get_timezone_at(activity_log.start)
    local_time = activity_log.start.astimezone(local_timezone)
    local_date = date(local_time.year, local_time.month, local_time.day)

    for day in list_and_create_day(activity_log.user, local_date):
        day.update_from_activities()
Example #5
0
 def daily_update(self, instance):
     if instance.daily_task:
         next_run_datetime = instance.daily_task.get_next_run_time()
         day_service = DayService(user = instance.user)
         timezone = day_service.get_timezone_at(next_run_datetime)
         corrected_datetime = next_run_datetime.astimezone(timezone)
         if next_run_datetime:
             return 'Next update at %s (%s)' % (corrected_datetime.strftime('%Y-%m-%d %H:%M'), timezone.zone)
     else:
         return 'No daily update'
Example #6
0
 def get_datetime_on(self, date):
     service = DayService(user = self.user)
     tz = service.get_timezone_at(date)
     local_date = service.get_date_at(date)
     dt = datetime(
         local_date.year,
         local_date.month,
         local_date.day,
         self.hour,
         self.minute
     )
     return tz.localize(dt)
Example #7
0
    def get_time_of_day_context(self):
        service = DayService(user = self.decision.user)
        local_timezone = service.get_timezone_at(self.decision.time)
        local_time = self.decision.time.astimezone(local_timezone)

        start_of_day = local_time.replace(hour=8, minute=0)
        morning_end = local_time.replace(hour=10, minute=30)
        lunch_end = local_time.replace(hour=13, minute=30)
        afternoon_end = local_time.replace(hour=16, minute=30)
        evening_end = local_time.replace(hour=18, minute=30)
        end_of_day = local_time.replace(hour=20, minute=0)

        if start_of_day < self.decision.time <= morning_end:
            return 'morning'
        if morning_end < self.decision.time <= lunch_end:
            return 'lunch'
        if lunch_end < self.decision.time <= afternoon_end:
            return 'midafternoon'
        if afternoon_end < self.decision.time <= evening_end:
            return 'evening'
        if evening_end < self.decision.time <= end_of_day:
            return 'postdinner'
Example #8
0
 def get_timezone(self):
     service = DayService(user=self.user)
     return service.get_timezone_at(self.date)
Example #9
0
 def get_message_decision_time(self, date):
     service = DayService(user=self.__user)
     timezone = service.get_timezone_at(date)
     return timezone.localize(
         datetime(date.year, date.month, date.day, 6, 0))
Example #10
0
 def timezone(self):
     if hasattr(self, '__timezone'):
         return self.__timezone
     service = DayService(user=self.user)
     self.__timezone = service.get_timezone_at(self.date)
     return self.__timezone