added: winix functions: locale, timezone

changed: time zones -- now we have the daylight saving time
       different for each year (start, end)
added: config option: time_zone_id (size_t)
       time zone identifier for not logged users
       or for newly created accounts
       those identifiers you can see in etc/time_zones.conf file
       or by using timezone winix function with 'a' parameter (timezone/a) (!!IMPROVE ME NOT IMPLEMENTED YET)
       default: 34 (Coordinated Universal Time UTC+00:00)
added: config option: locale_default_id (size_t)
       locale for not logged users
       or for newly created accounts
added: config option: locale_max_id (size_t)
       a maximum value of a locale identifier
       default: 100 (maximum: 1000)
       each locale files should have its own identifier (in "winix_locale_id" field)
       from zero to this value
added: config option: time_zone_max_id (size_t)
       maximum value of a time zone identifier
       time zones with an id greater than this will be skipped
       default: 130 (maximum: 1000)
removed: config option: locale_default



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@852 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-06-26 23:19:19 +00:00
parent 54e6c07efc
commit b8ff5d4cfc
53 changed files with 4618 additions and 3053 deletions

View File

@@ -11,6 +11,7 @@
#define headerfile_winix_core_timezone
#include <ctime>
#include <map>
#include "date/date.h"
#include "space/space.h"
@@ -20,13 +21,46 @@ class TimeZone
{
public:
struct Dst
{
// true if a time zone has daylight saving time
bool has_dst;
// time zone daylight saving time (used if has_dst is true)
// the 'year' field is the same in 'start' and 'end'
// start and end are represented in UTC time
PT::Date start, end;
// time zone daylight saving time offset
// used when has_dst is true and the date is whithin start and end
// this offset should be added to time zone offset
time_t offset;
Dst();
void Clear();
// checking whether specified 'date' is in the range of <start, end>
// the year field in date, start and end is ignored
// has_dst must be true
bool IsDstUsed(const PT::Date & date) const;
private:
// Compare returns zero if date1 and date2 are equal
// return value less than zero if date1 is lower than date2
// and a value greater than zero if date1 is greater than date2
// the year field is ignored
int Compare(const PT::Date & date1, const PT::Date & date2) const;
};
TimeZone();
/*
setting:
tz_offset = 0
tz_has_dst = false
*/
void Clear();
@@ -59,25 +93,39 @@ public:
time_t ToUTC(time_t local_time);
PT::Date ToUTC(const PT::Date & local_date);
// return a Dst structure for the specified year
// or null if it not exists
// this method can return a Dst structure for earlier year than 'year'
// if 'year' doesn't exist
Dst * FindDst(int year);
// a time zone name
// this is a key to locale
std::wstring name;
// each locale has its own identifier
int tz_id;
size_t id;
// time zone offset (in seconds)
time_t tz_offset;
time_t offset;
// true if the time zone has daylight saving time
bool tz_has_dst;
// daylight saving time map
// year -> Dst
// if there is not a specified year we are taking the lower year, e.g.
// if we are looking for 2010 and there is no such a year then we take 2009
// (or 2008 if 2009 not exists etc)
typedef std::map<int, Dst> DstMap;
DstMap dst_map;
// time zone daylight saving time (used if tz_has_dst is true)
// the 'year' field is ignored (is always 1970)
// these values (hours) are represented in local time (UTC + tz_offset)
PT::Date tz_dst_start, tz_dst_end;
// time zone daylight saving time offset
// used when tz_has_dst is true and the current date is whithin tz_dst_start and tz_dst_end
time_t tz_dst_offset;
private:
time_t ParseStrOffset(const wchar_t * str);
time_t GetOffset(PT::Space & space);
bool SetTzDst(PT::Space & year);
};