ICAL. VCardTime

Describes a vCard time, which has slight differences to the ICAL.Time. Properties can be null if not specified, for example for dates with reduced accuracy or truncation.

Note that currently not all methods are correctly re-implemented for VCardTime. For example, comparison will have undefined results when some members are null.

Also, normalization is not yet implemented for this class!

Constructor

new VCardTime(data, zone, icaltype)

Creates a new ICAL.VCardTime instance.

Parameters:
NameTypeDescription
dataObject

The data for the time instance

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

zoneICAL.Timezone | ICAL.UtcOffset

The timezone to use

icaltypeString

The type for this date/time object

Extends

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
  • "vcardtime"

icaltype :String

The type name, to be used in the jCal object.

Type:
  • String
Default Value
  • "date-and-or-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.VCardTime}

Returns a clone of the vcard date/time object.

Returns:

The cloned object

Type: 
ICAL.VCardTime

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

fromJSDate(aDatenullable, useUTC)

Set up the current instance from the Javascript date value.

Parameters:
NameTypeAttributesDescription
aDateDate<nullable>

The Javascript Date to read, or null to reset

useUTCBoolean

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 6350 compliant representation of this object.

Returns:

vcard date/time string

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 jCard 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

Returns:

The ISO week number

Type: 
Number

(static) fromDateAndOrTimeString(aValue, aIcalType) → {ICAL.VCardTime}

Returns a new ICAL.VCardTime instance from a date and/or time string.

Parameters:
NameTypeDescription
aValueString

The string to create from

aIcalTypeString

The type for this instance, e.g. date-and-or-time

Returns:

The date/time instance

Type: 
ICAL.VCardTime