Пример #1
0
    def testConversionFromString(self):
        """
        Coverage tests for converting strings of various forms to DateTime, Period, or nanosecond time (period)
        """

        # TODO: Methods which almost certainly have no business being wrapped...
        #   convertExpression(string), expressionToNanos(string), getFinestDefinedUnit(string)

        with self.subTest(msg="convertDateTime"):
            junk = DateTimeUtils.convertDateTime(
                "2018-11-13T15:00:00.000000 NY")
        with self.subTest(msg="convertDateTimeQuiet"):
            junk = DateTimeUtils.convertDateTimeQuiet(
                "2018-11-13T15:00:00.000000 NY")

        # appear to operate on string formatted as <days>T<hh>:<mm>:<ss>.<fractional seconds up to nanos>
        # NB: the documentation sucks, and I'm just guessing
        with self.subTest(msg="convertTime"):
            junk = DateTimeUtils.convertTime("1T02:04:16.3264128")
        with self.subTest(msg="convertTimeQuiet"):
            junk = DateTimeUtils.convertTimeQuiet("1T02:04:16.3264128")

        # appear to operate on string formatted as <years>Y<months>M<weeks>W<days>D<hours>H<minutes>M<seconds>S
        #   all literals could be upper or lower case
        # NB: the documentation sucks, and I'm mostly guessing
        with self.subTest(msg="convertPeriod"):
            junk = DateTimeUtils.convertPeriod("1Y1M1W1DT1H1M1S")
        with self.subTest(msg="convertPeriodQuiet"):
            junk = DateTimeUtils.convertPeriodQuiet("1Y1M1W1DT1H1M1S")
Пример #2
0
    def testArithmetic(self):
        """
        Coverage test of DateTime arithmetic helper methods
        """

        with self.subTest(msg="secondsToNanos"):
            junk = DateTimeUtils.secondsToNanos(1)
        with self.subTest(msg="millisToNanos"):
            junk = DateTimeUtils.millisToNanos(1)
        with self.subTest(msg="microsToNanos"):
            junk = DateTimeUtils.microsToNanos(1)
        with self.subTest(msg="nanosToMicros"):
            junk = DateTimeUtils.nanosToMicros(1000)
        with self.subTest(msg="nanosToMillis"):
            junk = DateTimeUtils.nanosToMillis(1000000)

        # get current time
        now = DateTimeUtils.currentTime()
        period = DateTimeUtils.convertPeriod("1D")  # returns a Period object
        # various plus/minus signatures
        with self.subTest(msg="plus(DateTime, long"):
            now2 = DateTimeUtils.plus(now,
                                      6000000000)  # shift forward by an hour
        with self.subTest(msg="plus(DateTime, Period"):
            junk = DateTimeUtils.plus(now, period)  # shift forward by a day
        with self.subTest(msg="minus(DateTime, long"):
            junk = DateTimeUtils.minus(now,
                                       6000000000)  # shift back by an hour
        with self.subTest(msg="minus(DateTime, DateTime"):
            junk = DateTimeUtils.minus(now2, now)
        with self.subTest(msg="minus(DateTime, Period)"):
            junk = DateTimeUtils.minus(now2, period)

        # other style date subtractions
        with self.subTest(msg="diffYear"):
            junk = DateTimeUtils.diffYear(now2, now)
        with self.subTest(msg="diffDay"):
            junk = DateTimeUtils.diffDay(now2, now)
        with self.subTest(msg="diffNanos"):
            junk = DateTimeUtils.diffNanos(now2, now)

        with self.subTest(msg="isAfter"):
            junk = DateTimeUtils.isAfter(now2, now)
        with self.subTest(msg="isBefore"):
            junk = DateTimeUtils.isBefore(now2, now)

        with self.subTest(msg="lowerBin"):
            junk = DateTimeUtils.lowerBin(now, 1000000000)
        with self.subTest(msg="upperBin"):
            junk = DateTimeUtils.upperBin(now, 1000000000)