Package com.redwood.scheduler.api.date
Class DateTimeZone
- java.lang.Object
-
- com.redwood.scheduler.api.date.DateTimeZone
-
- All Implemented Interfaces:
Serializable,Comparable<DateTimeZone>,Temporal,TemporalAccessor
public class DateTimeZone extends Object implements Serializable, Comparable<DateTimeZone>, Temporal
A Date with a time zone. This class is mutable but any method which implements Temporal will behave as if this class were immutable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intANYDAYWildcard for any single day.static intDAY_MILLISNumber of milliseconds in an day.static intDAYS_IN_WEEKNumber of days in weekstatic intFIVE_MINUTES_MILLISstatic intFRIDAYValue for Fridaystatic DateTimeZoneHIGHEST_SPECIAL_DATE_TIME_ZONEThe dates before this should not be considered normal date values.static longHIGHEST_SPECIAL_DATE_TIME_ZONE_MILLISstatic intHOUR_MILLISNumber of milliseconds in an hour.static intHOURS_IN_DAYNumber of hours in daystatic intLASTANYDAYA special value meaning 'the last day of the month'.static intLASTWORKDAYA special value meaning 'the last working day of the month'.static intMAX_DAYS_IN_MONTHThe maximum number of days in monthstatic intMAX_RECURRENCE_INTERVALThe maximum size of an interval that can be specified in a recurrencestatic intMAX_WEEKS_IN_MONTHThe maximum number of (partial) weeks in monthstatic intMAX_WORK_DAYS_IN_MONTHThe maximum number of workdays in monthstatic intMIN_DAYS_IN_MONTHThe minimum number of days in monthstatic intMINUTE_MILLISstatic intMONDAYValue for Mondaystatic intMONTHS_IN_YEARNumber of months in yearstatic DateTimeZoneNEVER_DATEThis value will be set if a job will not run.static longNEVER_MILLISstatic LongNEVER_MILLIS_LONGstatic StringNEVER_STRINGstatic longNOW_MILLISThis value will be used as the internal representation of "Now", which can be selected in the DateTimePickerControl/CalendarControl.static LongNOW_MILLIS_LONGstatic intQUARTER_MILLISstatic DateTimeZoneRECALC_DATEThis value will be set if a field should be recalculated.static longRECALC_MILLISstatic LongRECALC_MILLIS_LONGstatic StringRECALC_STRINGstatic DateTimeZoneREQUEUE_DATEThis value in milliseconds will be set on aJob.getScheduledStartTime()if the Job needs to be requeued.static longREQUEUE_MILLISstatic LongREQUEUE_MILLIS_LONGstatic intSATURDAYValue for Saturdaystatic intSECOND_MILLISstatic intSUNDAYValue for Sundaystatic intTHREE_MINUTES_MILLISstatic intTHURSDAYValue for Thursdaystatic intTUESDAYValue for Tuesdaystatic intWEDNESDAYValue for Wednesdaystatic intWEEKENDWildcard for weekends (Saturday and Sunday).static intWORK_DAYS_IN_WEEKNumber of work days in a weekstatic intWORKDAYWildcard for a single day from Monday till Fridaystatic intWORKWEEKWildcard for quintents (Monday,…,Friday).
-
Constructor Summary
Constructors Constructor Description DateTimeZone()DateTimeZone(int year, int monthZeroBased, int day, int hour, int minute, int second, int milli)DateTimeZone(long utcMillis)DateTimeZone(DateTimeZone createCopyFrom)DateTimeZone(ZonedDateTime newZonedDateTime)DateTimeZone(TimeZone timeZone)DateTimeZone(TimeZone timeZone, int year, int monthZeroBased, int day, int hour, int minute, int second, int milli)DateTimeZone(TimeZone timeZone, long utcMillis)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(int addWhat, int value)See Calendar.add(int,int)voidadd(int addWhat, long value)When adding milliseconds, you may want to add more than MAXINT.voidadd(int amount, TimeUnit timeUnit)voidadd(long amount, TimeUnit timeUnit)When adding milliseconds, you may want to add more than MAXINT.booleanafter(DateTimeZone moment)booleanbefore(DateTimeZone moment)static DayOfWeekcalendarDayAsDayOfWeek(int calendarWeekday)Converts Calendar representation of a weekday (Sunday = 1) to aDayOfWeekintcompareTo(DateTimeZone aDateTimeZone)intdaysBetween(DateTimeZone other)static DateTimeZonedecodePLSQLDate(String timeStamp)Constructs a DateTimeZone from a representation like: 1999.03.01 1999.03.01 00:00:00 1999.03.01 00:00:00 GMTbooleanequals(Object otherObject)Checks if twoDateTimeZoneobjects refer to the same moment in time and to the same time zone.DateTimeZoneexpression(String expression)Applytime expressionexpression to this date returning a new DateTimeZone with the modified date.static DateTimeZoneexpressionNow(String expression)Applytime expressionexpression to the current time.static StringformatDuration(long duration)Format a duration using the default format string: "|1 week, |# weeks, |1 day, |# days, |#|:#|:#|.#|".static StringformatDuration(long duration, String format)Format a duration using the specified format string.static DateTimeZonefrom(Date date)static DateTimeZonefrom(Date date, ZoneId timeZone)static DateTimeZonefromXSDDateTime(String dateString)intget(int getWhat)See Calendar.get(int)intget(TemporalField newField)CalendargetCalendar()Return aCalendarrepresenting the internal state of this DateTimeZone.intgetDayOfMonth()Return the current day of the month, the first day of the month has a value of one.intgetDayOfWeek()Deprecated.use getTemporalDayOfWeek() to get the day's enum value or get(WeekFields.SUNDAY_START.dayOfWeek()) to get the Calendar day numberintgetDayOfYear()Return the current day of the year, the first day of the year has a value of one.intgetDaysThisMonth()Returns the number of days in this month.static TimeZonegetDefaultTimeZone()Get the default TimeZone.static DateTimeZonegetHighDate()Returns the highest date we operate withintgetHour()Return the current hour of the day, this has a range of 0-23.longgetLong(TemporalField newField)static longgetLookAheadUntil(long from)static DateTimeZonegetLookAheadUntil(DateTimeZone from)Returns the 2-years interval within which we compute the time windows.static DateTimeZonegetLowDate()Returns the lowest date we operate withintgetMillisecond()Return the current millisecond of the second, this has a range of 0-999.intgetMinute()Return the current minute of the hour, this has a range of 0-59intgetMonth()Return the current month of the year, January has a value of zero.intgetSecond()Return the current second of the minute, this has a range of 0-60 to accommodate for leap seconds.DayOfWeekgetTemporalDayOfWeek()TimeZonegetTimeZone()static Comparator<DateTimeZone>getUTCComparator()longgetUTCMilliSecs()intgetYear()The current year.voidgoToNextDayOfWeek(int weekday)Deprecated.use goToNextDayOfWeek(DayOfWeek weekday) insteadvoidgoToNextDayOfWeek(DayOfWeek weekday)Skips to the same time of the next weekday providedinthashCode()booleanisLastDayInMonth()Is this date the last day of that month?static booleanisLastDayInMonthNow()Is it currently the last day of the month?booleanisLenient()Tells whether date/time interpretation is to be lenient.booleanisOverlap()booleanisSupported(TemporalField newField)booleanisSupported(TemporalUnit newUnit)booleanisWeekend()booleanisWorkday()DateTimeZoneminus(long newAmountToAdd, TemporalUnit newUnit)DateTimeZoneminus(TemporalAmount newAmountToAdd)static DateTimeZonenow()Creates a new DateTimeZone at the current system date-time and system-default time zone.static DateTimeZonenowPlusOffset(int amount, TimeUnit timeUnit)static DateTimeZoneof(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.static DateTimeZoneof(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.static DateTimeZoneparse(String string, String format)Parse the string into a date according to the specified Simple Date Format, using the default TimeZone.static DateTimeZoneparse(String string, String format, Locale locale)Parse the string into a date according to the specified Simple Date Format, using the default TimeZone.static DateTimeZoneparse(TimeZone timezone, String string, String format)Parse the string into a date according to the specified Simple Date Format.static DateTimeZoneparse(TimeZone timezone, String string, String format, Locale locale)Parse the string into a date according to the specified Simple Date Format.DateTimeZoneplus(long newAmountToAdd, TemporalUnit newUnit)DateTimeZoneplus(TemporalAmount newAmountToAdd)<R> Rquery(TemporalQuery<R> query)voidset(int setWhat, int value)See Calendar.set(int,int)voidset(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.voidset(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.voidset(DateTimeZone toCopyFrom)Sets this DateTimeZone from another DateTimeZone.voidset(TimeZone timeZone, long utcMilliSecs)voidsetLenient(boolean newLenient)Set the lenient flag, @see Calendar#setLenient(boolean) for more information.voidsetNow()voidsetTimeZone(TimeZone timeZone)voidsetUTCMilliSecs(long utcMilliSecs)voidsetYear(int year)Sets the year.voidsmartSetTimeOfDay(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.StringtoFormattedString(String format)Format the date according to the specified Date Time Formatter.StringtoFormattedString(String format, Locale locale)Format the date according to the specified Date Time Formatter.StringtoHHMMSSString()This time formatted HHMMSSLocalDatetoLocalDate()Convert this DateTimeZone to java's LocalDate.LocalDateTimetoLocalDateTime()Convert this DateTimeZone to java's LocalDateTimeLocalTimetoLocalTime()Convert this DateTimeZone to java's LocalTime.StringtoString()A string representation of this timestamp, including ms and time zoneStringtoUTCString()A string representation of this timestamp, converted to UTCStringtoYYYYMMDDString()This date formatted YYYYMMDDZonedDateTimetoZonedDateTime()Convert this DateTimeZone to java's ZonedDateTimevoidtruncateDay()Truncate to the beginning of the last day.voidtruncateHour()Truncate to the last hour.voidtruncateMinute()Truncate to the last minute.voidtruncateMonth()Truncate to the beginning of the last month.voidtruncateSecond()Truncate to the last second.ZonedDateTimetruncateSecond(ZonedDateTime time)DateTimeZonetruncateToHole()ZonedDateTimetruncateToHole(ZonedDateTime time)voidtruncateYear()Truncate to the beginning of the last year.longuntil(Temporal newEndExclusive, TemporalUnit newUnit)booleanutcEquals(Object aDateTimeZone)Checks if twoDateTimeZoneobjects refer to the same moment in time, even in different time zonesstatic DateTimeZonevalueOf(String str)static DateTimeZonevalueOf(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 .)static StringweekdayJavaToEnglish(int weekdayInJava)Spells out a DateTimeZone/Calendar weekday.static intweekdayJavaToOracle(int weekdayInJava)Deprecated.This class now uses the java.time framework, which uses Monday-starting weeks; use calendarDayAsDayOfWeek(weekdayInJava).value() insteadstatic intweekdayOracleToJava(int weekdayInOracle)Deprecated.This class now uses the java.time framework, which uses Monday-starting weeks; use DayOfWeek.of(weekdayInOracle) insteadDateTimeZonewith(TemporalField newField, long newValue)DateTimeZonewithEarlierOffsetAtOverlap()DateTimeZonewithLaterOffsetAtOverlap()DateTimeZonewithZoneSameInstant(ZoneId timeZone)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.time.temporal.TemporalAccessor
range
-
-
-
-
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
public static final long REQUEUE_MILLIS
- See Also:
- Constant Field Values
-
REQUEUE_DATE
public static final DateTimeZone REQUEUE_DATE
This value in milliseconds will be set on aJob.getScheduledStartTime()if the Job needs to be requeued. This date is later thanRECALC_DATE, but earlier than any date that a user can set forJob.setRequestedStartTime(DateTimeZone). 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.
-
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_MILLIS
public static final long RECALC_MILLIS
- See Also:
- Constant Field Values
-
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_MILLIS
public static final long NEVER_MILLIS
- See Also:
- Constant Field Values
-
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
-
SUNDAY
public static final int SUNDAY
Value for Sunday- See Also:
- Constant Field Values
-
MONDAY
public static final int MONDAY
Value for Monday- See Also:
- Constant Field Values
-
TUESDAY
public static final int TUESDAY
Value for Tuesday- See Also:
- Constant Field Values
-
WEDNESDAY
public static final int WEDNESDAY
Value for Wednesday- See Also:
- Constant Field Values
-
THURSDAY
public static final int THURSDAY
Value for Thursday- See Also:
- Constant Field Values
-
FRIDAY
public static final int FRIDAY
Value for Friday- See Also:
- Constant Field Values
-
SATURDAY
public static final int SATURDAY
Value for Saturday- 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). EachWEEKENDconsists of twoANYDAYs.- See Also:
- Constant Field Values
-
WORKWEEK
public static final int WORKWEEK
Wildcard for quintents (Monday,…,Friday). EachWORKWEEKconsists of 5WORKDAYs.- See Also:
- Constant Field Values
-
ANYDAY
public static final int ANYDAY
Wildcard for any single day.- 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
-
SECOND_MILLIS
public static final int SECOND_MILLIS
- See Also:
- Constant Field Values
-
MINUTE_MILLIS
public static final int MINUTE_MILLIS
- See Also:
- Constant Field Values
-
THREE_MINUTES_MILLIS
public static final int THREE_MINUTES_MILLIS
- See Also:
- Constant Field Values
-
FIVE_MINUTES_MILLIS
public static final int FIVE_MINUTES_MILLIS
- See Also:
- Constant Field Values
-
QUARTER_MILLIS
public static final int QUARTER_MILLIS
- See Also:
- Constant Field Values
-
NEVER_STRING
public static final String NEVER_STRING
- See Also:
- Constant Field Values
-
RECALC_STRING
public static final String RECALC_STRING
- 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_YEARmonth- the month-of-year to represent, from 1 (January) to 12 (December)day- the day-of-month to represent, from 1 to 31hour- the hour-of-day to represent, from 0 to 23minute- the minute-of-hour to represent, from 0 to 59second- the second-of-minute to represent, from 0 to 59milli- 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_YEARmonth- the month-of-year to represent, from 1 (January) to 12 (December)day- the day-of-month to represent, from 1 to 31hour- the hour-of-day to represent, from 0 to 23minute- the minute-of-hour to represent, from 0 to 59second- the second-of-minute to represent, from 0 to 59milli- the milli-of-second to represent, from 0 to 999timeZone- 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
-
nowPlusOffset
public static DateTimeZone nowPlusOffset(int amount, TimeUnit timeUnit)
-
from
public static DateTimeZone from(Date date)
-
from
public static DateTimeZone from(Date date, ZoneId timeZone)
-
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 addtimeUnit- 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()
-
withZoneSameInstant
public DateTimeZone withZoneSameInstant(ZoneId timeZone)
-
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 multipleset-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.
-
truncateSecond
public ZonedDateTime truncateSecond(ZonedDateTime time)
-
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.
-
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 addvalue- 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 addvalue- 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) insteadSkips 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 addvalue- 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 numberReturn the current day of the week, returns one ofSUNDAY,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)
-
before
public boolean before(DateTimeZone moment)
-
after
public boolean after(DateTimeZone moment)
-
utcEquals
public boolean utcEquals(Object aDateTimeZone)
Checks if twoDateTimeZoneobjects 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 twoDateTimeZoneobjects refer to the same moment in time and to the same time zone.
-
calendarDayAsDayOfWeek
public static DayOfWeek calendarDayAsDayOfWeek(int calendarWeekday) throws com.redwood.scheduler.api.exception.DateTimeConstantOutOfBoundsException
Converts Calendar representation of a weekday (Sunday = 1) to aDayOfWeek- 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() insteadConverts 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) insteadConverts 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
-
valueOf
public static DateTimeZone valueOf(String str)
- Parameters:
str- String representation of timestamp.- Returns:
- a timestamp.
- See Also:
with no default TimeZone
-
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
- 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)
with(java.time.temporal.TemporalField, long).- Parameters:
hour- hourminute- minutesecond- secondmilli- millisecond
-
truncateToHole
public DateTimeZone truncateToHole()
-
truncateToHole
public ZonedDateTime truncateToHole(ZonedDateTime time)
-
getCalendar
public Calendar getCalendar()
Return aCalendarrepresenting the internal state of this DateTimeZone. This is useful for printing this DateTimeZone usingDateFormat.setCalendar(Calendar).- Returns:
- a
Calendarrepresenting the internal state of this DateTimeZone
-
daysBetween
public int daysBetween(DateTimeZone other)
- Parameters:
other-- Returns:
- the number of days to get from this date to the other date
-
getUTCComparator
public static Comparator<DateTimeZone> getUTCComparator()
-
getDefaultTimeZone
public static TimeZone getDefaultTimeZone()
Get the default TimeZone.- Returns:
- the default TimeZone.
-
expression
public DateTimeZone expression(String expression)
Applytime expressionexpression 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)
Applytime expressionexpression to the current time.- Parameters:
expression- the time expression to apply.- Returns:
- the modified DateTimeZone.
-
toFormattedString
public String toFormattedString(String format)
Format the date according to the specified Date Time Formatter.- Parameters:
format- the format expression- Returns:
- the formatted date
- Throws:
InvalidFormatException- if the given format is nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- if the given format contains a unknown locale id
-
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 expressionlocale- 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 nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- 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
-
parse
public static DateTimeZone parse(TimeZone timezone, String string, String format) throws ParseException
Parse the string into a date according to the specified Simple Date Format. Additional format fields are supported, such as locale {en} and TimeZoneId 'i'- Parameters:
timezone- the TimeZone to usestring- the string to parseformat- the date format expression- Returns:
- the resulting DateTimeZone
- Throws:
InvalidFormatException- if the given format is nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- if the given format contains a unknown locale idParseException- if the parsing fails
-
parse
public static DateTimeZone parse(TimeZone timezone, String string, String format, Locale locale) throws ParseException
Parse the string into a date according to the specified Simple Date Format. Additional format field 'i' for the Olson-name of the time zone is supported.- Parameters:
timezone- the TimeZone to usestring- the string to parseformat- the date format expressionlocale- the locale to use for formatting. When no locale is specified, the default locale will be used.- Returns:
- the resulting DateTimeZone
- Throws:
InvalidFormatException- if the given format is nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- if the given format contains a unknown locale idParseException- if the parsing fails
-
parse
public static DateTimeZone parse(String string, String format) throws ParseException
Parse the string into a date according to the specified Simple Date Format, using the default TimeZone. Additional format fields are supported, such as locale {en} and TimeZoneId 'i'- Parameters:
string- the string to parseformat- the date format expression- Returns:
- the resulting DateTimeZone
- Throws:
InvalidFormatException- if the given format is nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- if the given format contains a unknown locale idParseException- if the parsing fails
-
parse
public static DateTimeZone parse(String string, String format, Locale locale) throws ParseException
Parse the string into a date according to the specified Simple Date Format, using the default TimeZone. Additional format field 'i' for the Olson-name of the time zone is supported.- Parameters:
string- the string to parseformat- the date format expressionlocale- the locale to use for formatting. When no locale is specified, the default locale will be used.- Returns:
- the resulting DateTimeZone
- Throws:
InvalidFormatException- if the given format is nullIllegalArgumentException- if the given format is invalidInvalidDateFormatUnknownLocale- if the given format contains a unknown locale idParseException- if the parsing fails
-
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.
-
fromXSDDateTime
public static DateTimeZone fromXSDDateTime(String dateString) throws ParseException
- Throws:
ParseException
-
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 week
- 2 weeks or more, # is replaced with the number of weeks.
- 1 day
- 2 days or more, # is replaced with the number of days.
- Hours, # is replaced with the two digit number of hours.
- Minutes, # is replaced with the two digit number of minutes.
- Seconds, # is replaced with the two digit number of seconds.
- Milliseconds, # is replaced with the two digit number of milliseconds.
- Parameters:
duration- the duration in millisecondsformat- the format to use.- Returns:
- the formatted duration.
-
compareTo
public int compareTo(DateTimeZone aDateTimeZone)
- Specified by:
compareToin interfaceComparable<DateTimeZone>
-
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)
-
isSupported
public boolean isSupported(TemporalField newField)
- Specified by:
isSupportedin interfaceTemporalAccessor
-
isSupported
public boolean isSupported(TemporalUnit newUnit)
- Specified by:
isSupportedin interfaceTemporal
-
get
public int get(TemporalField newField)
- Specified by:
getin interfaceTemporalAccessor
-
getLong
public long getLong(TemporalField newField)
- Specified by:
getLongin interfaceTemporalAccessor
-
with
public DateTimeZone with(TemporalField newField, long newValue)
-
plus
public DateTimeZone plus(TemporalAmount newAmountToAdd)
-
plus
public DateTimeZone plus(long newAmountToAdd, TemporalUnit newUnit)
-
minus
public DateTimeZone minus(TemporalAmount newAmountToAdd)
-
minus
public DateTimeZone minus(long newAmountToAdd, TemporalUnit newUnit)
-
isOverlap
public boolean isOverlap()
-
withEarlierOffsetAtOverlap
public DateTimeZone withEarlierOffsetAtOverlap()
-
withLaterOffsetAtOverlap
public DateTimeZone withLaterOffsetAtOverlap()
-
until
public long until(Temporal newEndExclusive, TemporalUnit newUnit)
-
query
public <R> R query(TemporalQuery<R> query)
- Specified by:
queryin interfaceTemporalAccessor- See Also:
ZonedDateTime.query(TemporalQuery)
-
-