Calendar Methods

Calendars Class

There are several calendar methods to use in Deephaven. If you want to use the default calendar in your system, calendar methods can be used statically within query strings, without importing the Calendar class. For example:

t2 = t.where("Date = currentDay()")

However, to use a different calendar other than the default, you must first import the Calendars class, as shown below.

from deephaven import *
jpose = cals.calendar("JPOSE")
t = t.update(“Date = jpose.currentDay()”)
import com.illumon.util.calendar.Calendars
jpose = Calendars.calendar("JPOSE")
t = t.where(“Date = jpose.currentDay()”)

There are three primary methods to access these calendars:

  1. You can specify the calendar by name. As demonstrated above, Calendars.calendar(“name”).
    Note: Use the calendarNames() method to get a list of available calendar names: print cals.calendarNames() or println Calendars.calendarNames()
  2. You can get the default calendar as specified in your configurations, or you can set the default calendar with the .calendar() method, e.g. USNYSE = Calendars.calendar() or USNYSE = cals.calendar(), or you can set the default calendar under Settings.
  3. You can use the provided calendars as variables (only in Groovy)

For example, if you wanted to use the provided USNYSE calendar in your query, you could use the following:

curDayNY = CALENDAR_USYSE.currentDay()

Or equivalently,

from deephaven import *  # Calendars module imported as cals

curDayNY = cals.calendar("USNYSE").currentDay()
 
                    
import com.illumon.util.calendar.Calendars
curDayNY = Calendars.calendar("USNYSE").currentDay()
 
                    

Method

Description

calendar(final String name)

Returns a specified business calendar.

calendar()

Returns the default business calendar.

calendarNames()

Returns the names of all available calendars

Calendar Methods

Once the Calendar class is imported, you can employ any of the calendar methods that follow to obtain time and date related information via queries.

Note: The methods that take no date parameter act on the current date. For example nextDay(5) is equivalent to nextDay(currentDay(), 5).

In addition to the general Calendar methods below, there are also separate methods for business-specific calendars. To learn more about those, see Business Calendar Methods.

Method

Description

dayOfWeek()

dayOfWeek(DBDateTime time)

dayOfWeek(java.lang.String date)

Gets the day of the week for a time.

For example, dayOfWeek(20170308) would return Wednesday.

daysInRange(DBDateTime start, DBDateTime end)

daysInRange(java.lang.String start, java.lang.String end)

Gets the days in a given range.

diffDay(DBDateTime start, DBDateTime end)

Returns the amount of time in days between start and end.

diffNanos(DBDateTime start, DBDateTime end)

Returns the amount of time in nanoseconds between start and end.

diffYear(DBDateTime start, DBDateTime end)

Returns the number of years between start and end.

name()

Gets the name of the calendar.

nextDay()

nextDay(DBDateTime time)

nextDay(java.lang.String date)

Gets the next date.

nextDay(int days)

nextDay(DBDateTime time, int days)

nextDay(java.lang.String date, int days)

Gets the date specified by the number of days after the input date.

numberOfDays(DBDateTime start, DBDateTime end)

numberOfDays(java.lang.String start, java.lang.String end)

Gets the number of days in a given range, end date exclusive.

numberOfDays(DBDateTime start, DBDateTime end, boolean endInclusive)

numberOfDays(java.lang.String start, java.lang.String end, boolean endInclusive)

Gets the number of days in a given range, with the option to make the end date inclusive or exclusive.

previousDay()

previousDay(DBDateTime time)

previousDay(java.lang.String date)

Gets the previous date.

previousDay(int days)

previousDay(DBDateTime time, int days)

previousDay(java.lang.String date, int days)

Gets the date specified by the number of days before the input date.

timeZone()

Gets the timezone of the calendar.

Available Timezones

DBDateTime strings use the following codes. For example, the following tables uses the timezone for London:

x=db.t("LSE","LSELondon").where("Date=`2020-04-01`").where("TIMESTAMP > '2020-04-01T08:00:00 LON'")

String

DateTimeZone ID

Timezone

NY

TZ_NY(DateTimeZone.forID("America/New_York"))

America/New York

ET

TZ_ET(DateTimeZone.forID("America/New_York"))

America/New York

MN

TZ_MN(DateTimeZone.forID("America/Chicago"))

America/Chicago

CT

TZ_CT(DateTimeZone.forID("America/Chicago"))

America/Chicago

MT

TZ_MT(DateTimeZone.forID("America/Denver"))

America/Denver

PT

TZ_PT(DateTimeZone.forID("America/Los_Angeles"))

America/Los Angeles

HI

TZ_HI(DateTimeZone.forID("Pacific/Honolulu"))

Pacific/Honolulu

BT

TZ_BT(DateTimeZone.forID("America/Sao_Paulo"))

America/Sao Paulo

KR

TZ_KR(DateTimeZone.forID("Asia/Seoul"))

Asia/Seoul

HK

TZ_HK(DateTimeZone.forID("Asia/Hong_Kong"))

Asia/Hong Kong

JP

TZ_JP(DateTimeZone.forID("Asia/Tokyo"))

Asia/Tokyo

AT

TZ_AT(DateTimeZone.forID("Canada/Atlantic"))

Canada/Atlantic

NF

TZ_NF(DateTimeZone.forID("Canada/Newfoundland"))

Canada/Newfoundland

AL

TZ_AL(DateTimeZone.forID("America/Anchorage"))

America/Anchorage

IN

TZ_IN(DateTimeZone.forID("Asia/Kolkata"))

Asia/Kolkata

CE

TZ_CE(DateTimeZone.forID("Europe/Berlin"))

Europe/Berlin

SG

TZ_SG(DateTimeZone.forID("Asia/Singapore"))

Asia/Singapore

LON

TZ_LON(DateTimeZone.forID("Europe/London"))

Europe/London

MOS

TZ_MOS(DateTimeZone.forID("Europe/Moscow"))

Europe/Moscow

SHG

TZ_SHG(DateTimeZone.forID("Asia/Shanghai"))

Asia/Shanghai

CH

TZ_CH(DateTimeZone.forID("Europe/Zurich"))

Europe/Zurich

NL

TZ_NL(DateTimeZone.forID("Europe/Amsterdam"))

Europe/Amsterdam

TW

TZ_TW(DateTimeZone.forID("Asia/Taipei"))

Asia/Tapei

SYD

TZ_SYD(DateTimeZone.forID("Australia/Sydney"))

Australia/Sydney

UTC

TZ_UTC(DateTimeZone.UTC)

Coordinated Universal Time