moved winix directories to winixd subdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1027 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
170
winixd/core/timezone.h
Normal file
170
winixd/core/timezone.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_timezone
|
||||
#define headerfile_winix_core_timezone
|
||||
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include "date/date.h"
|
||||
#include "space/space.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
||||
/*
|
||||
*/
|
||||
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);
|
||||
|
||||
// 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
|
||||
size_t id;
|
||||
|
||||
// time zone offset (in seconds)
|
||||
time_t offset;
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
time_t ParseStrOffset(const wchar_t * str);
|
||||
time_t GetOffset(PT::Space & space);
|
||||
bool SetTzDst(PT::Space & year);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user