Time API

The Time API provides information regarding date/time and time zones.

The JavaScript Date object does not have full timezone support. Date objects allow only simple representations to denote a particular location's offset from Universal Coordinated Time (UTC). This is typically provided as a +/- offset from UTC-0 (also known as Greenwich Mean Time, or GMT) for example, +05:30 denotes that a location is 5 hours and 30 minutes ahead of UTC +00:00. The issue with this method is not getting the correct local time for a given date. The existing methods are sufficient for this purpose. The issue is correctly converting to and from local time and UTC for all points in time - in any of the past, present, and future - based on an initial time provided. This is important for defining relative dates, where a time in a given location may observe different UTC offsets, according to any Daylight Savings Rules (DST) in effect or any other changes that may occur to a location's time zone over time. Without the communication of the explicit time zone rules governing a given date and time, the ability to effectively calculate the offset of the local time to UTC or to any other time zone at any point in the past or future is lost.

This API can be used to get TZDate objects with full time zone support, convert them between timezones, retrieve available timezones.

For more information on the Time features, see Time Guide.

Since: 1.0

Table of Contents


Summary of Interfaces and Methods

Interface Method
TimeManagerObject
TimeUtil TZDate getCurrentDateTime ()
DOMString getLocalTimezone ()
DOMString[] getAvailableTimezones ()
DOMString getDateFormat (optional boolean? shortformat)
DOMString getTimeFormat ()
boolean isLeapYear (long year)
void setDateTimeChangeListener (SuccessCallback changeCallback)
void unsetDateTimeChangeListener ()
void setTimezoneChangeListener (SuccessCallback changeCallback)
void unsetTimezoneChangeListener ()
TZDate long getDate ()
void setDate (long date)
long getDay ()
long getFullYear ()
void setFullYear (long year)
long getHours ()
void setHours (long hours)
long getMilliseconds ()
void setMilliseconds (long ms)
long getMinutes ()
void setMinutes (long minutes)
long getMonth ()
void setMonth (long month)
long getSeconds ()
void setSeconds (long seconds)
long getUTCDate ()
void setUTCDate (long date)
long getUTCDay ()
long getUTCFullYear ()
void setUTCFullYear (long year)
long getUTCHours ()
void setUTCHours (long hours)
long getUTCMilliseconds ()
void setUTCMilliseconds (long ms)
long getUTCMinutes ()
void setUTCMinutes (long minutes)
long getUTCMonth ()
void setUTCMonth (long month)
long getUTCSeconds ()
void setUTCSeconds (long seconds)
DOMString getTimezone ()
TZDate toTimezone (DOMString tzid)
TZDate toLocalTimezone ()
TZDate toUTC ()
TimeDuration difference (TZDate other)
boolean equalsTo (TZDate other)
boolean earlierThan (TZDate other)
boolean laterThan (TZDate other)
TZDate addDuration (TimeDuration duration)
DOMString toLocaleDateString ()
DOMString toLocaleTimeString ()
DOMString toLocaleString ()
DOMString toDateString ()
DOMString toTimeString ()
DOMString toString ()
DOMString getTimezoneAbbreviation ()
long secondsFromUTC ()
boolean isDST ()
TZDate? getPreviousDSTTransition ()
TZDate? getNextDSTTransition ()
TimeDuration TimeDuration difference (TimeDuration other)
boolean equalsTo (TimeDuration other)
boolean lessThan (TimeDuration other)
boolean greaterThan (TimeDuration other)

1. Type Definitions

1.1. TimeDurationUnit

Specifies the TimeDuration unit (milliseconds, seconds, minutes, hours or days).
  enum TimeDurationUnit { "MSECS", "SECS", "MINS", "HOURS", "DAYS" };

Since: 1.0

At least the following values must be supported:

  • MSECS - Indicates a duration in milliseconds
  • SECS - Indicates a duration in seconds
  • MINS - Indicates a duration in minutes
  • HOURS - Indicates a duration in hours
  • DAYS - Indicates a duration in days

2. Interfaces

2.1. TimeManagerObject

The TimeManagerObject interface defines what is instantiated in the tizen object by the Tizen Platform.
  [NoInterfaceObject] interface TimeManagerObject {
    readonly attribute TimeUtil time;
  };
  Tizen implements TimeManagerObject;

