Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / i18n / unicode / timezone.h
index a06d33d..6be60e0 100644 (file)
@@ -1,5 +1,5 @@
 /*************************************************************************
-* Copyright (c) 1997-2010, International Business Machines Corporation
+* Copyright (c) 1997-2013, International Business Machines Corporation
 * and others. All Rights Reserved.
 **************************************************************************
 *
@@ -39,6 +39,7 @@
 #include "unicode/uobject.h"
 #include "unicode/unistr.h"
 #include "unicode/ures.h"
+#include "unicode/ucal.h"
 
 U_NAMESPACE_BEGIN
 
@@ -66,7 +67,8 @@ class StringEnumeration;
  * </pre>
  * \htmlonly</blockquote>\endhtmlonly
  * You can use <code>getAvailableIDs</code> method to iterate through
- * all the supported time zone IDs. You can then choose a
+ * all the supported time zone IDs, or getCanonicalID method to check
+ * if a time zone ID is supported or not.  You can then choose a
  * supported ID to get a <code>TimeZone</code>.
  * If the time zone you want is not represented by one of the
  * supported IDs, then you can create a custom time zone ID with
@@ -80,8 +82,13 @@ class StringEnumeration;
  *
  * For example, you might specify GMT+14:00 as a custom
  * time zone ID.  The <code>TimeZone</code> that is returned
- * when you specify a custom time zone ID does not include
- * daylight savings time.
+ * when you specify a custom time zone ID uses the specified
+ * offset from GMT(=UTC) and does not observe daylight saving
+ * time. For example, you might specify GMT+14:00 as a custom
+ * time zone ID to create a TimeZone representing 14 hours ahead
+ * of GMT (with no daylight saving time). In addition,
+ * <code>getCanonicalID</code> can also be used to
+ * normalize a custom time zone ID.
  *
  * TimeZone is an abstract class representing a time zone.  A TimeZone is needed for
  * Calendar to produce local time for a particular time zone.  A TimeZone comprises
@@ -97,8 +104,8 @@ class StringEnumeration;
  * </ul>
  *
  * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle
- * daylight savings time and GMT offset in different ways.  Currently we only have one
- * TimeZone subclass: SimpleTimeZone.)
+ * daylight savings time and GMT offset in different ways.  Currently we have the following
+ * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.)
  * <P>
  * The TimeZone class contains a static list containing a TimeZone object for every
  * combination of GMT offset and daylight-savings time rules currently in use in the
@@ -127,9 +134,29 @@ public:
     virtual ~TimeZone();
 
     /**
-     * The GMT time zone has a raw offset of zero and does not use daylight
+     * Returns the "unknown" time zone.
+     * It behaves like the GMT/UTC time zone but has the
+     * <code>UCAL_UNKNOWN_ZONE_ID</code> = "Etc/Unknown".
+     * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized.
+     *
+     * @return the "unknown" time zone.
+     * @see UCAL_UNKNOWN_ZONE_ID
+     * @see createTimeZone
+     * @see getGMT
+     * @stable ICU 49
+     */
+    static const TimeZone& U_EXPORT2 getUnknown();
+
+    /**
+     * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight
      * savings time. This is a commonly used time zone.
-     * @return the GMT time zone.
+     *
+     * <p>Note: For backward compatibility reason, the ID used by the time
+     * zone returned by this method is "GMT", although the ICU's canonical
+     * ID for the GMT time zone is "Etc/GMT".
+     *
+     * @return the GMT/UTC time zone.
+     * @see getUnknown
      * @stable ICU 2.0
      */
     static const TimeZone* U_EXPORT2 getGMT(void);
@@ -138,15 +165,37 @@ public:
      * Creates a <code>TimeZone</code> for the given ID.
      * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles",
      * or a custom ID such as "GMT-8:00".
-     * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
-     * cannot be understood.  Return result guaranteed to be non-null.  If you
-     * require that the specific zone asked for be returned, check the ID of the
-     * return result.
+     * @return the specified <code>TimeZone</code>, or a mutable clone of getUnknown()
+     * if the given ID cannot be understood or if the given ID is "Etc/Unknown".
+     * The return result is guaranteed to be non-NULL.
+     * If you require that the specific zone asked for be returned,
+     * compare the result with getUnknown() or check the ID of the return result.
      * @stable ICU 2.0
      */
     static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
 
     /**
+     * Returns an enumeration over system time zone IDs with the given
+     * filter conditions.
+     * @param zoneType      The system time zone type.
+     * @param region        The ISO 3166 two-letter country code or UN M.49
+     *                      three-digit area code. When NULL, no filtering
+     *                      done by region. 
+     * @param rawOffset     An offset from GMT in milliseconds, ignoring
+     *                      the effect of daylight savings time, if any.
+     *                      When NULL, no filtering done by zone offset. 
+     * @param ec            Output param to filled in with a success or
+     *                      an error.
+     * @return an enumeration object, owned by the caller.
+     * @stable ICU 4.8
+     */
+    static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
+        USystemTimeZoneType zoneType,
+        const char* region,
+        const int32_t* rawOffset,
+        UErrorCode& ec);
+
+    /**
      * Returns an enumeration over all recognized time zone IDs. (i.e.,
      * all strings that createTimeZone() accepts)
      *
@@ -242,21 +291,30 @@ public:
      * Sets the default time zone (i.e., what's returned by createDefault()) to be the
      * specified time zone.  If NULL is specified for the time zone, the default time
      * zone is set to the default host time zone.  This call adopts the TimeZone object
-     * passed in; the clent is no longer responsible for deleting it.
+     * passed in; the client is no longer responsible for deleting it.
+     *
+     * <p>This function is not thread safe. It is an error for multiple threads
+     * to concurrently attempt to set the default time zone, or for any thread
+     * to attempt to reference the default zone while another thread is setting it.
      *
      * @param zone  A pointer to the new TimeZone object to use as the default.
      * @stable ICU 2.0
      */
     static void U_EXPORT2 adoptDefault(TimeZone* zone);
 
