Ejemplo n.º 1
0
def test_iso_format_with_time_zone_case_1():
    # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_iso_format_with_time_zone_case_1
    expected = DateTime(2019, 10, 30, 7, 54, 2.129790999, tzinfo=timezone_utc)
    assert expected.iso_format() == "2019-10-30T07:54:02.129790999+00:00"
    assert expected.tzinfo == FixedOffset(0)
    actual = DateTime.from_iso_format("2019-10-30T07:54:02.129790999+00:00")
    assert expected == actual
Ejemplo n.º 2
0
def test_to_native_case_2():
    # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_to_native_case_2
    dt = DateTime.from_iso_format("2019-10-30T12:34:56.789123456+00:00")
    native = dt.to_native()
    assert native.hour == dt.hour
    assert native.minute == dt.minute
    assert nano_add(native.second, nano_div(native.microsecond, 1000000)) == 56.789123
    assert native.tzinfo == FixedOffset(0)
    assert native.isoformat() == "2019-10-30T12:34:56.789123+00:00"
Ejemplo n.º 3
0
 def test_from_iso_format_with_negative_long_tz(self):
     expected = DateTime(2018,
                         10,
                         1,
                         12,
                         34,
                         56.123456789,
                         tzinfo=FixedOffset(-754))
     actual = DateTime.from_iso_format(
         "2018-10-01T12:34:56.123456789-12:34:56.123456")
     self.assertEqual(expected, actual)
Ejemplo n.º 4
0
    def setModelData(self, editor, model, index):
        '''
        this takes the current value of the editor widget, converts it back to a string and stores it back in the item model
        '''
        dataType = index.data(Qt.UserRole + 1)
        # string, integer, and float use a qlineedit
        if isinstance(editor, QLineEdit):
            if dataType == DataType.DATETIME.value:
                value = editor.text()
                try:
                    aNeoDateTime = DateTime.from_iso_format(value)
                    saveStr = aNeoDateTime.iso_format()
                    model.setData(index, saveStr, Qt.DisplayRole)
                except:
                    self.helper.displayErrMsg(
                        "Date Time",
                        "Entered text [{}] is not a valid ISO date time.".
                        format(value))
                    model.setData(index, value, Qt.DisplayRole)
            elif dataType == DataType.LOCALDATETIME.value:
                value = editor.text()
                try:
                    aNeoDateTime = DateTime.from_iso_format(value)
                    saveStr = aNeoDateTime.iso_format()
                    model.setData(index, saveStr, Qt.DisplayRole)
                except:
                    self.helper.displayErrMsg(
                        "Date Time",
                        "Entered text [{}] is not a valid ISO date time.".
                        format(value))
                    model.setData(index, value, Qt.DisplayRole)
            elif dataType in [DataType.LOCALTIME.value, DataType.TIME.value]:
                value = editor.text()
                try:
                    aNeoTime = Time.from_iso_format(value)
                    saveStr = aNeoTime.iso_format()
                    tz = ""
                    if aNeoTime.tzinfo is not None:
                        offset = aNeoTime.tzinfo.utcoffset(self)
                        tz = "%+03d:%02d" % divmod(
                            offset.total_seconds() // 60, 60)
                    returnStr = "{}{}".format(saveStr, tz)
                    model.setData(index, returnStr, Qt.DisplayRole)
                except:
                    self.helper.displayErrMsg(
                        "Time",
                        "Entered text [{}] is not a valid ISO time.".format(
                            value))
                    model.setData(index, value, Qt.DisplayRole)
            else:
                value = editor.text()
                model.setData(index, value, Qt.DisplayRole)
        # boolean datatype uses a listbox
        elif isinstance(editor, QComboBox):
            value = editor.currentText()
            model.setData(index, value, Qt.DisplayRole)
        elif isinstance(editor, FrmPoint):
            value = editor.getText()
            model.setData(index, value, Qt.DisplayRole)
        elif isinstance(editor, FrmGPoint):
            value = editor.getText()
            model.setData(index, value, Qt.DisplayRole)
#        elif isinstance(editor, FrmTime ):
#            value = editor.getText()
#            model.setData(index, value, Qt.DisplayRole)
#        elif isinstance(editor, FrmDateTime ):
#            value = editor.getText()
#            model.setData(index, value, Qt.DisplayRole)
        elif isinstance(editor, QDateTimeEdit):
            if dataType == DataType.DATE.value:
                value = editor.date().toString(Qt.ISODate)
                model.setData(index, value, Qt.DisplayRole)
Ejemplo n.º 5
0
def test_iso_format_with_time_zone_case_2():
    # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_iso_format_with_time_zone_case_2
    expected = DateTime.from_iso_format("2019-10-30T07:54:02.129790999+01:00")
    assert expected.tzinfo == FixedOffset(60)
    assert expected.iso_format() == "2019-10-30T07:54:02.129790999+01:00"
Ejemplo n.º 6
0
 def test_from_iso_format_hour_minute_second_nanoseconds(self):
     expected = DateTime(2018, 10, 1, 12, 34, 56.123456789)
     actual = DateTime.from_iso_format("2018-10-01T12:34:56.123456789")
     self.assertEqual(expected, actual)
Ejemplo n.º 7
0
 def test_from_iso_format_hour_and_minute(self):
     expected = DateTime(2018, 10, 1, 12, 34, 0)
     actual = DateTime.from_iso_format("2018-10-01T12:34")
     self.assertEqual(expected, actual)
Ejemplo n.º 8
0
 def test_from_iso_format_hour_only(self):
     expected = DateTime(2018, 10, 1, 12, 0, 0)
     actual = DateTime.from_iso_format("2018-10-01T12")
     self.assertEqual(expected, actual)