Class DateTimeZone

    • Field Detail

      • HIGHEST_SPECIAL_DATE_TIME_ZONE

        public static final DateTimeZone HIGHEST_SPECIAL_DATE_TIME_ZONE
        The dates before this should not be considered normal date values.
      • HIGHEST_SPECIAL_DATE_TIME_ZONE_MILLIS

        public static final long HIGHEST_SPECIAL_DATE_TIME_ZONE_MILLIS
      • REQUEUE_MILLIS_LONG

        public static final Long REQUEUE_MILLIS_LONG
      • NOW_MILLIS

        public static final long NOW_MILLIS
        This value will be used as the internal representation of "Now", which can be selected in the DateTimePickerControl/CalendarControl.
        See Also:
        Constant Field Values
      • NOW_MILLIS_LONG

        public static final Long NOW_MILLIS_LONG
      • RECALC_DATE

        public static final DateTimeZone RECALC_DATE
        This value will be set if a field should be recalculated. This is the earliest date that a DateTimeZone can take. Note: only set milliseconds, otherwise the time zone of the job will be reset to GMT. Comparing for this special date must be done on milliseconds.
      • RECALC_MILLIS_LONG

        public static final Long RECALC_MILLIS_LONG
      • NEVER_DATE

        public static final DateTimeZone NEVER_DATE
        This value will be set if a job will not run. This is the latest date that a DateTimeZone can take. Note: only set milliseconds, otherwise the time zone of the job will be reset to GMT. Comparing for this special date must be done on milliseconds.
      • NEVER_MILLIS_LONG

        public static final Long NEVER_MILLIS_LONG
      • MONTHS_IN_YEAR

        public static final int MONTHS_IN_YEAR
        Number of months in year
        See Also:
        Constant Field Values
      • DAYS_IN_WEEK

        public static final int DAYS_IN_WEEK
        Number of days in week
        See Also:
        Constant Field Values
      • WORK_DAYS_IN_WEEK

        public static final int WORK_DAYS_IN_WEEK
        Number of work days in a week
        See Also:
        Constant Field Values
      • HOURS_IN_DAY

        public static final int HOURS_IN_DAY
        Number of hours in day
        See Also:
        Constant Field Values
      • MIN_DAYS_IN_MONTH

        public static final int MIN_DAYS_IN_MONTH
        The minimum number of days in month
        See Also:
        Constant Field Values
      • MAX_DAYS_IN_MONTH

        public static final int MAX_DAYS_IN_MONTH
        The maximum number of days in month
        See Also:
        Constant Field Values
      • MAX_WORK_DAYS_IN_MONTH

        public static final int MAX_WORK_DAYS_IN_MONTH
        The maximum number of workdays in month
        See Also:
        Constant Field Values
      • MAX_WEEKS_IN_MONTH

        public static final int MAX_WEEKS_IN_MONTH
        The maximum number of (partial) weeks in month
        See Also:
        Constant Field Values
      • WORKDAY

        public static final int WORKDAY
        Wildcard for a single day from Monday till Friday
        See Also:
        Constant Field Values
      • WEEKEND

        public static final int WEEKEND
        Wildcard for weekends (Saturday and Sunday). Each WEEKEND consists of two ANYDAYs.
        See Also:
        Constant Field Values
      • WORKWEEK

        public static final int WORKWEEK
        Wildcard for quintents (Monday,…,Friday). Each WORKWEEK consists of 5 WORKDAYs.
        See Also:
        Constant Field Values
      • LASTANYDAY

        public static final int LASTANYDAY
        A special value meaning 'the last day of the month'. It has nothing to do with the day number, while it is always greater than that.
        See Also:
        Constant Field Values
      • LASTWORKDAY

        public static final int LASTWORKDAY
        A special value meaning 'the last working day of the month'. It has nothing to do with the day number, while it is always greater than that.
        See Also:
        Constant Field Values
      • MAX_RECURRENCE_INTERVAL

        public static final int MAX_RECURRENCE_INTERVAL
        The maximum size of an interval that can be specified in a recurrence
        See Also:
        Constant Field Values
      • HOUR_MILLIS

        public static final int HOUR_MILLIS
        Number of milliseconds in an hour.
        See Also:
        Constant Field Values
      • DAY_MILLIS

        public static final int DAY_MILLIS
        Number of milliseconds in an day.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DateTimeZone

        public DateTimeZone()
      • DateTimeZone

        public DateTimeZone​(TimeZone timeZone,
                            long utcMillis)
      • DateTimeZone

        public DateTimeZone​(long utcMillis)
      • DateTimeZone

        public DateTimeZone​(TimeZone timeZone)
      • DateTimeZone

        public DateTimeZone​(TimeZone timeZone,
                            int year,
                            int monthZeroBased,
                            int day,
                            int hour,
                            int minute,
                            int second,
                            int milli)
      • DateTimeZone

        public DateTimeZone​(int year,
                            int monthZeroBased,
                            int day,
                            int hour,
                            int minute,
                            int second,
                            int milli)
      • DateTimeZone

        public DateTimeZone​(DateTimeZone createCopyFrom)
      • DateTimeZone

        public DateTimeZone​(ZonedDateTime newZonedDateTime)
    • Method Detail

      • of

        public static DateTimeZone of​(int year,
                                      int month,
                                      int day,
                                      int hour,
                                      int minute,
                                      int second,
                                      int milli)
        Creates a new DateTimeZone with the specified temporal values and the system-default time zone. Note: this is NOT lenient and will only accept values in the specified ranges.
        Parameters:
        year - the year to represent, from MIN_YEAR to MAX_YEAR
        month - the month-of-year to represent, from 1 (January) to 12 (December)
        day - the day-of-month to represent, from 1 to 31
        hour - the hour-of-day to represent, from 0 to 23
        minute - the minute-of-hour to represent, from 0 to 59
        second - the second-of-minute to represent, from 0 to 59
        milli - the milli-of-second to represent, from 0 to 999
        Returns:
        the offset date-time, not null
        Throws:
        DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-year
      • of

        public static DateTimeZone of​(int year,
                                      int month,
                                      int day,
                                      int hour,
                                      int minute,
                                      int second,
                                      int milli,
                                      ZoneId timeZone)
        Creates a new DateTimeZone with the specified temporal values. Note: this is NOT lenient and will only accept values in the specified ranges.
        Parameters:
        year - the year to represent, from MIN_YEAR to MAX_YEAR
        month - the month-of-year to represent, from 1 (January) to 12 (December)
        day - the day-of-month to represent, from 1 to 31
        hour - the hour-of-day to represent, from 0 to 23
        minute - the minute-of-hour to represent, from 0 to 59
        second - the second-of-minute to represent, from 0 to 59
        milli - the milli-of-second to represent, from 0 to 999
        timeZone - the time-zone, not null
        Returns:
        the offset date-time, not null
        Throws:
        DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-year
      • now

        public static DateTimeZone now()
        Creates a new DateTimeZone at the current system date-time and system-default time zone.
        Returns:
        the current system date-time, not null
      • add

        public void add​(int amount,
                        TimeUnit timeUnit)
      • add

        public void add​(long amount,
                        TimeUnit timeUnit)
        When adding milliseconds, you may want to add more than MAXINT. See Calendar.add(int, TimeUnit)
        Parameters:
        amount - of elements (long) to add
        timeUnit - TimeUnit to add
      • getLowDate

        public static DateTimeZone getLowDate()
        Returns the lowest date we operate with
        Returns:
        the lowest date we operate with
      • getHighDate

        public static DateTimeZone getHighDate()
        Returns the highest date we operate with
        Returns:
        the highest date we operate with
      • getTimeZone

        public TimeZone getTimeZone()
      • setTimeZone

        public void setTimeZone​(TimeZone timeZone)
      • getUTCMilliSecs

        public long getUTCMilliSecs()
      • setUTCMilliSecs

        public void setUTCMilliSecs​(long utcMilliSecs)
      • set

        public void set​(TimeZone timeZone,
                        long utcMilliSecs)
      • setYear

        public void setYear​(int year)
        Sets the year. It is not the same as Calendar.set(Calendar.YEAR,year) because it does not support the batch execution of multiple set-s
        Parameters:
        year - the year to be set
      • getDaysThisMonth

        public int getDaysThisMonth()
        Returns the number of days in this month.
        Returns:
        the number of days in this month
      • truncateSecond

        public void truncateSecond()
        Truncate to the last second. That is, set the time of this object to be that of the beginning of the second, removing the millisecond component.
      • truncateMinute

        public void truncateMinute()
        Truncate to the last minute. That is, set the time of this object to be that of the beginning of the minute, removing second and millisecond components.
      • truncateHour

        public void truncateHour()
        Truncate to the last hour. That is, set the time of this object to be that of the beginning of the hour, removing minute, second and millisecond components.
      • truncateDay

        public void truncateDay()
        Truncate to the beginning of the last day. That is, set the time of this object to be that of the beginning of the day, removing hour, minute, second and millisecond components.
      • truncateMonth

        public void truncateMonth()
        Truncate to the beginning of the last month. That is, set the time of this object to be that of the beginning of the month, removing day, hour, minute, second and millisecond components.
      • truncateYear

        public void truncateYear()
        Truncate to the beginning of the last year. That is, set the time of this object to be that of the beginning of the year, removing month, day, hour, minute, second and millisecond components.
      • isWorkday

        public boolean isWorkday()
        Is the current day one of MONDAY through till FRIDAY?
        Returns:
        Is the current day one of MONDAY through till FRIDAY?
      • set

        public void set​(DateTimeZone toCopyFrom)
        Sets this DateTimeZone from another DateTimeZone.
        Parameters:
        toCopyFrom - to copy from
      • set

        public void set​(int year,
                        int monthZeroBased,
                        int day,
                        int hour,
                        int minute,
                        int second,
                        int milli)
        Sets the year, month, day, hour, minute, second, and milliseconds to the specified values.
        Parameters:
        year -
        monthZeroBased -
        day -
        hour -
        minute -
        second -
        milli -
      • set

        public void set​(int year,
                        int monthZeroBased,
                        int day,
                        int hour,
                        int minute,
                        int second,
                        int milli,
                        TimeZone timeZone)
        Sets the year, month, day, hour, minute, second, and milliseconds to the specified values.
        Parameters:
        year -
        monthZeroBased -
        day -
        hour -
        minute -
        second -
        milli -
        timeZone -
      • add

        public void add​(int addWhat,
                        int value)
        See Calendar.add(int,int)
        Parameters:
        addWhat - date element (int) to add
        value - amount of elements (int) to add
      • add

        public void add​(int addWhat,
                        long value)
        When adding milliseconds, you may want to add more than MAXINT. See Calendar.add(int,int)
        Parameters:
        addWhat - date element (int), i.e. Calendar field to add
        value - amount of elements (int) to add
      • goToNextDayOfWeek

        public void goToNextDayOfWeek​(DayOfWeek weekday)
        Skips to the same time of the next weekday provided
        Parameters:
        weekday - the weekday DayOfWeek.MONDAY..DayOfWeek.SUNDAY to skip to
      • goToNextDayOfWeek

        @Deprecated
        public void goToNextDayOfWeek​(int weekday)
        Deprecated.
        use goToNextDayOfWeek(DayOfWeek weekday) instead
        Skips to the same time of the next weekday provided
        Parameters:
        weekday - the weekday Calendar.SUNDAY..Calendar.SATURDAY to skip to
      • set

        public void set​(int setWhat,
                        int value)
        See Calendar.set(int,int)
        Parameters:
        setWhat - date element (int) to add
        value - amount of elements (int) to add
      • getYear

        public int getYear()
        The current year.
        Returns:
        current year
      • getMonth

        public int getMonth()
        Return the current month of the year, January has a value of zero.
        Returns:
        zero-based month
      • getDayOfYear

        public int getDayOfYear()
        Return the current day of the year, the first day of the year has a value of one.
        Returns:
        day of year
      • getDayOfMonth

        public int getDayOfMonth()
        Return the current day of the month, the first day of the month has a value of one.
        Returns:
        day of month
      • getDayOfWeek

        @Deprecated
        public int getDayOfWeek()
        Deprecated.
        use getTemporalDayOfWeek() to get the day's enum value or get(WeekFields.SUNDAY_START.dayOfWeek()) to get the Calendar day number
        Return the current day of the week, returns one of SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY.
        Returns:
        day of week
      • getTemporalDayOfWeek

        public DayOfWeek getTemporalDayOfWeek()
      • getHour

        public int getHour()
        Return the current hour of the day, this has a range of 0-23.
        Returns:
        the current hour of the day
      • getMinute

        public int getMinute()
        Return the current minute of the hour, this has a range of 0-59
        Returns:
        the current minute of the hour
      • getSecond

        public int getSecond()
        Return the current second of the minute, this has a range of 0-60 to accommodate for leap seconds.
        Returns:
        the current second of the minute
      • getMillisecond

        public int getMillisecond()
        Return the current millisecond of the second, this has a range of 0-999.
        Returns:
        the current millisecond of the second
      • get

        public int get​(int getWhat)
        See Calendar.get(int)
        Parameters:
        getWhat - calendar element to retrieve
        Returns:
        Calendar.get(int)
      • utcEquals

        public boolean utcEquals​(Object aDateTimeZone)
        Checks if two DateTimeZone objects refer to the same moment in time, even in different time zones
        Parameters:
        aDateTimeZone - to compare with
        Returns:
        true if both represent the same moment
      • equals

        public boolean equals​(Object otherObject)
        Checks if two DateTimeZone objects refer to the same moment in time and to the same time zone.
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • calendarDayAsDayOfWeek

        public static DayOfWeek calendarDayAsDayOfWeek​(int calendarWeekday)
                                                throws com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException
        Converts Calendar representation of a weekday (Sunday = 1) to a DayOfWeek
        Parameters:
        calendarWeekday - a constant Calendar.SUNDAY,...,Calendar.SATURDAY
        Returns:
        the DayOfWeek for the given calendarWeekday
        Throws:
        com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException - if calendarWeekday is not in the range 1..7
      • weekdayJavaToOracle

        @Deprecated
        public static int weekdayJavaToOracle​(int weekdayInJava)
                                       throws com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException
        Deprecated.
        This class now uses the java.time framework, which uses Monday-starting weeks; use calendarDayAsDayOfWeek(weekdayInJava).value() instead
        Converts Java representation of a weekday (Sunday = 1) to Oracle (Monday = 1)
        Parameters:
        weekdayInJava - a constant Calendar.SUNDAY,...,Calendar.SATURDAY
        Returns:
        1 (Monday) to 7 (Sunday)
        Throws:
        com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException - if weekdayInJava is not in the range 1..7
      • weekdayJavaToEnglish

        public static String weekdayJavaToEnglish​(int weekdayInJava)
                                           throws com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException
        Spells out a DateTimeZone/Calendar weekday.
        Parameters:
        weekdayInJava - a constant Calendar.SUNDAY,...,Calendar.SATURDAY, DateTimeZone.WEEKEND, DateTimeZone.WORKDAY, DateTimeZone.ANYDAY
        Returns:
        a word in English
        Throws:
        com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException - if weekdayInJava is not in the range 0..9
      • weekdayOracleToJava

        @Deprecated
        public static int weekdayOracleToJava​(int weekdayInOracle)
                                       throws com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException
        Deprecated.
        This class now uses the java.time framework, which uses Monday-starting weeks; use DayOfWeek.of(weekdayInOracle) instead
        Converts Oracle representation of a weekday (Monday = 1, .., Sunday = 7) to Java (Sunday = 1, .., Saturday = 7)
        Parameters:
        weekdayInOracle - Oracle representation of a weekday (Monday = 1, .., Sunday = 7)
        Returns:
        a constant Calendar.SUNDAY,...,Calendar.SATURDAY
        Throws:
        com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException - if weekdayInJava is not in the range 1..7
      • toUTCString

        public String toUTCString()
        A string representation of this timestamp, converted to UTC
        Returns:
        string representation of this timestamp
      • toString

        public String toString()
        A string representation of this timestamp, including ms and time zone
        Overrides:
        toString in class Object
        Returns:
        string representation of this timestamp
      • valueOf

        public static DateTimeZone valueOf​(TimeZone timeZone,
                                           String str)
        Parse our variation on ISO-8601 dates (YYYY/MM/DD HH:MM:SS,FFF ZZZ) as well as real ISO-8601 timestamps as well as Microsoft's interpretation (that doesn't adhere to ISO-31, and thus uses .)
        Parameters:
        timeZone - default TimeZone used only when str doesn't specify timezone.
        str - String representation of timestamp.
        Returns:
        a timestamp.
      • toYYYYMMDDString

        public String toYYYYMMDDString()
        This date formatted YYYYMMDD
        Returns:
        string representation of this date
      • toHHMMSSString

        public String toHHMMSSString()
        This time formatted HHMMSS
        Returns:
        string representation of this time
      • decodePLSQLDate

        public static DateTimeZone decodePLSQLDate​(String timeStamp)
        Constructs a DateTimeZone from a representation like:
        • 1999.03.01
        • 1999.03.01 00:00:00
        • 1999.03.01 00:00:00 GMT
        Parameters:
        timeStamp - string with timestamp, e.g. 1999.03.01 00:00:00 GMT
        Returns:
        DateTimeZone
      • getLookAheadUntil

        public static DateTimeZone getLookAheadUntil​(DateTimeZone from)
        Returns the 2-years interval within which we compute the time windows. This is the central point for computing this interval, it is also used in tests.
        Parameters:
        from - The moment to start counting from
        Returns:
        cut-off timestamp, a new DateTimeZone, that is not used elsewhere
      • getLookAheadUntil

        public static long getLookAheadUntil​(long from)
      • setNow

        public void setNow()
      • smartSetTimeOfDay

        public void smartSetTimeOfDay​(int hour,
                                      int minute,
                                      int second,
                                      int milli)
        smartSetTimeOfDay should set the 'time-of-day' part of the given calendar to the given values, but if these values are positioned at a 'hole' it should set the time_of_day to the earliest time AFTER the hole. Furthermore if we set the time in an overlap, the Calendar implementation takes the LAST alternative and we want the first alternative There are some implicit assumptions here:
        • holes and overlaps start and end at a full minute
        • holes and overlaps do not pass day boundaries
        • holes and overlaps do not start at midnight
        • no day has more than one hole or overlap
        The implementation is not elegant. Other potential implementations are:
        • use getTimeZone() and try to derive the information you need from that (probably not much easier)
        • use another set of base classes (http://joda-time.sourceforge.net/index.html) (not sure if this set really tackles the problem)
        • write our own set of base-classes (copy the source of GregorianCalendar to start)
        To set values for specific temporal fields, use with(java.time.temporal.TemporalField, long).
        Parameters:
        hour - hour
        minute - minute
        second - second
        milli - millisecond
      • daysBetween

        public int daysBetween​(DateTimeZone other)
        Parameters:
        other -
        Returns:
        the number of days to get from this date to the other date
      • getDefaultTimeZone

        public static TimeZone getDefaultTimeZone()
        Get the default TimeZone.
        Returns:
        the default TimeZone.
      • expression

        public DateTimeZone expression​(String expression)
        Apply time expression expression to this date returning a new DateTimeZone with the modified date.
        Parameters:
        expression - the time expression to apply.
        Returns:
        the new DateTimeZone modified by the expression
      • expressionNow

        public static DateTimeZone expressionNow​(String expression)
        Apply time expression expression to the current time.
        Parameters:
        expression - the time expression to apply.
        Returns:
        the modified DateTimeZone.
      • toFormattedString

        public String toFormattedString​(String format,
                                        Locale locale)
        Format the date according to the specified Date Time Formatter. Additional format field 'i' for the Olson-name of the time zone is supported.
        Parameters:
        format - the format expression
        locale - the locale to use for formatting. When no locale is specified, the default locale will be used.
        Returns:
        the formatted date
        Throws:
        InvalidFormatException - if the given format is null
        IllegalArgumentException - if the given format is invalid
        InvalidDateFormatUnknownLocale - if the given format contains a unknown locale id
      • toLocalDate

        public LocalDate toLocalDate()
        Convert this DateTimeZone to java's LocalDate.
        Returns:
        LocalDate
      • toLocalTime

        public LocalTime toLocalTime()
        Convert this DateTimeZone to java's LocalTime.
        Returns:
        LocalTime
      • toLocalDateTime

        public LocalDateTime toLocalDateTime()
        Convert this DateTimeZone to java's LocalDateTime
        Returns:
        LocalDateTime
      • toZonedDateTime

        public ZonedDateTime toZonedDateTime()
        Convert this DateTimeZone to java's ZonedDateTime
        Returns:
        ZonedDateTime
      • isLastDayInMonthNow

        public static boolean isLastDayInMonthNow()
        Is it currently the last day of the month?
        Returns:
        true if it is the last day of the month, otherwise false.
      • isLastDayInMonth

        public boolean isLastDayInMonth()
        Is this date the last day of that month?
        Returns:
        true if it is the last day of the month, otherwise false.
      • formatDuration

        public static String formatDuration​(long duration)
        Format a duration using the default format string: "|1 week, |# weeks, |1 day, |# days, |#|:#|:#|.#|".
        Parameters:
        duration - the duration in milliseconds
        Returns:
        the formatted string
      • formatDuration

        public static String formatDuration​(long duration,
                                            String format)
        Format a duration using the specified format string. The format starts and ends with | and is separated by |. There are 8 elements, each controls how to format part of the string:
        1. 1 week
        2. 2 weeks or more, # is replaced with the number of weeks.
        3. 1 day
        4. 2 days or more, # is replaced with the number of days.
        5. Hours, # is replaced with the two digit number of hours.
        6. Minutes, # is replaced with the two digit number of minutes.
        7. Seconds, # is replaced with the two digit number of seconds.
        8. Milliseconds, # is replaced with the two digit number of milliseconds.
        Parameters:
        duration - the duration in milliseconds
        format - the format to use.
        Returns:
        the formatted duration.
      • setLenient

        public void setLenient​(boolean newLenient)
        Set the lenient flag, @see Calendar#setLenient(boolean) for more information. It is recommended not to pass 'strict' dates through to API calls (ie. reset this flag before making an API call) as behavior may differ for strict dates.
        Parameters:
        newLenient - the new value for the lenient flag.
        See Also:
        isLenient()
      • isLenient

        public boolean isLenient()
        Tells whether date/time interpretation is to be lenient.
        Returns:
        true if the interpretation mode of this calendar is lenient; false otherwise.
        See Also:
        setLenient(boolean)
      • isOverlap

        public boolean isOverlap()
      • withEarlierOffsetAtOverlap

        public DateTimeZone withEarlierOffsetAtOverlap()
      • withLaterOffsetAtOverlap

        public DateTimeZone withLaterOffsetAtOverlap()