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:
- You can specify the calendar by name. As demonstrated above,
Calendars.calendar(“name”)
.
Note: Use thecalendarNames()
method to get a list of available calendar names:print cals.calendarNames()
orprintln Calendars.calendarNames()
- 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()
orUSNYSE = cals.calendar(),
or you can set the default calendar under Settings. - 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 |
---|---|
|
Returns a specified business calendar. |
|
Returns the default business calendar. |
|
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 |
---|---|
|
Gets the day of the week for a time. For example, dayOfWeek(20170308) would return Wednesday. |
|
Gets the days in a given range. |
|
Returns the amount of time in days between start and end. |
|
Returns the amount of time in nanoseconds between start and end. |
|
Returns the number of years between start and end. |
|
Gets the name of the calendar. |
|
Gets the next date. |
|
Gets the date specified by the number of days after the input date. |
|
Gets the number of days in a given range, end date exclusive. |
|
Gets the number of days in a given range, with the option to make the end date inclusive or exclusive. |
|
Gets the previous date. |
|
Gets the date specified by the number of days before the input date. |
|
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 |
---|---|---|
|
|
America/New York |
|
|
America/New York |
|
|
America/Chicago |
|
|
America/Chicago |
|
|
America/Denver |
|
|
America/Los Angeles |
|
|
Pacific/Honolulu |
|
|
America/Sao Paulo |
|
|
Asia/Seoul |
|
|
Asia/Hong Kong |
|
|
Asia/Tokyo |
|
|
Canada/Atlantic |
|
|
Canada/Newfoundland |
|
|
America/Anchorage |
|
|
Asia/Kolkata |
|
|
Europe/Berlin |
|
|
Asia/Singapore |
|
|
Europe/London |
|
|
Europe/Moscow |
|
|
Asia/Shanghai |
|
|
Europe/Zurich |
|
|
Europe/Amsterdam |
|
|
Asia/Tapei |
|
|
Australia/Sydney |
|
|
Coordinated Universal Time |