+#ifndef U_HIDE_SYSTEM_API
     /**
      * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted;
      * the caller remains responsible for deleting it.
      *
+     * <p>See the thread safety note under adoptDefault().
+     *
      * @param zone  The given timezone.
      * @system
+     * @stable ICU 2.0
      */
     static void U_EXPORT2 setDefault(const TimeZone& zone);
+#endif  /* U_HIDE_SYSTEM_API */
 
     /**
      * Returns the timezone data version currently used by ICU.
@@ -300,6 +358,63 @@ public:
     static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
         UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
 
+#ifndef U_HIDE_DRAFT_API
+    /**
+    * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
+    * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
+    *
+    * <p>There are system time zones that cannot be mapped to Windows zones. When the input
+    * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be
+    * empty, but the operation itself remains successful (no error status set on return).
+    *
+    * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+    * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+    * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+    * Updating the Time Zone Data</a>.
+    *
+    * @param id        A system time zone ID.
+    * @param winid     Receives a Windows time zone ID. When the input system time zone ID is unknown
+    *                  or unmappable to a Windows time zone ID, then an empty string is set on return.
+    * @param status    Receives the status.
+    * @return          A reference to the result (<code>winid</code>).
+    * @see getIDForWindowsID
+    *
+    * @draft ICU 52
+    */
+    static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
+        UnicodeString& winid, UErrorCode& status);
+
+    /**
+    * Converts a Windows time zone ID to an equivalent system time zone ID
+    * for a region. For example, system time zone ID "America/Los_Angeles" is returned
+    * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
+    * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
+    * region "CA".
+    *
+    * <p>Not all Windows time zones can be mapped to system time zones. When the input
+    * Windows time zone ID is unknown or unmappable to a system time zone, then the result
+    * will be empty, but the operation itself remains successful (no error status set on return).
+    *
+    * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+    * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+    * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+    * Updating the Time Zone Data</a>.
+    *
+    * @param winid     A Windows time zone ID.
+    * @param region    A null-terminated region code, or <code>NULL</code> if no regional preference.
+    * @param id        Receives a system time zone ID. When the input Windows time zone ID is unknown
+    *                  or unmappable to a system time zone ID, then an empty string is set on return.
+    * @param status    Receives the status.
+    * @return          A reference to the result (<code>id</code>).
+    * @see getWindowsID
+    *
+    * @draft ICU 52
+    */
+    static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
+        UnicodeString& id, UErrorCode& status);
+
+#endif /* U_HIDE_DRAFT_API */
+
     /**
      * Returns true if the two TimeZones are equal.  (The TimeZone version only compares
      * IDs, but subclasses are expected to also compare the fields they add.)
@@ -554,6 +669,34 @@ public:
      * Queries if this time zone uses daylight savings time.
      * @return true if this time zone uses daylight savings time,
      * false, otherwise.
+     * <p><strong>Note:</strong>The default implementation of
+     * ICU TimeZone uses the tz database, which supports historic
+     * rule changes, for system time zones. With the implementation,
+     * there are time zones that used daylight savings time in the
+     * past, but no longer used currently. For example, Asia/Tokyo has
+     * never used daylight savings time since 1951. Most clients would
+     * expect that this method to return <code>FALSE</code> for such case.
+     * The default implementation of this method returns <code>TRUE</code>
+     * when the time zone uses daylight savings time in the current
+     * (Gregorian) calendar year.
+     * <p>In Java 7, <code>observesDaylightTime()</code> was added in
+     * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code>
+     * only checks if daylight saving time is observed by the last known
+     * rule. This specification might not be what most users would expect
+     * if daylight saving time is currently observed, but not scheduled
+     * in future. In this case, Java's <code>userDaylightTime()</code> returns
+     * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>,
+     * which takes the current rule into account. The method <code>observesDaylightTime()</code>
+     * was added in ICU4J for supporting API signature compatibility with JDK.
+     * In general, ICU4C also provides JDK compatible methods, but the current
+     * implementation <code>userDaylightTime()</code> serves the purpose
+     * (takes the current rule into account), <code>observesDaylightTime()</code>
+     * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C
+     * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code>
+     * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing
+     * historic and future time zone rule iteration, so you can check if daylight saving
+     * time is observed or not within a given period.
+     * 
      * @stable ICU 2.0
      */
     virtual UBool useDaylightTime(void) const = 0;