Since: 1.0

There will be a tizen.time object that allows accessing the functionality of the Time API.

2.2. TimeUtil

The TimeUtil interface that provides access to the time API.
  [NoInterfaceObject] interface TimeUtil {
    TZDate getCurrentDateTime() raises(WebAPIException);

    DOMString getLocalTimezone() raises(WebAPIException);

    DOMString[] getAvailableTimezones() raises(WebAPIException);

    DOMString getDateFormat(optional boolean? shortformat) raises(WebAPIException);

    DOMString getTimeFormat() raises(WebAPIException);

    boolean isLeapYear(long year) raises(WebAPIException);

    void setDateTimeChangeListener(SuccessCallback changeCallback) raises(WebAPIException);

    void unsetDateTimeChangeListener() raises(WebAPIException);

    void setTimezoneChangeListener(SuccessCallback changeCallback) raises(WebAPIException);

    void unsetTimezoneChangeListener() raises(WebAPIException);

  };

Since: 1.0

This interface offers methods to manage date/time as well as timezones such as:

  • Get the current date/time using getCurrentDateTime().
  • Get timezones using getLocalTimezone() and getAvailableTimezones().

Methods

getCurrentDateTime
Gets the current date/time.
TZDate getCurrentDateTime();
             

Since: 1.0

Return value:

TZDate The current TZDate object

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var current_dt = tizen.time.getCurrentDateTime();
 console.log("current date/time is " + current_dt.toLocaleString());
 
getLocalTimezone
Gets the identifier of the local system timezone.
DOMString getLocalTimezone();
             

Since: 1.0

Return value:

Timezone The local timezone

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 console.log("The local time zone is " + tizen.time.getLocalTimezone());
 
getAvailableTimezones
Gets synchronously the identifiers of the timezones supported by the device.
DOMString[] getAvailableTimezones();
             

Since: 1.0

Zero or more slashes separate different components of a timezone identifier, with the most general descriptor first and the most specific one last. For example, 'Europe/Berlin', 'America/Argentina/Buenos_Aires'.

Return value:

The array of time zone identifiers

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var tzids = tizen.time.getAvailableTimezones();
 console.log("The device supports " + tzids.length + " time zones.");
 
getDateFormat
DOMString getDateFormat(optional boolean? shortformat);
             

Since: 1.0

Gets the date format according to the system's locale settings.

These expressions may be used in the returned string:

  • "d" = day number (1 to 31)
  • "D" = day name
  • "m" = month number (1 to 12)
  • "M" = month name
  • "y" = year

Examples of string formats include: "d/m/y", "y-d-m", "D, M d y".

Parameters:

  • shortformat [optional] [nullable]: The flag indicating whether the user is interested in the short date format (23/10/2011) instead of a long date format ("Monday, October 23 2011")
    By default, this attribute is set to false.

Return value:

DOMString The date format according to the system's locale settings

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

getTimeFormat
DOMString getTimeFormat();
             

Since: 1.0

Gets the time format according to the system's locale settings.

These expressions may be used in the returned string:

  • "h" = hours (0 to 23 or 1 to 12 if AM/PM display)
  • "m" = minutes (0 to 59)
  • "s" = seconds (0 to 59)
  • "ap" = AM/PM display

Examples of string formats include: "h:m:s ap", "h:m:s".

Return value:

DOMString The time format according to the system's locale settings

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

isLeapYear
Checks whether the given year is a leap year.
boolean isLeapYear(long year);
             

Since: 1.0

Parameters:

  • year: The year to check

Return value:

boolean true, if the year is a leap year

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type InvalidValuesError, if any of the input parameters contain an invalid value.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var current_dt = tizen.time.getCurrentDateTime();
 var is_leap = tizen.time.isLeapYear(current_dt.getFullYear());
 if (is_leap) {
   console.log("This year is a leap year.");
 }
 
setDateTimeChangeListener
Sets a listener to receive notification of changes to the time/date on a device.
void setDateTimeChangeListener(SuccessCallback changeCallback);
             

Since: 2.3

Listener set with setTimezoneChangeListener() method is called when device time was set by the user.

