Class PackedInstant

  • Direct Known Subclasses:
    PackedLocalDateTime

    public class PackedInstant
    extends Object
    A short localdatetime packed into a single long value. The long is comprised of an int for the date and an int for the time

    The bytes are packed into the date int as: First two bytes: short (year) next byte (month of year) last byte (day of month)

    The bytes are packed into the time int as First byte: hourOfDay next byte: minuteOfHour last two bytes (short): millisecond of minute

    Storing the millisecond of minute in an short requires that we treat the short as if it were unsigned. Unfortunately, Neither Java nor Guava provide unsigned short support so we use char, which is a 16-bit unsigned int to store values of up to 60,000 milliseconds (60 secs * 1000)

    • Constructor Detail

      • PackedInstant

        protected PackedInstant()
    • Method Detail

      • asInstant

        public static Instant asInstant​(long dateTime)
      • pack

        public static long pack​(Instant instant)
      • date

        public static int date​(long packedDateTIme)
      • time

        public static int time​(long packedDateTIme)
      • toString

        public static String toString​(long dateTime)
      • plus

        public static long plus​(long packedDateTime,
                                long amountToAdd,
                                TemporalUnit unit)
        Returns the given packedDateTime with amtToAdd of temporal units added

        TODO(lwhite): Replace with a native implementation that doesn't convert everything to Instant

      • isAfter

        public static boolean isAfter​(long packedDateTime,
                                      long value)
      • isBefore

        public static boolean isBefore​(long packedDateTime,
                                       long value)
      • create

        public static long create​(int date,
                                  int time)
      • minutesUntil

        public static long minutesUntil​(long packedDateTimeEnd,
                                        long packedDateTimeStart)
      • hoursUntil

        public static long hoursUntil​(long packedDateTimeEnd,
                                      long packedDateTimeStart)
      • daysUntil

        public static int daysUntil​(long packedDateTimeEnd,
                                    long packedDateTimeStart)
      • weeksUntil

        public static int weeksUntil​(long packedDateTimeEnd,
                                     long packedDateStart)
      • isEqualTo

        public static boolean isEqualTo​(long packedDateTime,
                                        long value)
      • isOnOrAfter

        public static boolean isOnOrAfter​(long valueToTest,
                                          long valueToTestAgainst)
      • isOnOrBefore

        public static boolean isOnOrBefore​(long valueToTest,
                                           long valueToTestAgainst)