winix/core/timezone.h

95 lines
1.7 KiB
C
Raw Normal View History

/*
* 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 (tz_id is skipped)
the space 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);
// each locale has its own identifier
int tz_id;
// 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