Parameters:

  • changeCallback: Callback method to be invoked when device time was set
    It is not invoked when time passes naturally.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var changedCallback = function() {
     try {
         var current_dt = tizen.time.getCurrentDateTime();
         console.log("current date/time is " + current_dt.toLocaleString());

     } catch (err) {
         console.log (err.name + ": " + err.message);
     }
 };

 tizen.time.setDateTimeChangeListener(changedCallback);

 
unsetDateTimeChangeListener
Unsets the listener to stop receiving notification of changes to the time/date on a device.
void unsetDateTimeChangeListener();
             

Since: 2.3

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var changedCallback = function() {
     try {
         var current_dt = tizen.time.getCurrentDateTime();
         console.log("current date/time is " + current_dt.toLocaleString());
         tizen.time.unsetDateTimeChangeListener();
     } catch (err) {
         console.log (err.name + ": " + err.message);
     }
 };

 tizen.time.setDateTimeChangeListener(changedCallback);

 
setTimezoneChangeListener
Sets a listener to receive notification of changes to the time zone on a device.
void setTimezoneChangeListener(SuccessCallback changeCallback);
             

Since: 2.3

Listener set with setTimezoneChangeListener() method is called when device time zone has changed.

Parameters:

  • changeCallback: Callback method that is invoked when the time zone has changed

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var changedCallback = function() {
     try {
         // The new time zone can be retrieved through tizen.time.getLocalTimezone()
         var zone = tizen.time.getLocalTimezone();
         console.log("current time zone is " + zone);
     } catch (err) {
         console.log (err.name + ": " + err.message);
     }
 };

 tizen.time.setTimezoneChangeListener(changedCallback);

 
unsetTimezoneChangeListener
Unsets the listener to stop receiving notification of changes to the time zone on a device.
void unsetTimezoneChangeListener();
             

Since: 2.3

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var changedCallback = function() {
     try {
         var zone = tizen.time.getLocalTimezone();
         console.log("current time zone is " + zone);
         tizen.time.unsetTimezoneChangeListener();
     } catch (err) {
         console.log (err.name + ": " + err.message);
     }
 };

 tizen.time.setTimezoneChangeListener(changedCallback);
 

2.3. TZDate

The TZDate interface represents information regarding a given date/time in a predefined timezone. If its date/time exceeds the platform limit, TZDate will be invalid.
  [Constructor(optional Date? datetime, optional DOMString? timezone),
   Constructor(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone)]

  interface TZDate {
    long getDate();

    void setDate(long date);

    long getDay();

    long getFullYear();

    void setFullYear(long year);

    long getHours();

    void setHours(long hours);

    long getMilliseconds();

    void setMilliseconds(long ms);

    long getMinutes();

    void setMinutes(long minutes);

    long getMonth();

    void setMonth(long month);

    long getSeconds();

    void setSeconds(long seconds);

    long getUTCDate();

    void setUTCDate(long date);

    long getUTCDay();

    long getUTCFullYear();

    void setUTCFullYear(long year);

    long getUTCHours();

    void setUTCHours(long hours);

    long getUTCMilliseconds();

    void setUTCMilliseconds(long ms);

    long getUTCMinutes();

    void setUTCMinutes(long minutes);

    long getUTCMonth();

    void setUTCMonth(long month);

    long getUTCSeconds();

    void setUTCSeconds(long seconds);

    DOMString getTimezone();

    TZDate toTimezone(DOMString tzid) raises(WebAPIException);

    TZDate toLocalTimezone() raises(WebAPIException);

    TZDate toUTC() raises(WebAPIException);

    TimeDuration difference(TZDate other) raises(WebAPIException);

    boolean equalsTo(TZDate other) raises(WebAPIException);

    boolean earlierThan(TZDate other) raises(WebAPIException);

    boolean laterThan(TZDate other) raises(WebAPIException);

    TZDate addDuration(TimeDuration duration) raises(WebAPIException);

    DOMString toLocaleDateString();

    DOMString toLocaleTimeString();

    DOMString toLocaleString();

    DOMString toDateString();

    DOMString toTimeString();

    DOMString toString();

    DOMString getTimezoneAbbreviation() raises(WebAPIException);

    long secondsFromUTC() raises(WebAPIException);

    boolean isDST() raises(WebAPIException);

    TZDate? getPreviousDSTTransition() raises(WebAPIException);

    TZDate? getNextDSTTransition() raises(WebAPIException);
  };

