ICAL. Time

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.

Constructor

new Time(data, zone)

Creates a new ICAL.Time instance.

Parameters:
NameTypeDescription
dataObject

Time initialization

Properties
NameTypeAttributesDescription
yearNumber<optional>

The year for this date

monthNumber<optional>

The month for this date

dayNumber<optional>

The day for this date

hourNumber<optional>

The hour for this date

minuteNumber<optional>

The minute for this date

secondNumber<optional>

The second for this date

isDateBoolean<optional>

If true, the instance represents a date (as opposed to a date-time)

zoneICAL.Timezone

timezone this position occurs in

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

Members

(constant) DEFAULT_WEEK_START

The default weekday for the WKST part.

Default Value
  • ICAL.Time.MONDAY

daysInYearPassedMonth :Array.<Array.<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.

Type:
  • Array.<Array.<Number>>
Example
var isLeapYear = ICAL.Time.isLeapYear(year);
var passedDays = ICAL.Time.daysInYearPassedMonth[isLeapYear][month];

(constant) epochTime :ICAL.Time

January 1st, 1970 as an ICAL.Time.

fromData

Creates a new ICAL.Time instance from the the passed data object.

(constant) icalclass :String

The class identifier.

Type:
  • String
Default Value
  • "icaltime"

icaltype :String

The type name, to be used in the jCal object. This value may change and is strictly defined by the isDate member.

Type:
  • String
Default Value
  • "date-time"

zone :ICAL.Timezone

The timezone for this time.

Methods

addDuration(aDuration)

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

Parameters:
NameTypeDescription
aDurationICAL.Duration

The duration to add

adjust(aExtraDays, aExtraHours, aExtraMinutes, aExtraSeconds, aTimeopt)

Adjust the date/time by the given offset

Parameters:
NameTypeAttributesDescription
aExtraDaysNumber

The extra amount of days

aExtraHoursNumber

The extra amount of hours

aExtraMinutesNumber

The extra amount of minutes

aExtraSecondsNumber

The extra amount of seconds

aTimeNumber<optional>

The time to adjust, defaults to the current instance.

clone() → {ICAL.Time}

Returns a clone of the time object.

Returns:

The cloned object

Type: 
ICAL.Time

compare(aOther) → {Number}

Compares the ICAL.Time instance with another one.

Parameters:
NameTypeDescription
aOtherICAL.Duration

The instance to compare with

Returns:

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

Type: 
Number

compareDateOnlyTz(other, tz) → {Number}

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

Parameters:
NameTypeDescription
otherICAL.Duration

The instance to compare with

tzICAL.Timezone

The timezone to compare in

Returns:

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

Type: 
Number

convertToZone(zone) → {ICAL.Time}

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

Parameters:
NameTypeDescription
zoneICAL.Timezone

The zone to convert to

Returns:

The copy, converted to the zone

Type: 
ICAL.Time

dayOfWeek(aWeekStartopt) → {ICAL.Time.weekDay}

Calculate the day of week.

Parameters:
NameTypeAttributesDescription
aWeekStartICAL.Time.weekDay<optional>

The week start weekday, defaults to SUNDAY

Returns:
Type: 
ICAL.Time.weekDay

dayOfYear() → {Number}

Calculate the day of year.

Returns:
Type: 
Number

endOfMonth() → {ICAL.Time}

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:

The end of the month (cloned)

Type: 
ICAL.Time

endOfWeek(aWeekStartopt) → {ICAL.Time}

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:
NameTypeAttributesDescription
aWeekStartICAL.Time.weekDay<optional>

The week start weekday, defaults to SUNDAY

Returns:

The end of the week (cloned)

Type: 
ICAL.Time

endOfYear() → {ICAL.Time}

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:

The end of the year (cloned)

Type: 
ICAL.Time

fromData(aData, aZoneopt)

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

Parameters:
NameTypeAttributesDescription
aDataObject

Time initialization

Properties
NameTypeAttributesDescription
yearNumber<optional>

The year for this date

monthNumber<optional>

The month for this date

dayNumber<optional>

The day for this date

hourNumber<optional>

The hour for this date

minuteNumber<optional>

The minute for this date

secondNumber<optional>

The second for this date

isDateBoolean<optional>

If true, the instance represents a date (as opposed to a date-time)

aZoneICAL.Timezone<optional>

Timezone this position occurs in

fromJSDate(aDatenullable, useUTCopt)

Set up the current instance from the Javascript date value.

Parameters:
NameTypeAttributesDefaultDescription
aDateDate<nullable>

The Javascript Date to read, or null to reset

useUTCBoolean<optional>
false

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

fromUnixTime(seconds)

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

Parameters:
NameTypeDescription
secondsNumber

The seconds to set up with

getDominicalLetter(yr) → {String}

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

Parameters:
NameTypeDescription
yrNumber

The year to retrieve the letter for

Returns:

The dominical letter.

Type: 
String

isNthWeekDay(aDayOfWeek, aPos) → {Boolean}

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:
NameTypeDescription
aDayOfWeekICAL.Time.weekDay

Day of week to check

aPosNumber

Relative position

Returns:

True, if it is the nth weekday

Type: 
Boolean

nthWeekDay(aDayOfWeek, aPos) → {Number}

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:
NameTypeDescription
aDayOfWeekNumber

Day of the week see the day name constants

aPosNumber

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:

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

