How to use the datetime.time function in DateTime

To help you get started, we’ve selected a few DateTime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IronLanguages / ironpython2 / Tests / modules / misc / test_datetime.py View on Github external
y = datetime.time(1, 2, 33, 445)
        self.assertTrue(not(x==y))
        self.assertTrue(x==datetime.time(1, 2, 33, 444))

        #inequality
        x = datetime.time(1, 2, 33, 444)
        y = None
        self.assertTrue(x!=y)
        y = datetime.time(1, 2, 33, 445)
        self.assertTrue(x!=y)

        #ge
        self.assertTrue(datetime.time(1, 2, 33, 444) >= datetime.time(1, 2, 33, 444))
        self.assertTrue(datetime.time(1, 2, 33, 445) >= datetime.time(1, 2, 33, 444))
        self.assertTrue(datetime.time(1, 2, 33, 446) >= datetime.time(1, 2, 33, 444))
        self.assertTrue(not (datetime.time(1, 2, 33, 443) >= datetime.time(1, 2, 33, 444)))
        self.assertTrue(not (datetime.time(1, 2, 33, 442) >= datetime.time(1, 2, 33, 444)))

        #le
        self.assertTrue(datetime.time(1, 2, 33, 444) <= datetime.time(1, 2, 33, 444))
        self.assertTrue(datetime.time(1, 2, 33, 444) <= datetime.time(1, 2, 33, 445))
        self.assertTrue(datetime.time(1, 2, 33, 444) <= datetime.time(1, 2, 33, 446))
        self.assertTrue(not (datetime.time(1, 2, 33, 444) <= datetime.time(1, 2, 33, 443)))
        self.assertTrue(not (datetime.time(1, 2, 33, 444) <= datetime.time(1, 2, 33, 442)))

        #gt
        self.assertTrue(not (datetime.time(1, 2, 33, 444) > datetime.time(1, 2, 33, 444)))
        self.assertTrue(datetime.time(1, 2, 33, 445) > datetime.time(1, 2, 33, 444))
        self.assertTrue(datetime.time(1, 2, 33, 446) > datetime.time(1, 2, 33, 444))
        self.assertTrue(not (datetime.time(1, 2, 33, 443) > datetime.time(1, 2, 33, 444)))
        self.assertTrue(not (datetime.time(1, 2, 33, 442) > datetime.time(1, 2, 33, 444)))
github django-oscar / django-oscar / tests / integration / forms / test_widget.py View on Github external
def test_timepickerinput_format_unicode(self):
        # Check that the widget can handle unicode formats
        i = widgets.TimePickerInput(format=u'Ï„-%H:%M')
        time = datetime.time(10, 47)
        html = i.render('time', time)
        self.assertIn(u'value="Ï„-10:47"', html)
github jedie / django-reversion-compare / reversion_compare / tests.py View on Github external
def create_VariantModel_data(self):
        with reversion.create_revision():
            item = VariantModel.objects.create(
                integer = 0,
                boolean = False,
                positive_integer = 0,
                big_integer = 0,
                time = datetime.time(hour=20, minute=15),
                date = datetime.date(year=1941, month=5, day=12), # Z3 was presented in germany ;)
                # PyLucid v0.0.1 release date:
                datetime = datetime.datetime(year=2005, month=8, day=19, hour=8, minute=13, second=24),
                decimal = 0,
                float = 0,
                ip_address = "192.168.0.1",
            )

        if self.verbose:
            print("version 1:", item)

        return item
github AppScale / appscale / AppServer / google / appengine / cron / groctimespecification.py View on Github external
def _GetTime(time_string):
  """Converts a string to a datetime.time object.

  Arguments:
    time_string: a string representing a time ('hours:minutes')

  Returns:
    a datetime.time object
  """
  hourstr, minutestr = time_string.split(':')
  return datetime.time(int(hourstr), int(minutestr))
github p2pu / learning-circles / studygroups / forms.py View on Github external
'venue_website': _('Link to any website that has more info about the venue or learning circle.'),
            'start_date': _('Give yourself at least 4 weeks to advertise, if possible.'),
            'duration': _('We recommend 90 - 120 minutes.'),
            'image': _('Make your learning circle stand out with a picture or .gif. It could be related to location, subject matter, or anything else you want to identify with!'),
        }
        widgets = {
            'latitude': forms.HiddenInput,
            'longitude': forms.HiddenInput,
            'place_id': forms.HiddenInput,
            'country': forms.HiddenInput,
            'region': forms.HiddenInput,
        }


class MeetingForm(forms.ModelForm):
    meeting_time = forms.TimeField(input_formats=['%I:%M %p'], initial=datetime.time(16))
    class Meta:
        model = Meeting
        fields = ['meeting_date', 'meeting_time', 'study_group']
        widgets = {'study_group': forms.HiddenInput}


class DigestGenerateForm(forms.Form):
    start_date = forms.DateField()
    end_date = forms.DateField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.add_input(Submit('submit', 'Generate'))
github Khan / frankenserver / python / google / appengine / ext / db / __init__.py View on Github external
def make_value_from_datastore(self, value):
    """Native representation of this property.

    If this list is a list of datetime.date or datetime.time, we convert
    the list of datetime.datetime retrieved from the entity into
    datetime.date or datetime.time.

    See base class method documentation for details.
    """

    if self.item_type == datetime.date:
      for v in value:
        assert isinstance(v, datetime.datetime)
      value = map(lambda x: x.date(), value)
    elif self.item_type == datetime.time:
      for v in value:
        assert isinstance(v, datetime.datetime)
      value = map(lambda x: x.time(), value)

    return value
github Parisson / TeleForma / teleforma / models / appointment.py View on Github external
def end(self):
        dt = datetime.datetime.combine(datetime.date.today(), self.start) + datetime.timedelta(
            minutes=self.appointment_period.appointment_slot_size)
        return datetime.time(dt.hour, dt.minute, 0)
github Gahshomar / gahshomar / src / khayyam / jalali_datetime.py View on Github external
def time(self):
        return time(self.hour, self.minute, self.second, self.microsecond)
github badoo / pyexasol / examples / 00_prepare.py View on Github external
def random_ts():
    date = random_date()
    time = datetime.time(random.randint(0, 23), random.randint(0,59), random.randint(0,59), random.randint(0, 999) * 1000)

    return datetime.datetime.combine(date, time)
github michael-donat / tf-mapper / formlayout.py View on Github external
value = float(QLocale().toDouble(field.text())[0])
            elif isinstance(value, int):
                value = int(field.value())
            elif isinstance(value, datetime.datetime):
                value = field.dateTime()
                try:
                    value = value.toPyDateTime()  # PyQt
                except AttributeError:
                    value = value.toPython()  # PySide
            elif isinstance(value, datetime.date):
                value = field.date()
                try:
                    value = value.toPyDate()  # PyQt
                except AttributeError:
                    value = value.toPython()  # PySide
            elif isinstance(value, datetime.time):
                value = field.time()
                try:
                    value = value.toPyTime()  # PyQt
                except AttributeError:
                    value = value.toPython()  # PySide
            else:
                value = eval(str(field.text()))
            if isinstance(field, CountLayout):
                value = (value, field.n())
            valuelist.append((label, value))
        if self.result == 'list':
            return [value for label, value in valuelist]
        elif self.result in ['dict', 'OrderedDict', 'JSON']:
            if self.result == 'dict':
                dic = {}
            else: