Пример #1
0
    def test_datetime_with_time_zone(self):
        oldDefaultTimeZone = TimeZone.getDefault()
        try:
            TimeZone.setDefault(TimeZone.getTimeZone("GMT+4"))
            c = tWithDateTimeZCursor(self.context)

            zoneId = ZoneId.of("GMT+2")
            #This is the datetime we will insert
            localDateTime = LocalDateTime.of(2017, Month.DECEMBER, 31, 22, 0,
                                             0)
            zonedDateTime = ZonedDateTime.of(localDateTime, zoneId)
            #This is the datetime we expect the database to receive
            utcDateTime = LocalDateTime.of(2018, Month.JANUARY, 1, 0, 0, 0)

            c.eventDate = zonedDateTime
            c.insert()
            c.clear()

            c.first()

            zoneIdAfterSelect = ZoneId.of("GMT+4")
            self.assertEquals(utcDateTime, c.eventDate.toLocalDateTime())
            self.assertEquals(zoneIdAfterSelect, c.eventDate.getZone())

        finally:
            TimeZone.setDefault(oldDefaultTimeZone)
Пример #2
0
    def test_mat_view_date_rounding(self):
        tableCursor = table3Cursor(self.context)
        mViewCursor = mView4Cursor(self.context)

        tableCursor.deleteAll()
        self.assertEquals(0, mViewCursor.count())

        datetime1 = LocalDateTime.of(2000, Month.AUGUST, 5, 10, 5, 32)
        date1 = datetime1.truncatedTo(ChronoUnit.DAYS)

        tableCursor.numb = 5
        tableCursor.date = Timestamp.valueOf(datetime1)
        tableCursor.insert()
        tableCursor.clear()

        datetime2 = LocalDateTime.of(2000, Month.AUGUST, 5, 22, 5, 32)
        tableCursor.numb = 2
        tableCursor.date = Timestamp.valueOf(datetime2)
        tableCursor.insert()
        tableCursor.clear()

        datetime3 = LocalDateTime.of(2000, Month.AUGUST, 6, 10, 5, 32)
        date2 = datetime3.truncatedTo(ChronoUnit.DAYS)
        tableCursor.numb = 5
        tableCursor.date = Timestamp.valueOf(datetime3)
        tableCursor.insert()
        tableCursor.clear()

        self.assertEquals(2, mViewCursor.count())
        mViewCursor.get(Timestamp.valueOf(date1))
        self.assertEquals(7, mViewCursor.s)

        mViewCursor.get(Timestamp.valueOf(date2))
        self.assertEquals(5, mViewCursor.s)
Пример #3
0
 def onConfigure(self):
     self.withArgs([
         DateTimeType("dateTime").withDateTime().withMinValue(
             LocalDateTime.of(2020, 1, 1, 0, 0)).withMaxValue(
                 LocalDateTime.of(2030, 1, 1, 0, 0)),
         DateTimeType("dateTimeZone").withDateTimeZone(),
         DateTimeType("date").withDate().withFormat("yyyy-MM-dd"),
         DateTimeType("time").withTime().withFormat("HH:mm:ss"),
         DateTimeType("instant").withInstant()
     ]).withResult(ListType(DynamicType()))
Пример #4
0
def jdatetime(t):
    """
    Convert python date to joda DateTime.
    
    :param t: Python date
    
    :returns: Joda DateTime
    """
    if isinstance(t, (list, tuple)):
        r = []
        for tt in t:
            r.append(LocalDateTime.of(tt.year, tt.month, tt.day, tt.hour, tt.minute, tt.second, tt.microsecond / 1000))
        return r
    else:
        return LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second, t.microsecond / 1000)
Пример #5
0
 def dt_gen(inc_days):
     with jvm():
         from java.time import LocalDateTime
         from java.time.format import DateTimeFormatter
         dt = LocalDateTime.of(2019, 11, 26, 16, 30, 0)
         dtfmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
         for inc in range(1, inc_days + 1):
             yield dt.plusDays(inc).format(dtfmt)
Пример #6
0
 def onConfigure(self):
     self.withLabel("Action with a date/time argument")
     self.withArg(
         DateTimeType("dateTime").withDateTime().withFormat(
             "yyyy-MM-dd HH:mm").withMinValue(
                 LocalDateTime.of(2020, 1, 1, 0,
                                  0)).withLabel("Date and time"))
     self.withResult(StringType().withLabel("Formatted text"))
     self.withFeature("icon", "timer")
Пример #7
0
def jdate(t):
    """
    Convert python date to java LocalDateTime.
    
    :param t: Python date
    
    :returns: Java date
    """
    if isinstance(t, list):
        r = []
        for tt in t:
            t = LocalDateTime.of(tt.year, tt.month, tt.day, tt.hour, tt.minute, tt.second)
            #cal.set(Calendar.MILLISECOND, 0)
            r.append(t)
        return r
    else:
        t = LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second)
        #cal.set(Calendar.MILLISECOND, 0)
        return t