Since: 1.0

Constructors

TZDate(optional Date? datetime, optional DOMString? timezone);
TZDate(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone);
  • year : The year of TZDate. If it is between 0 and 99, 1900 will be added to it like Javascript Date object.

Methods

getDate
Gets the day of the month (from 1-31).
long getDate();
             

Since: 1.0

Return value:

long The day of the month.
setDate
Sets the day of the month (from 1-31).
void setDate(long date);
             

Since: 1.0

If it tries to set the day bigger than the last day of the month or smaller than 1, it will be calculated automatically. For example, if TZDate's month is May and parameter is 32, it will be June 1.

Parameters:

  • date: Date to set
getDay
Gets the day of the week (from 0-6).
long getDay();
             

Since: 1.0

Return value:

long The day of the week
getFullYear
Gets the year.
long getFullYear();
             

Since: 1.0

Positive values indicate AD(Anno Domini) years. 0 and negative values indicate BC(Before Christ) years. For example, 1 = AD 1, 0 = BC 1, -1 = BC 2.

Return value:

long The year
setFullYear
Sets the year.
void setFullYear(long year);
             

Since: 1.0

Parameters:

  • year: Year to set
getHours
Gets the hour (0-23).
long getHours();
             

Since: 1.0

Return value:

long The hour
setHours
Sets the hour (0-23).
void setHours(long hours);
             

Since: 1.0

If it tries to set the hour bigger than 23 or smaller than 0, it will be calculated automatically. For example, if hours is 24, it will set 0 and add to a date.

Parameters:

  • hours: Hours to set
getMilliseconds
Gets the milliseconds (from 0-999).
long getMilliseconds();
             

Since: 1.0

Return value:

long The milliseconds
setMilliseconds
Sets the milliseconds (from 0-999).
void setMilliseconds(long ms);
             

Since: 1.0

If it tries to set the millisecond bigger than 999 or smaller than 0, it will be calculated automatically. For example, if ms is 1000, it will set 0 and add to a second.

Parameters:

  • ms: Milliseconds to set
getMinutes
Gets the minutes (from 0-59).
long getMinutes();
             

Since: 1.0

Return value:

long The minutes
setMinutes
Sets the minutes.
void setMinutes(long minutes);
             

Since: 1.0

If it tries to set the minute bigger than 59 or smaller than 0, it will be calculated automatically. For example, if minutes is 60, it will set 0 and add to an hour.

Parameters:

  • minutes: Minutes to set
getMonth
Gets the month (from 0-11).
long getMonth();
             

Since: 1.0

Return value:

long The month
setMonth
Sets the month (from 0-11).
void setMonth(long month);
             

Since: 1.0

If it tries to set the month bigger than 11 or smaller than 0, it will be calculated automatically. For example, if month is 12, it will set 0 and add to a year.

Parameters:

  • month: Month to set
getSeconds
Gets the seconds (from 0-59).
long getSeconds();
             

Since: 1.0

Return value:

long The seconds
setSeconds
Sets the seconds (from 0-59).
void setSeconds(long seconds);
             

Since: 1.0

If it tries to set the second bigger than 59 or smaller than 0, it will be calculated automatically. For example, if seconds is 60, it will set 0 and add to a minute.

Parameters:

  • seconds: Seconds to set
getUTCDate
Gets the day of the month, according to universal time (from 1-31).
long getUTCDate();
             

Since: 1.0

Return value:

long The day of the month, according to universal time
setUTCDate
Sets the day of the month, according to universal time (from 1-31).
void setUTCDate(long date);
             

Since: 1.0

If it tries to set the day bigger than the last day of the month or smaller than 1, it will be calculated automatically. For example, if TZDate's month is May and date is 32, it will be June 1.

Parameters:

  • date: Date to set
getUTCDay
Gets the day of the week, according to universal time (from 0-6).
long getUTCDay();
             

Since: 1.0

Return value:

long The day of the week, according to universal time
getUTCFullYear
Gets the year, according to universal time.
long getUTCFullYear();
             