Type: 
Number

reset()

Reset the time instance to epoch time

resetTo(year, month, day, hour, minute, second, timezone)

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

Parameters:
NameTypeDescription
yearNumber

The year to set

monthNumber

The month to set

dayNumber

The day to set

hourNumber

The hour to set

minuteNumber

The minute to set

secondNumber

The second to set

timezoneICAL.Timezone

The timezone to set

startDoyWeek(aFirstDayOfWeekopt) → {Number}

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:
NameTypeAttributesDescription
aFirstDayOfWeekICAL.Time.weekDay<optional>

The week start weekday, defaults to SUNDAY

Returns:

The calculated day of year

Type: 
Number

startOfMonth() → {ICAL.Time}

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:

The start of the month (cloned)

Type: 
ICAL.Time

startOfWeek(aWeekStartopt) → {ICAL.Time}

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:
NameTypeAttributesDescription
aWeekStartICAL.Time.weekDay<optional>

The week start weekday, defaults to SUNDAY

Returns:

The start of the week (cloned)

Type: 
ICAL.Time

startOfYear() → {ICAL.Time}

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:

The start of the year (cloned)

Type: 
ICAL.Time

subtractDate(aDate) → {ICAL.Duration}

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

Parameters:
NameTypeDescription
aDateICAL.Time

The date to subtract

Returns:

The difference as a duration

Type: 
ICAL.Duration

subtractDateTz(aDate) → {ICAL.Duration}

Subtract the date details, taking timezones into account.

Parameters:
NameTypeDescription
aDateICAL.Time

The date to subtract

Returns:

The difference in duration

Type: 
ICAL.Duration

toICALString() → {String}

Returns an RFC 5545 compliant ical representation of this object.

Returns:

ical date/date-time

Type: 
String

toJSDate() → {Date}

Converts the current instance to a Javascript date

Returns:
Type: 
Date

toJSON() → {Object}

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

Returns:
Type: 
Object
Example
// toJSON will automatically be called
var json = JSON.stringify(mytime);

var deserialized = JSON.parse(json);

var time = new ICAL.Time(deserialized);

toString() → {String}

The string representation of this date/time, in jCal form (including : and - separators).

Returns:
Type: 
String

toUnixTime() → {Number}

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

Returns:

Seconds since 1970

Type: 
Number

utcOffset() → {Number}

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

Returns:

UTC offset in seconds

Type: 
Number

weekNumber(aWeekStart) → {Number}

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:
NameTypeDescription
aWeekStartICAL.Time.weekDay

The weekday the week starts with

See
  • Time.weekOneStarts
Returns:

The ISO week number

Type: 
Number

(static) daysInMonth(month, year) → {Number}

Returns the days in the given month

Parameters:
NameTypeDescription
monthNumber

The month to check

yearNumber

The year to check

Returns:

The number of days in the month

Type: 
Number

(static) fromDateString(aValue) → {ICAL.Time}

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

Parameters:
NameTypeDescription
aValueString

The string to create from

Returns:

The date/time instance

Type: 
ICAL.Time

(static) fromDateTimeString(aValue, propopt) → {ICAL.Time}

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:
NameTypeAttributesDescription
aValueString

The string to create from

propICAL.Property<optional>

The property the date belongs to

Returns:

The date/time instance

Type: 
ICAL.Time

(static) fromDayOfYear(aDayOfYear, aYear) → {ICAL.Time}

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

Parameters:
NameTypeDescription
aDayOfYearNumber

The day of year

aYearNumber

The year to create the instance in

Returns:

The created instance with the calculated date

Type: 
ICAL.Time

(static) fromJSDate(aDatenullable, useUTCopt)

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

Parameters:
NameTypeAttributesDefaultDescription
aDateDate<nullable>

The Javascript Date to read, or null to reset

useUTCBoolean<optional>
false

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

(static) fromString(aValue, propopt) → {ICAL.Time}

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

Parameters:
NameTypeAttributesDescription
aValueString

The string to create from

propICAL.Property<optional>

The property the date belongs to

Returns:

The date/time instance

Type: 
ICAL.Time

(static) fromStringv2(str) → {ICAL.Time}

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

Parameters:
NameTypeDescription
strString

The string to create from

Deprecated
Returns:

The date/time instance

Type: 
ICAL.Time

(static) getDominicalLetter(yr) → {String}

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

Parameters:
NameTypeDescription
yrNumber

The year to retrieve the letter for

Returns:

The dominical letter.

Type: 
String

(static) isLeapYear(year) → {Boolean}

Checks if the year is a leap year

Parameters:
NameTypeDescription
yearNumber

The year to check

Returns:

True, if the year is a leap year

Type: 
Boolean

(static) now() → {ICAL.Time}

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:
Type: 
ICAL.Time

(static) weekOneStarts(aYear, aWeekStartopt) → {ICAL.Time}

Returns the date on which ISO week number 1 starts.

Parameters:
NameTypeAttributesDescription
aYearNumber

The year to search in

aWeekStartICAL.Time.weekDay<optional>

The week start weekday, used for calculation.

See
  • Time#weekNumber
Returns:

The date on which week number 1 starts

Type: 
ICAL.Time

Type Definitions

weekDay

The weekday, 1 = SUNDAY, 7 = SATURDAY. Access via ICAL.Time.MONDAY, ICAL.Time.TUESDAY, ...

Type:
  • Number