date/timezone classes

From: Date: Thu, 07 Jul 2005 21:10:16 +0000
Subject: date/timezone classes
Groups: php.internals 
Request: Send a blank email to internals+get-17169@lists.php.net to get a copy of this message
Hei, I wrote up a little document about how I want to implement the date and timezone "class"es - although I'm not planning any OO methods. I'm just wrapping the timelib_time and timelib_tzinfo structures in an object. Let me know what you think. Derick

Definitions: Timezone Abbreviation: CEST, EEST, PDT Timezone Identifier: Europe/Oslo, Europe/Helsinki, America/Los_Angeles Timezone database: Database consisting of all timezone definitions and Transition Times. Transistion Time: Time where the GMT offset in a timezone changes (f.e. due to a DST changeover) Timezone related functions obj timezone timezone_open(string timezone); Loads a timezone from the database. First the timezone will be looked for in the Timezone Abbreviation database and the corresponding Timezone Identifier is then opened from the database. If the timezone is not found in the Timezone Abbreviation database, then the function attempts to load it directly from the Timezone database. string timezone_name_get(obj timezone); Returns the Timezone Identifier belonging to the timezone object. int timezone_offset_get(obj timezone, obj date); Returns the GMT offset belonging to the date object in the passed timezone. array timezone_transistions_get(obj timezone); Returns a multi-dimensional array containing all the known Transistion Times. Each element in the returned array consists of two elements. The first element "time" is a string in the format "yyyy-mm-ddThh:ii:ssZ" describing the transistion time, and the second element "offset" is the GMT offset accompanying the Transistion Time. array timezone_abbreviations_list(); Returns a multi-dimensional associate array where the key is the Timezone Abbreviation and as data an array with three elements: "offset" describes the GMT offset in seconds, "dst" whether the Timezone Abbreviation is a DST abbreviation or not and "timezone_id" containing the Timezone Identifier as string if it exists, or NULL otherwise. array timezone_identifiers_list(); Returns a single-dimensional array with all available Timezone Identifiers as string. Date related functions obj date date_create(string date_representatation); Creates a date object out of a string representation of date/time information - analogous to strtotime(). obj timezone date_timezone_get(obj date); Returns the timezone object associated with the date object. Returns false if the time was not a local time, but UTC time. int date_offset_get(obj date); Returns the offset in seconds that belongs to the time that the date object represents in the assigned timezone. If the date is currently representing UTC time, then 0 will be returned, and if the date is representing a local time then the offset to UTC will be returned. bool date_timezone_set(obj date, obj timezone); Updates the date object's timezone with the passed timezone object. Returns true if this succeeded, or false when it doesn't (which I can't find a reason for why that might happen right now). bool date_timezone_set_by_name(obj date, string timezone); Updates the date object's timezone with the passed timezone string. The same algorithm for determining the Timezone Identifier is used as when creating a timezone object with timezone_open(). Returns false if the timezone could not be found, true if everything went Ok. bool date_to_utc(obj date); Unassociates the timezone information from the date, reverting it to UTC time. Returns true if there was something changed, false if the date object was already representing UTC time. bool date_to_local(obj date); Associates the timezone information already available in the date object with the date object again. This results in the representation using the local time with an offset to UTC again. Returns true if there was something changed, false if the date object was already representing local time. string date_format(date obj, string format) Formats a date with the format string "format". The same format modifiers are being used as with the date() function. bool date_modify(date obj, string modify_string) Uses strtotime() functionality for modifying the date object. An example of such a modifying string is "next month". If an invalid format is passed, false will be returned, otherwise the date will be modified and true returned.
« previous php.internals (#17169) next »