Since: 1.0

Positive values indicate AD(Anno Domini) years. 0 and negative values indicate BC(Before Christ) years. For example, 1 = AD 1, 0 = BC 1, -1 = BC 2.

Return value:

long The year, according to universal time
setUTCFullYear
Sets the year, according to universal time.
void setUTCFullYear(long year);
             

Since: 1.0

Parameters:

  • year: Year to set
getUTCHours
Gets the hour, according to universal time (0-23).
long getUTCHours();
             

Since: 1.0

Return value:

long The hour, according to universal time
setUTCHours
Sets the hour, according to universal time (0-23).
void setUTCHours(long hours);
             

Since: 1.0

If it tries to set the hour bigger than 23 or smaller than 0, it will be calculated automatically. For example, if hours is 24, it will set 0 and add to a date.

Parameters:

  • hours: Hours to set
getUTCMilliseconds
Gets the milliseconds, according to universal time (from 0-999).
long getUTCMilliseconds();
             

Since: 1.0

Return value:

long The milliseconds, according to universal time
setUTCMilliseconds
Sets the milliseconds, according to universal time (from 0-999).
void setUTCMilliseconds(long ms);
             

Since: 1.0

If it tries to set the millisecond bigger than 999 or smaller than 0, it will be calculated automatically. For example, if ms is 1000, it will set 0 and add to a second.

Parameters:

  • ms: Milliseconds to set
getUTCMinutes
Gets the minutes, according to universal time (from 0-59).
long getUTCMinutes();
             

Since: 1.0

Return value:

long The minutes, according to universal time
setUTCMinutes
Sets the minutes, according to universal time (from 0-59).
void setUTCMinutes(long minutes);
             

Since: 1.0

If it tries to set the minute bigger than 59 or smaller than 0, it will be calculated automatically. For example, if minutes is 60, it will set 0 and add to an hour.

Parameters:

  • minutes: Minutes to set
getUTCMonth
Gets the month, according to universal time (from 0-11).
long getUTCMonth();
             

Since: 1.0

Return value:

long The month, according to universal time
setUTCMonth
Sets the month, according to universal time (from 0-11).
void setUTCMonth(long month);
             

Since: 1.0

If it tries to set the month bigger than 11 or smaller than 0, it will be calculated automatically. For example, if month is 12, it will set 0 and add to a year.

Parameters:

  • month: Month to set
getUTCSeconds
Gets the seconds, according to universal time (from 0-59).
long getUTCSeconds();
             

Since: 1.0

Return value:

long The seconds, according to universal time
setUTCSeconds
Sets the seconds, according to universal time (from 0-59).
void setUTCSeconds(long seconds);
             

Since: 1.0

If it tries to set the second bigger than 59 or smaller than 0, it will be calculated automatically. For example, if seconds is 60, it will set 0 and add to a minute.

Parameters:

  • seconds: Seconds to set
getTimezone
Gets the timezone identifier.
DOMString getTimezone();
             

Since: 1.0

Zero or more slashes separate different components, with the most general descriptor first and the most specific one last. For example, 'Europe/Berlin', 'America/Argentina/Buenos_Aires'.

This attribute uniquely identifies the timezone.

Return value:

DOMString The string timezone identifier
If TZDate is invalid, it will return 'Invalid Date'.
toTimezone
Gets a copy of the TZDate converted to a given time zone.
TZDate toTimezone(DOMString tzid);
             

Since: 1.0

Parameters:

  • tzid: Timezone identifier to set

Return value:

TZDate The new TZDate in given Timezone

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type InvalidValuesError, if the provided TZID is not recognized as a valid timezone identifier.

    • with error type UnknownError, if the call failed due to an unknown error.

toLocalTimezone
Gets a copy of the TZDate converted to the local time zone.
TZDate toLocalTimezone();
             

Since: 1.0

Return value:

TZDate The new TZDate in local Timezone

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

toUTC
Gets a copy of the TZDate converted to Coordinated Universal Time (UTC).
TZDate toUTC();
             

Since: 1.0

Return value:

TZDate The Date/Time in UTC

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

difference
Calculates the difference with another TZDate object.
TimeDuration difference(TZDate other);
             

Since: 1.0

