Constructor
new Time(data, zone)
Creates a new ICAL.Time instance.
| Name | Type | Description |
|---|---|---|
data | ICAL. | Time initialization |
zone | ICAL. | timezone this position occurs in |
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
day :Number
The day of this date.
- Number
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.
- Array.<Array.<Number>>
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.
hour :Number
The hour of this date-time.
- Number
(constant) icalclass :String
The class identifier.
- 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.
- String
- Default Value
- "date-time"
isDate :Boolean
If true, the instance represents a date (as opposed to a date-time)
- Boolean
minute :Number
The minute of this date-time.
- Number
month :Number
The month of this date.
- Number
second :Number
The second of this date-time.
- Number
year :Number
The year of this date.
- Number
zone :ICAL.Timezone
The timezone for this time.
Methods
addDuration(aDuration)
Adds the duration to the current time. The instance is modified in place.
| Name | Type | Description |
|---|---|---|
aDuration | ICAL. | The duration to add |
adjust(aExtraDays, aExtraHours, aExtraMinutes, aExtraSeconds, aTimeopt)
Adjust the date/time by the given offset
| Name | Type | Attributes | Description |
|---|---|---|---|
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 | |
aTime | Number | <optional> | The time to adjust, defaults to the current instance. |
clone() → {ICAL.Time}
Returns a clone of the time object.
The cloned object
- Type:
- ICAL.
Time
compare(aOther) → {Number}
Compares the ICAL.Time instance with another one, or a period.
| Name | Type | Description |
|---|---|---|
aOther | ICAL. | The instance to compare with |
-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.
| Name | Type | Description |
|---|---|---|
other | ICAL. | The instance to compare with |
tz | ICAL. | The timezone to compare in |
-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.
| Name | Type | Description |
|---|---|---|
zone | ICAL. | The zone to convert to |
The copy, converted to the zone
- Type:
- ICAL.
Time
dayOfWeek(aWeekStartopt) → {ICAL.Time.weekDay}
Calculate the day of week.
| Name | Type | Attributes | Description |
|---|---|---|---|
aWeekStart | ICAL. | <optional> | The week start weekday, defaults to SUNDAY |
- Type:
- ICAL.
Time. weekDay
dayOfYear() → {Number}
Calculate the day of year.
- 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.
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
aWeekStart | ICAL. | <optional> | The week start weekday, defaults to SUNDAY |
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.
The end of the year (cloned)
- Type:
- ICAL.
Time
fromData(aData, aZoneopt)
Sets up the current instance using members from the passed data object.
| Name | Type | Attributes | Description |
|---|---|---|---|
aData | ICAL. | Time initialization | |
aZone | ICAL. | <optional> | Timezone this position occurs in |
fromJSDate(aDatenullable, useUTCopt)
Set up the current instance from the Javascript date value.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
aDate | Date | <nullable> | The Javascript Date to read, or null to reset | |
useUTC | Boolean | <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.
| Name | Type | Description |
|---|---|---|
seconds | Number | 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.
| Name | Type | Description |
|---|---|---|
yr | Number | The year to retrieve the letter for |
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.
| Name | Type | Description |
|---|---|---|
aDayOfWeek | ICAL. | Day of week to check |
aPos | Number | Relative position |
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.
| Name | Type | Description |
|---|---|---|
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 |
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.
| Name | Type | Description |
|---|---|---|
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 |
timezone | ICAL. | 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.
| Name | Type | Attributes | Description |
|---|---|---|---|
aFirstDayOfWeek | ICAL. | <optional> | The week start weekday, defaults to SUNDAY |
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.
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
aWeekStart | ICAL. | <optional> | The week start weekday, defaults to SUNDAY |
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.
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.
| Name | Type | Description |
|---|---|---|
aDate | ICAL. | The date to subtract |
The difference as a duration
- Type:
- ICAL.
Duration
subtractDateTz(aDate) → {ICAL.Duration}
Subtract the date details, taking timezones into account.
| Name | Type | Description |
|---|---|---|
aDate | ICAL. | The date to subtract |
The difference in duration
- Type:
- ICAL.
Duration
toICALString() → {String}
Returns an RFC 5545 compliant ical representation of this object.
ical date/date-time
- Type:
- String
toJSDate() → {Date}
Converts the current instance to a Javascript date
- Type:
- Date
toJSON() → {Object}
Converts time to into Object which can be serialized then re-created using the constructor.
- Type:
- Object
// 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).
- Type:
- String
toUnixTime() → {Number}
Converts the current instance to seconds since January 1st 1970.
Seconds since 1970
- Type:
- Number
utcOffset() → {Number}
Calculates the UTC offset of the current date/time in the timezone it is in.
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.
| Name | Type | Description |
|---|---|---|
aWeekStart | ICAL. | The weekday the week starts with |
- See
- Time.weekOneStarts
The ISO week number
- Type:
- Number
(static) daysInMonth(month, year) → {Number}
Returns the days in the given month
| Name | Type | Description |
|---|---|---|
month | Number | The month to check |
year | Number | The year to check |
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.
| Name | Type | Description |
|---|---|---|
aValue | String | The string to create from |
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
aValue | String | The string to create from | |
prop | ICAL. | <optional> | The property the date belongs to |
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.
| Name | Type | Description |
|---|---|---|
aDayOfYear | Number | The day of year |
aYear | Number | The year to create the instance in |
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
aDate | Date | <nullable> | The Javascript Date to read, or null to reset | |
useUTC | Boolean | <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,
| Name | Type | Attributes | Description |
|---|---|---|---|
aValue | String | The string to create from | |
prop | ICAL. | <optional> | The property the date belongs to |
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.
| Name | Type | Description |
|---|---|---|
str | String | The string to create from |
- Deprecated
- Use ICAL.Time.fromDateString instead
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.
| Name | Type | Description |
|---|---|---|
yr | Number | The year to retrieve the letter for |
The dominical letter.
- Type:
- String
(static) isLeapYear(year) → {Boolean}
Checks if the year is a leap year
| Name | Type | Description |
|---|---|---|
year | Number | The year to check |
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)
- Type:
- ICAL.
Time
(static) weekOneStarts(aYear, aWeekStartopt) → {ICAL.Time}
Returns the date on which ISO week number 1 starts.
| Name | Type | Attributes | Description |
|---|---|---|---|
aYear | Number | The year to search in | |
aWeekStart | ICAL. | <optional> | The week start weekday, used for calculation. |
- See
- Time#weekNumber
The date on which week number 1 starts
- Type:
- ICAL.
Time
Type Definitions
timeInit
Time initialization
- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
year | Number | <optional> | The year for this date |
month | Number | <optional> | The month for this date |
day | Number | <optional> | The day for this date |
hour | Number | <optional> | The hour for this date |
minute | Number | <optional> | The minute for this date |
second | Number | <optional> | The second for this date |
isDate | Boolean | <optional> | If true, the instance represents a date (as opposed to a date-time) |
timezone | String | <optional> | Timezone id if zone is unknown [internal] |
zone | ICAL. | <optional> | Resolved timezone object [internal] |
weekDay
The weekday, 1 = SUNDAY, 7 = SATURDAY. Access via ICAL.Time.MONDAY, ICAL.Time.TUESDAY, ...
- Number