def create_form_data(self, start_diff, end_diff, event=None, special=False, special_text=""): return { "start_time": date_to_local(timezone.now() + timedelta( hours=start_diff)).strftime("%d.%m.%Y %H:%M:%S"), "end_time": date_to_local(timezone.now() + timedelta( hours=end_diff)).strftime("%d.%m.%Y %H:%M:%S"), "event": event is not None, "event_pk": 0 if event is None else event.pk, "special": special, "special_text": special_text, "machine_type": SewingMachine.literal, "machine_name": self.machine.pk }
def test_date_to_local(self): self.assertEqual( datetime(2018, 3, 12, 11, 20, 20).date(), date_to_local( timezone.datetime(2018, 3, 12, 10, 20, 20, tzinfo=timezone.utc)).date()) self.assertEqual( datetime(2018, 3, 12, 11, 20, 20).time(), date_to_local( timezone.datetime(2018, 3, 12, 10, 20, 20, tzinfo=timezone.utc)).time())
def date_to_percentage(date): try: date = date_to_local(date) except ValueError: pass return (date.hour / 24 + date.minute / 1440) * 100