Class Time

Classdesc

iCalendar Time representation (similar to JS Date object). Fully independent of system (OS) timezone / time. Unlike JS Date, the month January is 1, not zero.

Example

var time = new ICAL.Time({
year: 2012,
month: 10,
day: 11
minute: 0,
second: 0,
isDate: false
});

Alias

ICAL.Time

Hierarchy

Constructors

  • Creates a new ICAL.Time instance.

    Parameters

    • Optional data: TimeData

      Time initialization

    • Optional zone: Timezone

      timezone this position occurs in

    Returns Time

Properties

_cachedUnixTime: null | number = null
_pendingNormalization: boolean = false

Internal uses to indicate that a change has been made and the next read operation must attempt to normalize the value (for example changing the day to 33).

_time: Required<TimeData>
auto_normalize: boolean
day: number
hour: number
icalclass: "icaltime" | "vcardtime" = 'icaltime'

The class identifier.

isDate: boolean
minute: number
month: number
second: number
wrappedJSObject: Time
year: number
zone?: Timezone

The timezone for this time.

#epochTime: null | Time = null
DEFAULT_WEEK_START: 2 = 2

The default weekday for the WKST part.

Constant

Default

ICAL.Time.MONDAY
FRIDAY: FRIDAY = WeekDay.FRIDAY
MONDAY: MONDAY = WeekDay.MONDAY
SATURDAY: SATURDAY = WeekDay.SATURDAY
SUNDAY: SUNDAY = WeekDay.SUNDAY
THURSDAY: THURSDAY = WeekDay.THURSDAY
TUESDAY: TUESDAY = WeekDay.TUESDAY
WEDNESDAY: WEDNESDAY = WeekDay.WEDNESDAY
_dowCache: Record<number, number> = {}
_wnCache: Record<number, number> = {}
daysInYearPassedMonth: number[][] = ...

The days that have passed in the year after a given month. The array has two members, one being an array of passed days for non-leap years, the other analog for leap years.

Example

var isLeapYear = ICAL.Time.isLeapYear(year);
var passedDays = ICAL.Time.daysInYearPassedMonth[isLeapYear][month];
fromData: ((aData, aZone?) => Time) = ...

Type declaration

    • (aData, aZone?): Time
    • Creates a new ICAL.Time instance from the the passed data object.

      Parameters

      • aData: TimeData

        Time initialization

      • Optional aZone: Timezone

        Timezone this position occurs in

      Returns Time

Accessors

  • get icaltype(): "date-and-or-time" | "date" | "date-time"
  • The type name, to be used in the jCal object. This value may change and is strictly defined by the ICAL.Time#isDate isDate member.

    Returns "date-and-or-time" | "date" | "date-time"

    Default

    "date-time"
    
  • get epochTime(): Time
  • January 1st, 1970 as an ICAL.Time.

    Returns Time

    Constant

    Instance