Calculates the difference in time between this and the other object. This comparison method takes timezones into consideration for the comparison.

The TimeDuration that is returned is effectively this - other. The return value is a duration in milliseconds both TZDate objects have a time component, in days, otherwise. The result value will be:

  • Negative, if other is in the future
  • 0 if the two date/times are equal
  • Positive, if other is in the past

Parameters:

  • other: The other Date/Time to compare to

Return value:

TimeDuration The duration in milliseconds between the two date/time objects (or in days for comparison between dates with no time component)

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

equalsTo
Checks whether the TZDate is equal to another.
boolean equalsTo(TZDate other);
             

Since: 1.0

This method takes the timezones into consideration and will return trueif the two TZDate objects represent the same instant in different timezones.

Parameters:

  • other: Other Date/Time to compare to

Return value:

boolean true if the 2 date/times are the same

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

earlierThan
Checks whether the TZDate is earlier than another.
boolean earlierThan(TZDate other);
             

Since: 1.0

This method takes the timezones into consideration.

Parameters:

  • other: The other Date/Time to compare to

Return value:

boolean true, if the Date/Time is earlier than the one passed in argument

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

laterThan
Checks whether the TZDate is later than another.
boolean laterThan(TZDate other);
             

Since: 1.0

This method takes the timezones into consideration.

Parameters:

  • other: The other Date/Time to compare to

Return value:

boolean true, if the Date/Time is later than the one passed in argument

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

addDuration
Gets a new date by adding a duration to the current TZDate object.
TZDate addDuration(TimeDuration duration);
             

Since: 1.0

If the length of duration is negative, the new date/time will be earlier than it used to.

Note that calling this method does not alter the current object.

Parameters:

  • duration: TimeDuration to add

Return value:

TZDate The new TZDate by adding a duration

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var now = tizen.time.getCurrentDateTime();
 var in_one_week = now.addDuration(new tizen.TimeDuration(7, "DAYS"));
 
toLocaleDateString
Gets the date portion of a TZDate object as a string, using locale conventions.
DOMString toLocaleDateString();
             

Since: 1.0

Return value:

DOMString The date portion of the TZDate object as a string, using locale conventions
If TZDate is invalid, it will return 'Invalid Date'.
toLocaleTimeString
Gets the time portion of a TZDate object as a string, using locale conventions.
DOMString toLocaleTimeString();
             

Since: 1.0

Return value:

DOMString The time portion of the TZDate object as a string, using locale conventions
If TZDate is invalid, it will return 'Invalid Date'.
toLocaleString
Converts a TZDate object to a string, using locale conventions.
DOMString toLocaleString();
             

Since: 1.0

Return value:

DOMString The string representation of the TZDate object, using locale conventions
If TZDate is invalid, it will return 'Invalid Date'.
toDateString
Gets the date portion of a TZDate object as a string.
DOMString toDateString();
             

Since: 1.0

Return value:

DOMString The date portion of the TZDate object as a string
If TZDate is invalid, it will return 'Invalid Date'.
toTimeString
Gets the time portion of a TZDate object as a string.
DOMString toTimeString();
             

Since: 1.0

Return value:

DOMString The time portion of the TZDate object as a string
If TZDate is invalid, it will return 'Invalid Date'.
toString
Converts a TZDate object to a string.
DOMString toString();
             

Since: 1.0

Return value:

DOMString The string representation of the TZDate object
If TZDate is invalid, it will return 'Invalid Date'.
getTimezoneAbbreviation
Determines the time zone abbreviation to be used at a particular date in the time zone.

Deprecated. Some timezones return "GMT[+-]hh:mm". It is inconsistent.

DOMString getTimezoneAbbreviation();
             

Since: 1.0

For example, in Toronto this is currently "EST" during the winter months and "EDT" during the summer months when daylight savings time is in effect.

Return value:

DOMString The abbreviation of the time zone (such as "EST")
If TZDate is invalid, it will return 'Invalid Date'.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

secondsFromUTC
Gets the number of seconds from Coordinated Universal Time (UTC) offset for the timezone.
long secondsFromUTC();
             

Since: 1.0

Returns the offset (in seconds) from UTC of the timezone, accounting for daylight savings if it is in the timezone. For example, if time zone is GMT+8, it will return -32,400.