Пример #8
0
    def test_getXRec(self):
        cursor = tXRecCursor(self.context)
        cursor.deleteAll()

        id = 1
        num = 10
        cost = 10.2
        title = 'product'
        isActive = True
        created = Timestamp.valueOf(
            LocalDateTime.of(2018, Month.of(1), 11, 19, 15))

        cursor.num = num
        cursor.cost = cost
        cursor.title = title
        cursor.isActive = isActive
        cursor.created = created

        xRec = cursor.getXRec()
        self._assertXRecCursorFields(xRec, None, None, None, None, None, None)
        cursor.insert()

        self._assertXRecCursorFields(xRec, None, None, None, None, None, None)
        cursor.clear()

        xRec = cursor.getXRec()
        self._assertXRecCursorFields(xRec, None, None, None, None, None, None)

        cursor.get(1)
        self._assertXRecCursorFields(xRec, id, num, cost, title, isActive,
                                     created)

        cursor.num = num + 1
        cursor.cost = cost + 1
        cursor.title = title + 'asd'
        cursor.isActive = False
        cursor.created = Timestamp.valueOf(
            LocalDateTime.of(2017, Month.of(1), 11, 19, 15))

        self._assertXRecCursorFields(xRec, id, num, cost, title, isActive,
                                     created)
Пример #9
0
    def onConfigure(self):
        self.withLabel("Type date-time arg action")
        self.withArgs([
            DateTimeType("arg").withLabel("Date-time non nullable").withDefaultValue(LocalDateTime.of(2020, 1, 1, 12, 0)),
            DateTimeType("argNullable").withLabel("Date-time nullable").withNullable(),
            DateTimeType("argDefault").withLabel("Date-time with default").withDefaultValue(LocalDateTime.of(2020, 1, 1, 12, 0)),
            DateTimeType("argReadOnlyNullable").withLabel("Date-time read only nullable").withReadOnly().withNullable()
                .withDefaultValue(LocalDateTime.of(2020, 1, 1, 12, 0)),
            DateTimeType("argReadOnlyNonNullable").withLabel("Date-time read only non nullable").withReadOnly()
                .withDefaultValue(LocalDateTime.of(2020, 1, 1, 12, 0)),

            DateTimeType("argDate").withDate().withLabel("Date non nullable").withDefaultValue(LocalDate.of(2020, 1, 1)),
            DateTimeType("argDateNullable").withDate().withLabel("Date nullable").withNullable(),
            DateTimeType("argDateDefault").withDate().withLabel("Date with default").withDefaultValue(LocalDate.of(2020, 1, 1)),
            DateTimeType("argDateReadOnlyNullable").withDate().withLabel("Date read only nullable").withReadOnly().withNullable()
                .withDefaultValue(LocalDate.of(2020, 1, 1)),
            DateTimeType("argDateReadOnlyNonNullable").withDate().withLabel("Date read only non nullable").withReadOnly()
                .withDefaultValue(LocalDate.of(2020, 1, 1)),

            DateTimeType("argTime").withTime().withFormat("HH:mm").withLabel("Time non nullable").withDefaultValue(LocalTime.of(12, 0)),
            DateTimeType("argTimeNullable").withTime().withFormat("HH:mm").withLabel("Time nullable").withNullable(),
            DateTimeType("argTimeDefault").withTime().withFormat("HH:mm").withLabel("Time with default").withDefaultValue(LocalTime.of(12, 0)),
            DateTimeType("argTimeReadOnlyNullable").withTime().withFormat("HH:mm").withLabel("Time read only nullable").withReadOnly().withNullable()
                .withDefaultValue(LocalTime.of(12, 0)),
            DateTimeType("argTimeReadOnlyNonNullable").withTime().withFormat("HH:mm").withLabel("Time read only non nullable").withReadOnly()
                .withDefaultValue(LocalTime.of(12, 0)),

            DateTimeType("argDateTimeZoneReadOnlyNullable").withDateTimeZone().withLabel("Date-time-zone read only nullable").withReadOnly().withNullable()
                .withDefaultValue(ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 12, 0), ZoneId.of("America/Detroit"))),
            DateTimeType("argDateTimeZoneReadOnlyNonNullable").withDateTimeZone().withLabel("Date-time-zone read only non nullable").withReadOnly()
                .withDefaultValue(ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 12, 0), ZoneId.of("America/Detroit"))),

            DateTimeType("argInstantReadOnlyNullable").withInstant().withLabel("Instant read only nullable").withReadOnly().withNullable()
                .withDefaultValue(Instant.now()),
            DateTimeType("argInstantReadOnlyNonNullable").withInstant().withLabel("Instant read only non nullable").withReadOnly()
                .withDefaultValue(Instant.now()),

            # DATE_TIME_ZONE and INSTANT editing is not supported yet.
        ]).withResult(StringType())
