Class Calendar

java.lang.Object
io.deephaven.time.calendar.Calendar
Direct Known Subclasses:
BusinessCalendar

public class Calendar extends Object
A calendar.

A calendar is associated with a specific time zone.

Date strings must be in a format that can be parsed by DateTimeUtils.parseLocalDate(String). Methods that accept strings can be slower than methods written explicitly for Instant, ZonedDateTime, or LocalDate.

  • Method Details

    • name

      public String name()
      Gets the name of the calendar.
      Returns:
      the name of the calendar
    • description

      public String description()
      Gets the description of the calendar.
      Returns:
      the description of the calendar
    • timeZone

      public ZoneId timeZone()
      Gets the timezone of the calendar.
      Returns:
      the time zone of the calendar
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • calendarDate

      public LocalDate calendarDate()
      The current date for the calendar.
      Returns:
      current date
    • dayOfWeek

      public DayOfWeek dayOfWeek()
      The current day of the week for the calendar.
      Returns:
      current day of the week
    • dayOfWeek

      public DayOfWeek dayOfWeek(LocalDate date)
      The current day of the week for the calendar.
      Parameters:
      date - date
      Returns:
      current day of the week, or null if the input is null.
    • dayOfWeek

      public DayOfWeek dayOfWeek(String date)
      The current day of the week for the calendar.
      Parameters:
      date - date
      Returns:
      current day of the week, or null if the input is null.
    • dayOfWeek

      public DayOfWeek dayOfWeek(Instant time)
      The current day of the week for the calendar.
      Parameters:
      time - time
      Returns:
      current day of the week, or null if the input is null.
    • dayOfWeek

      public DayOfWeek dayOfWeek(ZonedDateTime time)
      The current day of the week for the calendar.
      Parameters:
      time - time
      Returns:
      current day of the week, or null if the input is null.
    • dayOfWeekValue

      public int dayOfWeekValue()
      Returns a 1-based int value of the day of the week for the calendar, where 1 is Monday and 7 is Sunday.
      Returns:
      current day of the week
    • dayOfWeekValue

      public int dayOfWeekValue(LocalDate date)
      Returns a 1-based int value of the day of the week for the calendar, where 1 is Monday and 7 is Sunday.
      Parameters:
      date - date
      Returns:
      current day of the week, or QueryConstants.NULL_INT if the input is null.
    • dayOfWeekValue

      public int dayOfWeekValue(String date)
      Returns a 1-based int value of the day of the week for the calendar, where 1 is Monday and 7 is Sunday.
      Parameters:
      date - date
      Returns:
      current day of the week, or QueryConstants.NULL_INT if the input is null.
    • dayOfWeekValue

      public int dayOfWeekValue(Instant time)
      Returns a 1-based int value of the day of the week for the calendar, where 1 is Monday and 7 is Sunday.
      Parameters:
      time - time
      Returns:
      current day of the week, or QueryConstants.NULL_INT if the input is null.
    • dayOfWeekValue

      public int dayOfWeekValue(ZonedDateTime time)
      Returns a 1-based int value of the day of the week for the calendar, where 1 is Monday and 7 is Sunday.
      Parameters:
      time - time
      Returns:
      current day of the week, or QueryConstants.NULL_INT if the input is null.
    • plusDays

      public LocalDate plusDays(LocalDate date, int days)
      Adds a specified number of days to an input date. Adding negative days is equivalent to subtracting days.
      Parameters:
      date - date
      days - number of days to add
      Returns:
      days days after date, or null if any input is null or QueryConstants.NULL_INT.
    • plusDays

      public String plusDays(String date, int days)
      Adds a specified number of days to an input date. Adding negative days is equivalent to subtracting days.
      Parameters:
      date - date
      days - number of days to add
      Returns:
      days days after date, or null if any input is null or QueryConstants.NULL_INT.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • plusDays

      public Instant plusDays(Instant time, int days)
      Adds a specified number of days to an input time. Adding negative days is equivalent to subtracting days.

      Day additions are not always 24 hours. The resultant time will have the same local time as the input time, as determined by the calendar's time zone. This accounts for Daylight Savings Time. For example, 2023-11-05 has a daylight savings time adjustment, so '2023-11-04T14:00 ET' plus 1 day will result in '2023-11-05T15:00 ET', which is a 25-hour difference.

      Parameters:
      time - time
      days - number of days to add
      Returns:
      days days after time, or null if any input is null or QueryConstants.NULL_INT.
    • plusDays

      public ZonedDateTime plusDays(ZonedDateTime time, int days)
      Adds a specified number of days to an input time. Adding negative days is equivalent to subtracting days.

      Day additions are not always 24 hours. The resultant time will have the same local time as the input time, as determined by the calendar's time zone. This accounts for Daylight Savings Time. For example, 2023-11-05 has a daylight savings time adjustment, so '2023-11-04T14:00 ET' plus 1 day will result in '2023-11-05T15:00 ET', which is a 25-hour difference.

      The resultant time will have the same time zone as the calendar. This could be different than the time zone of the input ZonedDateTime.

      Parameters:
      time - time
      days - number of days to add
      Returns:
      days days after time, or null if any input is null or QueryConstants.NULL_INT.
    • minusDays

      public LocalDate minusDays(LocalDate date, int days)
      Subtracts a specified number of days to an input date. Subtracting negative days is equivalent to adding days.
      Parameters:
      date - date
      days - number of days to subtract
      Returns:
      days days before date, or null if any input is null or QueryConstants.NULL_INT.
    • minusDays

      public String minusDays(String date, int days)
      Subtracts a specified number of days to an input date. Subtracting negative days is equivalent to adding days.
      Parameters:
      date - date
      days - number of days to subtract
      Returns:
      days days before date, or null if any input is null or QueryConstants.NULL_INT.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • minusDays

      public Instant minusDays(Instant time, int days)
      Subtracts a specified number of days to an input time. Subtracting negative days is equivalent to adding days.

      Day subtractions are not always 24 hours. The resultant time will have the same local time as the input time, as determined by the calendar's time zone. This accounts for Daylight Savings Time. For example, 2023-11-05 has a daylight savings time adjustment, so '2023-11-04T14:00 ET' plus 1 day will result in '2023-11-05T15:00 ET', which is a 25-hour difference.

      Parameters:
      time - time
      days - number of days to subtract
      Returns:
      days days before time, or null if any input is null or QueryConstants.NULL_INT.
    • minusDays

      public ZonedDateTime minusDays(ZonedDateTime time, int days)
      Subtracts a specified number of days to an input time. Subtracting negative days is equivalent to adding days.

      Day subtractions are not always 24 hours. The resultant time will have the same local time as the input time, as determined by the calendar's time zone. This accounts for Daylight Savings Time. For example, 2023-11-05 has a daylight savings time adjustment, so '2023-11-04T14:00 ET' plus 1 day will result in '2023-11-05T15:00 ET', which is a 25-hour difference.

      The resultant time will have the same time zone as the calendar. This could be different than the time zone of the input ZonedDateTime.

      Parameters:
      time - time
      days - number of days to subtract
      Returns:
      days days before time, or null if any input is null or QueryConstants.NULL_INT.
    • futureDate

      public LocalDate futureDate(int days)
      Adds a specified number of days to the current date. Adding negative days is equivalent to subtracting days.
      Parameters:
      days - number of days to add.
      Returns:
      days days after the current date, or null if days is QueryConstants.NULL_INT.
    • pastDate

      public LocalDate pastDate(int days)
      Subtracts a specified number of days from the current date. Subtracting negative days is equivalent to adding days.
      Parameters:
      days - number of days to subtract.
      Returns:
      days days before the current date, or null if days is QueryConstants.NULL_INT.
    • calendarDates

      public LocalDate[] calendarDates(LocalDate start, LocalDate end, boolean startInclusive, boolean endInclusive)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      dates between start and end, or null if any input is null.
    • calendarDates

      public String[] calendarDates(String start, String end, boolean startInclusive, boolean endInclusive)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      dates between start and end, or null if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • calendarDates

      public LocalDate[] calendarDates(ZonedDateTime start, ZonedDateTime end, boolean startInclusive, boolean endInclusive)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      dates between start and end, or null if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • calendarDates

      public LocalDate[] calendarDates(Instant start, Instant end, boolean startInclusive, boolean endInclusive)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      dates between start and end, or null if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • calendarDates

      public LocalDate[] calendarDates(LocalDate start, LocalDate end)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      dates between start and end, including start and end, or null if any input is null.
    • calendarDates

      public String[] calendarDates(String start, String end)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      dates between start and end, including start and end, or null if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • calendarDates

      public LocalDate[] calendarDates(ZonedDateTime start, ZonedDateTime end)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      dates between start and end, including start and end, or null if any input is null.
    • calendarDates

      public LocalDate[] calendarDates(Instant start, Instant end)
      Returns the dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      dates between start and end, including start and end, or null if any input is null.
    • numberCalendarDates

      public int numberCalendarDates(LocalDate start, LocalDate end, boolean startInclusive, boolean endInclusive)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      number of dates between start and end, or QueryConstants.NULL_INT if any input is null.
    • numberCalendarDates

      public int numberCalendarDates(String start, String end, boolean startInclusive, boolean endInclusive)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      number of dates between start and end, or QueryConstants.NULL_INT if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • numberCalendarDates

      public int numberCalendarDates(ZonedDateTime start, ZonedDateTime end, boolean startInclusive, boolean endInclusive)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      number of dates between start and end, or QueryConstants.NULL_INT if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • numberCalendarDates

      public int numberCalendarDates(Instant start, Instant end, boolean startInclusive, boolean endInclusive)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      startInclusive - true to include start in the result; false to exclude start
      endInclusive - true to include end in the result; false to exclude end
      Returns:
      number of dates between start and end, or QueryConstants.NULL_INT if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • numberCalendarDates

      public int numberCalendarDates(LocalDate start, LocalDate end)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      number of dates between start and end, including start and end, or QueryConstants.NULL_INT if any input is null.
    • numberCalendarDates

      public int numberCalendarDates(String start, String end)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      number of dates between start and end, including start and end, or QueryConstants.NULL_INT if any input is null.
      Throws:
      DateTimeUtils.DateTimeParseException - if the string cannot be parsed
    • numberCalendarDates

      public int numberCalendarDates(ZonedDateTime start, ZonedDateTime end)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      number of dates between start and end, including start and end, or QueryConstants.NULL_INT if any input is null.
    • numberCalendarDates

      public int numberCalendarDates(Instant start, Instant end)
      Returns the number of dates in a given range.
      Parameters:
      start - start of a time range
      end - end of a time range
      Returns:
      number of dates between start and end, including start and end, or QueryConstants.NULL_INT if any input is null.