]> git.tdb.fi Git - libs/core.git/blob - source/time/timezone.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / time / timezone.cpp
1 #include <cstdlib>
2 #include <msp/strings/format.h>
3 #include "timezone.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace Time {
9
10 TimeZone::TimeZone():
11         name("UTC")
12 { }
13
14 TimeZone::TimeZone(int minutes):
15         offset(minutes*min)
16 {
17         if(minutes)
18         {
19                 int m = abs(minutes);
20                 name = format("UTC%c%d", (minutes<0 ? '-' : '+'), m/60);
21                 if(m%60)
22                         name += format(":%02d", m%60);
23         }
24         else
25                 name = "UTC";
26 }
27
28 TimeZone::TimeZone(int minutes, const string &n):
29         name(n),
30         offset(minutes*min)
31 { }
32
33 const TimeZone &TimeZone::utc()
34 {
35         static TimeZone tz(0);
36         return tz;
37 }
38
39 const TimeZone &TimeZone::local()
40 {
41         static TimeZone tz = platform_get_local_timezone();
42         return tz;
43 }
44
45 } // namespace Time
46 } // namespace Msp