added: TimeZone struct (core)
this class has information about a time zone (utf offset, daylight saving time) and methods for converting between UTC and local time structs User and Config has a TimeZone object System::ToLocal() and System::ToUTC() uses it for converting (depending whether a user is logged or not) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@842 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
93
core/timezone.h
Normal file
93
core/timezone.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_timezone
|
||||
#define headerfile_winix_core_timezone
|
||||
|
||||
#include <ctime>
|
||||
#include "date/date.h"
|
||||
#include "space/space.h"
|
||||
|
||||
|
||||
|
||||
class TimeZone
|
||||
{
|
||||
public:
|
||||
|
||||
TimeZone();
|
||||
|
||||
|
||||
/*
|
||||
setting:
|
||||
tz_offset = 0
|
||||
tz_has_dst = false
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
|
||||
/*
|
||||
reading zime zone values from Space struct
|
||||
the struct should have:
|
||||
"tz_offset" (long)
|
||||
"tz_has_dst" (bool)
|
||||
if tz_has_dst is true then also:
|
||||
"tz_dst_start" date in the following format: MM:DD HH[:MM[:SS]]
|
||||
"tz_dst_end" the same as above
|
||||
"tz_dst_offset" (long)
|
||||
*/
|
||||
bool SetTz(PT::Space & space);
|
||||
|
||||
|
||||
/*
|
||||
converting from UTC to local time
|
||||
*/
|
||||
time_t CalcLocalOffset(const PT::Date & utc_date);
|
||||
time_t ToLocal(time_t utc_time);
|
||||
PT::Date ToLocal(const PT::Date & utc_date);
|
||||
|
||||
|
||||
/*
|
||||
converting from local time to UTC
|
||||
*/
|
||||
time_t CalcUTCOffset(const PT::Date & local_date);
|
||||
time_t ToUTC(time_t local_time);
|
||||
PT::Date ToUTC(const PT::Date & local_date);
|
||||
|
||||
|
||||
|
||||
|
||||
// time zone offset (in seconds)
|
||||
time_t tz_offset;
|
||||
|
||||
// true if the time zone has daylight saving time
|
||||
bool tz_has_dst;
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user