Return value:

long The offset from UTC in seconds

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var offset = tizen.time.getCurrentDateTime().secondsFromUTC();
 var myDate = new Date();
 var exp_offset = myDate.getTimezoneOffset()*60;
 //offset is equals to exp_offset.
 
isDST
Checks whether Daylight Saving Time(DST) is active for this TZDate.
boolean isDST();
             

Since: 1.0

Indicates if daylight savings are in effect for the time zone and instant identified by the TZDate object.

Return value:

boolean The flag indicating whether the daylight saving are in effect

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

getPreviousDSTTransition
Gets the date of the previous daylight saving time transition for the timezone.
TZDate? getPreviousDSTTransition();
             

Since: 1.0

Return value:

TZDate The date of the previous daylight saving transition (before the instant identified by the TZDate)

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

getNextDSTTransition
Gets the date of the next daylight saving time transition for the timezone.
TZDate? getNextDSTTransition();
             

Since: 1.0

Return value:

TZDate The date of the next daylight saving transition (after the instant identified by the TZDate)

Exceptions:

  • WebAPIException
    • with error type UnknownError, if the call failed due to an unknown error.

2.4. TimeDuration

The TimeDuration interface that contains the length and its associated time unit.
  [Constructor(long long length, optional TimeDurationUnit? unit)]
  interface TimeDuration
  {
    attribute long long length;

    attribute TimeDurationUnit unit;

    TimeDuration difference(TimeDuration other) raises(WebAPIException);

    boolean equalsTo(TimeDuration other) raises(WebAPIException);

    boolean lessThan(TimeDuration other) raises(WebAPIException);

    boolean greaterThan(TimeDuration other) raises(WebAPIException);
  };

Since: 1.0

Code example:

 var now = tizen.time.getCurrentDateTime();
 var tomorrow = now.addDuration(new tizen.TimeDuration(1, "DAYS")); // Becomes tomorrow, same time.
 

Constructors

TimeDuration(long long length, optional TimeDurationUnit? unit);

Attributes

  • long long length
    The duration length.

    The unit of the duration length (milliseconds, seconds, minutes, hours, or days) is determined by the duration unit attribute.

    Since: 1.0

  • TimeDurationUnit unit
    The duration unit (milliseconds, seconds, minutes, hours, or days).

    The default value is "MSECS" (milliseconds unit).

    Since: 1.0

Methods

difference
Calculates the difference between two TimeDuration objects.
TimeDuration difference(TimeDuration other);
             

Since: 1.0

Calculates the difference in time between this and other. The TimeDuration that is returned is effectively first - other (that is: positive if the first parameter is larger).

The returned TimeDuration is the biggest possible unit without losing the precision.

Parameters:

  • other: Other TimeDuration object to compare to

Return value:

The new TimeDuration object corresponding to the result of this - other.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 // Assume that event1 and event2 are tizen.CalendarEvent objects.
 // Computes event1.duration - event2.duration
 var diff = event1.duration.difference(event2.duration);
 if (diff.length > 0)
   console.log("The event1 is longer than event2.");
 else if (diff.length == 0)
   console.log("The duration of two events is same.");
 else
   console.log("The event1 is shorter than the event2.");
 
equalsTo
Checks whether the TimeDuration is equal to another.
boolean equalsTo(TimeDuration other);
             

Since: 1.0

This method takes the units into consideration and will return true if the two TimeDuration objects represent the same duration in different units.

Parameters:

  • other: Other TimeDuration object to compare to

Return value:

boolean true if the two TimeDuration object represent the same duration

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var d1 = new tizen.TimeDuration(60, "MINS"); // 60 minutes
 var d2 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
 var ret = d1.equalsTo(d2); // Returns true
 
lessThan
Checks whether the TimeDuration is lower than another.
boolean lessThan(TimeDuration other);
             

Since: 1.0

This method takes the units into consideration when doing the comparison.

Parameters:

  • other: Other TimeDuration object to compare to

Return value:

boolean true if the TimeDuration is less than other

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var d1 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
 var d2 = new tizen.TimeDuration(120, "MINS"); // 120 minutes
 var ret = d1.lessThan(d2); // Returns true
 
