updated to the new Pikotools api (new Space struct)

This commit is contained in:
2021-04-09 17:50:58 +02:00
parent 00b980e74b
commit 35e10ed469
52 changed files with 795 additions and 736 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -242,12 +242,12 @@ return offset;
time_t TimeZone::GetOffset(PT::Space & space)
{
std::wstring * offset_str = space.GetFirstValue(L"offset_str");
std::wstring * offset_str = space.get_wstr(L"offset_str");
if( offset_str )
return ParseStrOffset(offset_str->c_str());
return space.Long(L"offset");
return space.to_long(L"offset");
}
@@ -257,22 +257,25 @@ bool TimeZone::SetTzDst(PT::Space & year)
bool result = true;
Dst dst;
int year_int = Toi(year.name);
int year_int = 0;
if( year.name )
year_int = Toi(*year.name);
if( year_int < 1970 || year_int > 10000 )
return false;
dst.has_dst = year.Bool(L"has_dst", false);
dst.has_dst = year.to_bool(L"has_dst", false);
if( dst.has_dst )
{
dst.start.year = year_int;
dst.end.year = year_int;
if( !dst.start.ParseMonthDayTime(year.Text(L"start")) )
if( !dst.start.ParseMonthDayTime(year.to_wstr(L"start")) )
result = false;
if( !dst.end.ParseMonthDayTime(year.Text(L"end")) )
if( !dst.end.ParseMonthDayTime(year.to_wstr(L"end")) )
result = false;
dst.offset = GetOffset(year);
@@ -291,24 +294,31 @@ return result;
bool TimeZone::SetTz(PT::Space & space)
{
bool result = true;
name = space.name;
id = space.Int(L"id", -1);
name.clear();
if( space.name )
name = *space.name;
id = space.to_int(L"id", -1);
offset = GetOffset(space);
time_t h24 = 60 * 60 * 24; // 24 hours
if( offset < -h24 || offset > h24 )
result = false;
PT::Space & dst = space.FindAddSpace(L"dst");
PT::Space * dst = space.find_child_space(L"dst");
for(size_t i=0 ; i<dst.spaces.size() ; ++i)
if( dst && dst->child_spaces )
{
PT::Space & year = *dst.spaces[i];
if( !SetTzDst(year) )
for(size_t i=0 ; i<dst->child_spaces->size() ; ++i)
{
result = false;
break;
PT::Space & year = *(*dst->child_spaces)[i];
if( !SetTzDst(year) )
{
result = false;
break;
}
}
}