@@ -630,6 +773,26 @@ public:
      */
     virtual int32_t getDSTSavings() const;
 
+    /**
+     * Gets the region code associated with the given
+     * system time zone ID. The region code is either ISO 3166
+     * 2-letter country code or UN M.49 3-digit area code.
+     * When the time zone is not associated with a specific location,
+     * for example - "Etc/UTC", "EST5EDT", then this method returns
+     * "001" (UN M.49 area code for World).
+     * 
+     * @param id            The system time zone ID.
+     * @param region        Output buffer for receiving the region code.
+     * @param capacity      The size of the output buffer.
+     * @param status        Receives the status.  When the given time zone ID
+     *                      is not a known system time zone ID,
+     *                      U_ILLEGAL_ARGUMENT_ERROR is set.
+     * @return The length of the output region code.
+     * @stable ICU 4.8 
+     */ 
+    static int32_t U_EXPORT2 getRegion(const UnicodeString& id, 
+        char *region, int32_t capacity, UErrorCode& status); 
+
 protected:
 
     /**
@@ -659,6 +822,7 @@ protected:
      */
     TimeZone& operator=(const TimeZone& right);
 
+#ifndef U_HIDE_INTERNAL_API
     /**
      * Utility function. For internally loading rule data.
      * @param top Top resource bundle for tz data
@@ -669,6 +833,7 @@ protected:
      * @internal
      */
     static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
+#endif  /* U_HIDE_INTERNAL_API */
 
 private:
     friend class ZoneMeta;
@@ -677,6 +842,16 @@ private:
     static TimeZone*        createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
 
     /**
+     * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata,
+     * returns the pointer to the ID resource. This method is exposed through ZoneMeta class
+     * for ICU internal implementation and useful for building hashtable using a time zone
+     * ID as a key.
+     * @param id zone id string
+     * @return the pointer of the ID resource, or NULL.
+     */
+    static const UChar* findID(const UnicodeString& id);
+
+    /**
      * Resolve a link in Olson tzdata.  When the given id is known and it's not a link,
      * the id itself is returned.  When the given id is known and it is a link, then
      * dereferenced zone id is returned.  When the given id is unknown, then it returns
@@ -687,12 +862,27 @@ private:
     static const UChar* dereferOlsonLink(const UnicodeString& id);
 
     /**
-     * Returns the region code associated with the given zone.
+     * Returns the region code associated with the given zone,
+     * or NULL if the zone is not known.
      * @param id zone id string
      * @return the region associated with the given zone
      */
     static const UChar* getRegion(const UnicodeString& id);
 
+  public:
+#ifndef U_HIDE_INTERNAL_API
+    /**
+     * Returns the region code associated with the given zone,
+     * or NULL if the zone is not known.
+     * @param id zone id string
+     * @param status Status parameter
+     * @return the region associated with the given zone
+     * @internal
+     */
+    static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
+#endif  /* U_HIDE_INTERNAL_API */
+
+  private:
     /**
      * Parses the given custom time zone identifier
      * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
@@ -704,7 +894,7 @@ private:
      * @return Returns TRUE when the given custom id is valid.
      */
     static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
-        int32_t& min, int32_t& sec);
+        int32_t& minute, int32_t& second);
 
     /**
      * Parse a custom time zone identifier and return the normalized
@@ -724,32 +914,16 @@ private:
      * @param hour offset hours
      * @param min offset minutes
      * @param sec offset seconds
-     * @param netative sign of the offset, TRUE for negative offset.
+     * @param negative sign of the offset, TRUE for negative offset.
      * @param id Receves the format result (normalized custom ID)
      * @return The reference to id
      */
     static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
         UBool negative, UnicodeString& id);
 
-    /**
-     * Responsible for setting up DEFAULT_ZONE.  Uses routines in TPlatformUtilities
-     * (i.e., platform-specific calls) to get the current system time zone.  Failing
-     * that, uses the platform-specific default time zone.  Failing that, uses GMT.
-     */
-    static void             initDefault(void);
-
-    // See source file for documentation
-    /**
-     * Lookup the given name in our system zone table.  If found,
-     * instantiate a new zone of that name and return it.  If not
-     * found, return 0.
-     * @param name tthe given name of a system time zone.
-     * @return the TimeZone indicated by the 'name'.
-     */
-    static TimeZone*        createSystemTimeZone(const UnicodeString& name);
-
     UnicodeString           fID;    // this time zone's ID
 
+    friend class TZEnumeration;
 };