greaterThan
Checks whether the TimeDuration is greater than another.
boolean greaterThan(TimeDuration other);
             

Since: 1.0

This method takes the units into consideration when doing the comparison.

Parameters:

  • other: Other TimeDuration object to compare to

Return value:

boolean true if the TimeDuration is greater than other

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if the call failed due to an unknown error.

Code example:

 var d1 = new tizen.TimeDuration(120, "MINS"); // 120 minutes
 var d2 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
 var ret = d1.greaterThan(d2); // Returns true
 

3. Full WebIDL

module Time {

  enum TimeDurationUnit { "MSECS", "SECS", "MINS", "HOURS", "DAYS" };

  [NoInterfaceObject] interface TimeManagerObject {
    readonly attribute TimeUtil time;
  };
  Tizen implements TimeManagerObject;

  [NoInterfaceObject] interface TimeUtil {
    TZDate getCurrentDateTime() raises(WebAPIException);

    DOMString getLocalTimezone() raises(WebAPIException);

    DOMString[] getAvailableTimezones() raises(WebAPIException);

    DOMString getDateFormat(optional boolean? shortformat) raises(WebAPIException);

    DOMString getTimeFormat() raises(WebAPIException);

    boolean isLeapYear(long year) raises(WebAPIException);

    void setDateTimeChangeListener(SuccessCallback changeCallback) raises(WebAPIException);

    void unsetDateTimeChangeListener() raises(WebAPIException);

    void setTimezoneChangeListener(SuccessCallback changeCallback) raises(WebAPIException);

    void unsetTimezoneChangeListener() raises(WebAPIException);

  };

  [Constructor(optional Date? datetime, optional DOMString? timezone),
   Constructor(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone)]

  interface TZDate {
    long getDate();

    void setDate(long date);

    long getDay();

    long getFullYear();

    void setFullYear(long year);

    long getHours();

    void setHours(long hours);

    long getMilliseconds();

    void setMilliseconds(long ms);

    long getMinutes();

    void setMinutes(long minutes);

    long getMonth();

    void setMonth(long month);

    long getSeconds();

    void setSeconds(long seconds);

    long getUTCDate();

    void setUTCDate(long date);

    long getUTCDay();

    long getUTCFullYear();

    void setUTCFullYear(long year);

    long getUTCHours();

    void setUTCHours(long hours);

    long getUTCMilliseconds();

    void setUTCMilliseconds(long ms);

    long getUTCMinutes();

    void setUTCMinutes(long minutes);

    long getUTCMonth();

    void setUTCMonth(long month);

    long getUTCSeconds();

    void setUTCSeconds(long seconds);

    DOMString getTimezone();

    TZDate toTimezone(DOMString tzid) raises(WebAPIException);

    TZDate toLocalTimezone() raises(WebAPIException);

    TZDate toUTC() raises(WebAPIException);

    TimeDuration difference(TZDate other) raises(WebAPIException);

    boolean equalsTo(TZDate other) raises(WebAPIException);

    boolean earlierThan(TZDate other) raises(WebAPIException);

    boolean laterThan(TZDate other) raises(WebAPIException);

    TZDate addDuration(TimeDuration duration) raises(WebAPIException);

    DOMString toLocaleDateString();

    DOMString toLocaleTimeString();

    DOMString toLocaleString();

    DOMString toDateString();

    DOMString toTimeString();

    DOMString toString();

    DOMString getTimezoneAbbreviation() raises(WebAPIException);

    long secondsFromUTC() raises(WebAPIException);

    boolean isDST() raises(WebAPIException);

    TZDate? getPreviousDSTTransition() raises(WebAPIException);

    TZDate? getNextDSTTransition() raises(WebAPIException);
  };

  [Constructor(long long length, optional TimeDurationUnit? unit)]
  interface TimeDuration
  {
    attribute long long length;

    attribute TimeDurationUnit unit;

    TimeDuration difference(TimeDuration other) raises(WebAPIException);

    boolean equalsTo(TimeDuration other) raises(WebAPIException);

    boolean lessThan(TimeDuration other) raises(WebAPIException);

    boolean greaterThan(TimeDuration other) raises(WebAPIException);
  };
};