Пример #10
0
 def onCall(self, type):
     if type == "nonNullable":
         return DynamicValue(LocalDateTime.of(2020, 1, 1, 12, 0), DateTimeType().withLabel("Date-time non nullable"))
     elif type == "nullable":
         return DynamicValue(None, DateTimeType().withLabel("Date-time nullable").withNullable())
     elif type == "readOnlyNullable":
         return DynamicValue(None, DateTimeType().withLabel("Date-time read only nullable").withReadOnly().withNullable())
     elif type == "readOnlyNonNullable":
         return DynamicValue(LocalDateTime.of(2020, 1, 1, 12, 0), DateTimeType().withLabel("Date-time read only non nullable").withReadOnly())
     if type == "dateNonNullable":
         return DynamicValue(LocalDate.of(2020, 1, 1), DateTimeType().withDate().withLabel("Date non nullable"))
     elif type == "dateNullable":
         return DynamicValue(None, DateTimeType().withDate().withLabel("Date nullable").withNullable())
     elif type == "dateReadOnlyNullable":
         return DynamicValue(None, DateTimeType().withDate().withLabel("Date read only nullable").withReadOnly().withNullable())
     elif type == "dateReadOnlyNonNullable":
         return DynamicValue(LocalDate.of(2020, 1, 1), DateTimeType().withDate().withLabel("Date-time read only non nullable").withReadOnly())
     if type == "timeNonNullable":
         return DynamicValue(LocalTime.of(12, 0), DateTimeType().withTime().withFormat("HH:mm").withLabel("Time non nullable"))
     elif type == "timeNullable":
         return DynamicValue(None, DateTimeType().withTime().withFormat("HH:mm").withLabel("Time nullable").withNullable())
     elif type == "timeReadOnlyNullable":
         return DynamicValue(None, DateTimeType().withTime().withFormat("HH:mm").withLabel("Time read only nullable").withReadOnly().withNullable())
     elif type == "timeReadOnlyNonNullable":
         return DynamicValue(LocalTime.of(12, 0), DateTimeType().withTime().withFormat("HH:mm").withLabel("Time read only non nullable").withReadOnly())
     if type == "dateTimeZoneReadOnlyNullable":
         return DynamicValue(None,
                             DateTimeType().withDateTimeZone().withLabel("Date-time-zone read only nullable").withReadOnly().withNullable())
     elif type == "dateTimeZoneReadOnlyNonNullable":
         return DynamicValue(ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 12, 0), ZoneId.of("America/Detroit")),
                             DateTimeType().withDateTimeZone().withLabel("Date-time-zone read only non nullable").withReadOnly())
     if type == "instantReadOnlyNullable":
         return DynamicValue(None, DateTimeType().withInstant().withLabel("Instant read only nullable").withReadOnly().withNullable())
     elif type == "instantReadOnlyNonNullable":
         return DynamicValue(Instant.now(), DateTimeType().withInstant().withLabel("Instant read only non nullable").withReadOnly())
     else:
         return None
Пример #11
0
def saveverifyfile(filename, vtables, times=None):
    """
    Save verification result cvs file.
    
    :param filename: (*string*) Output file name.
    :param vtables: (*list or VerifyTable*) Verification table list.
    :param times: (*list or datetime*) Times corresponding to virification tables.
    """
    if not isinstance(vtables, list):
        vtables = [vtables]
        if not times is None:
            times = [times]
    if times is None:
        VerifyStat.writeVerifyFile(vtables, filename)
    else:
        dates = []
        for t in times:
            d = LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second)
            dates.append(d)
        VerifyStat.writeVerifyFile(vtables, dates, filename)
Пример #12
0
from mil.army.usace.hec.vortex.math import Normalizer
from mil.army.usace.hec.vortex.io import DataReader

from java.time import ZonedDateTime
from java.time import LocalDateTime
from java.time import ZoneId
from java.time import Duration

source = "C:/Temp/qpe.dss"
normals = "C:/Temp/prism.dss"

sourceGrids = DataReader.getVariables(source)
normalGrids = DataReader.getVariables(normals)

start = ZonedDateTime.of(LocalDateTime.of(2017, 1, 1, 0, 0), ZoneId.of("UTC"))
end = ZonedDateTime.of(LocalDateTime.of(2017, 1, 3, 0, 0), ZoneId.of("UTC"))
interval = Duration.ofDays(1)

destination = 'C:/Temp/normalized.dss'

options = {'partF': 'my normalized grids'}

normalizer = Normalizer.builder() \
    .startTime(start) \
    .endTime(end) \
    .interval(interval) \
    .pathToSource(source) \
    .sourceVariables(sourceGrids) \
    .pathToNormals(normals) \
    .normalsVariables(normalGrids) \
    .destination(destination) \