Methods

  • Adds the duration to the current time. The instance is modified in place.

    Parameters

    • aDuration: Duration

      The duration to add

    Returns void

  • Adjust the date/time by the given offset

    Parameters

    • aExtraDays: number

      The extra amount of days

    • aExtraHours: number

      The extra amount of hours

    • aExtraMinutes: number

      The extra amount of minutes

    • aExtraSeconds: number

      The extra amount of seconds

    • Optional aTime: Required<TimeData>

      The time to adjust, defaults to the current instance.

    Returns Time

  • Returns a clone of the time object.

    Returns Time

    The cloned object

  • Compares the ICAL.Time instance with another one.

    Parameters

    Returns number

    -1, 0 or 1 for less/equal/greater

  • Compares only the date part of this instance with another one.

    Parameters

    • other: Duration

      The instance to compare with

    • tz: Timezone

      The timezone to compare in

    Returns number

    -1, 0 or 1 for less/equal/greater

  • Convert the instance into another timezone. The returned ICAL.Time instance is always a copy.

    Parameters

    Returns Time

    The copy, converted to the zone

  • Calculate the day of week.

    Parameters

    • Optional aWeekStart: WeekDay

      The week start weekday, defaults to SUNDAY

    Returns WeekDay

  • Calculate the day of year.

    Returns number

  • Returns a copy of the current date/time, shifted to the end of the month. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Returns Time

    The end of the month (cloned)

  • Returns a copy of the current date/time, shifted to the end of the week. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Parameters

    • Optional aWeekStart: WeekDay

      The week start weekday, defaults to SUNDAY

    Returns Time

    The end of the week (cloned)

  • Returns a copy of the current date/time, shifted to the end of the year. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Returns Time

    The end of the year (cloned)

  • Sets up the current instance using members from the passed data object.

    Parameters

    • Optional aData: TimeData

      Time initialization

    • Optional aZone: Timezone

      Timezone this position occurs in

    Returns Time

  • Set up the current instance from the Javascript date value.

    Parameters

    • aDate: null | Date

      The Javascript Date to read, or null to reset

    • Optional useUTC: boolean

      If true, the UTC values of the date will be used

    Returns Time

  • Sets up the current instance from unix time, the number of seconds since January 1st, 1970.

    Parameters

    • seconds: number

      The seconds to set up with

    Returns void

  • Get the dominical letter for the current year. Letters range from A - G for common years, and AG to GF for leap years.

    Returns string

    The dominical letter.

  • Checks if current time is the nth weekday, relative to the current month. Will always return false when rule resolves outside of current month.

    Parameters

    • aDayOfWeek: WeekDay

      Day of week to check

    • aPos: number

      Relative position

    Returns boolean

    True, if it is the nth weekday

  • Finds the nthWeekDay relative to the current month (not day). The returned value is a day relative the month that this month belongs to so 1 would indicate the first of the month and 40 would indicate a day in the following month.

    Parameters

    • aDayOfWeek: number

      Day of the week see the day name constants

    • aPos: number

      Nth occurrence of a given week day values of 1 and 0 both indicate the first weekday of that type. aPos may be either positive or negative

    Returns number

    numeric value indicating a day relative to the current month of this time object

  • Reset the time instance to epoch time

    Returns void

  • Reset the time instance to the given date/time values.

    Parameters

    • year: number

      The year to set

    • month: number

      The month to set

    • day: number

      The day to set

    • hour: number

      The hour to set

    • minute: number

      The minute to set

    • second: number

      The second to set

    • Optional timezone: Timezone

      The timezone to set

    Returns void

  • First calculates the start of the week, then returns the day of year for this date. If the day falls into the previous year, the day is zero or negative.

    Parameters

    • Optional aFirstDayOfWeek: WeekDay

      The week start weekday, defaults to SUNDAY

    Returns number

    The calculated day of year

  • Returns a copy of the current date/time, rewound to the start of the month. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Returns Time

    The start of the month (cloned)

  • Returns a copy of the current date/time, rewound to the start of the week. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Parameters

    • Optional aWeekStart: WeekDay

      The week start weekday, defaults to SUNDAY

    Returns Time

    The start of the week (cloned)

  • Returns a copy of the current date/time, rewound to the start of the year. The resulting ICAL.Time instance is of icaltype date, even if this is a date-time.

    Returns Time

    The start of the year (cloned)

  • Subtract the date details (excluding timezone). Useful for finding the relative difference between two time objects excluding their timezone differences.

    Parameters

    • aDate: Time

      The date to subtract

    Returns Duration

    The difference as a duration

  • Subtract the date details, taking timezones into account.

    Parameters

    • aDate: Time

      The date to subtract

    Returns Duration

    The difference in duration

  • Returns an RFC 5545 compliant ical representation of this object.

    Returns string

    ical date/date-time

  • Converts the current instance to a Javascript date

    Returns Date

  • Converts time to into Object which can be serialized then re-created using the constructor.

    Returns Record<string, any>

    Example

    // toJSON will automatically be called
    var json = JSON.stringify(mytime);

    var deserialized = JSON.parse(json);

    var time = new ICAL.Time(deserialized);
  • The string representation of this date/time, in jCal form (including : and - separators).

    Returns string

  • Converts the current instance to seconds since January 1st 1970.

    Returns number

    Seconds since 1970

  • Calculates the UTC offset of the current date/time in the timezone it is in.

    Returns number

    UTC offset in seconds

  • Calculates the ISO 8601 week number. The first week of a year is the week that contains the first Thursday. The year can have 53 weeks, if January 1st is a Friday.

    Note there are regions where the first week of the year is the one that starts on January 1st, which may offset the week number. Also, if a different week start is specified, this will also affect the week number.

    Parameters

    • aWeekStart: WeekDay

      The weekday the week starts with

    Returns number

    The ISO week number

    See

    ICAL.Time.weekOneStarts

  • Parameters

    • a: any
    • b: any
    • attr: any

    Returns 0 | 1 | -1

  • Returns the days in the given month

    Parameters

    • month: number

      The month to check

    • year: number

      The year to check

    Returns number

    The number of days in the month

  • Returns a new ICAL.Time instance from a date string, e.g 2015-01-02.

    Parameters

    • aValue: string

      The string to create from

    Returns Time

    The date/time instance

  • Returns a new ICAL.Time instance from a date-time string, e.g 2015-01-02T03:04:05. If a property is specified, the timezone is set up from the property's TZID parameter.

    Parameters

    • aValue: string

      The string to create from

    • Optional prop: Property

      The property the date belongs to

    Returns Time

    The date/time instance

  • Create a new ICAL.Time from the day of year and year. The date is returned in floating timezone.

    Parameters

    • aDayOfYear: number

      The day of year

    • aYear: number

      The year to create the instance in

    Returns Time

    The created instance with the calculated date

  • Creates a new ICAL.Time instance from the given Javascript Date.

    Parameters

    • aDate: null | Date

      The Javascript Date to read, or null to reset

    • useUTC: boolean

      If true, the UTC values of the date will be used

    Returns Time

  • Returns a new ICAL.Time instance from a date or date-time string,

    Parameters

    • aValue: string

      The string to create from

    • Optional aProperty: Property

      The property the date belongs to

    Returns Time

    The date/time instance

  • Returns a new ICAL.Time instance from a date string, e.g 2015-01-02.

    Parameters

    • str: string

      The string to create from

    Returns Time

    The date/time instance

    Deprecated

    Use ICAL.Time.fromDateString instead

  • Get the dominical letter for the given year. Letters range from A - G for common years, and AG to GF for leap years.

    Parameters

    • yr: number

      The year to retrieve the letter for

    Returns string

    The dominical letter.

  • Checks if the year is a leap year

    Parameters

    • year: number

      The year to check

    Returns boolean

    True, if the year is a leap year

  • Creates a new ICAL.Time instance from the current moment. The instance is “floating” - has no timezone relation. To create an instance considering the time zone, call ICAL.Time.fromJSDate(new Date(), true)

    Returns Time

  • Returns the date on which ISO week number 1 starts.

    Parameters

    • aYear: number

      The year to search in

    • aWeekStart: WeekDay

      The week start weekday, used for calculation.

    Returns Time

    The date on which week number 1 starts

    See

    ICAL.Time#weekNumber

Generated using TypeDoc