-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2008 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <cstdlib>
-#include <sstream>
-#include <iomanip>
-#include <time.h>
+#include <msp/strings/format.h>
#include "timezone.h"
-#include "units.h"
using namespace std;
-namespace {
-
-using Msp::Time::TimeZone;
-
-TimeZone get_local_timezone()
-{
-#ifdef WIN32
- TIME_ZONE_INFORMATION tzinfo;
- DWORD dst=GetTimeZoneInformation(&tzinfo);
- if(dst==TIME_ZONE_ID_INVALID)
- throw SystemError("Failed to get time zone information", GetLastError());
-
- int offset=tzinfo.Bias;
- if(dst==TIME_ZONE_ID_STANDARD)
- offset+=tzinfo.StandardBias;
- else if(dst==TIME_ZONE_ID_DAYLIGHT)
- offset+=tzinfo.DaylightBias;
-
- return TimeZone(offset);
-#else
- tzset();
- return TimeZone(timezone/60);
-#endif
-}
-
-}
-
namespace Msp {
namespace Time {
name("UTC")
{ }
-TimeZone::TimeZone(int minutes_west):
- offset(minutes_west*min)
+TimeZone::TimeZone(int minutes):
+ offset(minutes*min)
{
- if(minutes_west)
+ if(minutes)
{
- ostringstream ss;
- ss.fill('0');
- int m=abs(minutes_west);
- ss<<"UTC"<<(minutes_west<0 ? '-' : '+')<<m/60;
+ int m = abs(minutes);
+ name = format("UTC%c%d", (minutes<0 ? '-' : '+'), m/60);
if(m%60)
- ss<<':'<<setw(2)<<m%60;
+ name += format(":%02d", m%60);
}
else
- name="UTC";
+ name = "UTC";
}
+TimeZone::TimeZone(int minutes, const string &n):
+ name(n),
+ offset(minutes*min)
+{ }
+
const TimeZone &TimeZone::utc()
{
static TimeZone tz(0);
const TimeZone &TimeZone::local()
{
- static TimeZone tz=get_local_timezone();
+ static TimeZone tz = platform_get_local_timezone();
return tz;
}