]> git.tdb.fi Git - libs/core.git/blob - tests/timezone.cpp
Add some utility functions for joining strings
[libs/core.git] / tests / timezone.cpp
1 #include <msp/time/timedelta.h>
2 #include <msp/time/timezone.h>
3 #include <msp/test/test.h>
4
5 using namespace std;
6 using namespace Msp;
7
8 class TimeZoneTests: public Test::RegisteredTest<TimeZoneTests>
9 {
10 public:
11         TimeZoneTests();
12
13         static const char *get_name() { return "TimeZone"; }
14
15 private:
16         void utc();
17         void local();
18         void custom();
19 };
20
21
22 TimeZoneTests::TimeZoneTests()
23 {
24         add(&TimeZoneTests::utc, "UTC");
25         add(&TimeZoneTests::local, "Local");
26         add(&TimeZoneTests::custom, "Custom");
27 }
28
29 void TimeZoneTests::utc()
30 {
31         Time::TimeZone tz = Time::TimeZone::utc();
32         EXPECT_EQUAL(tz.get_name(), "UTC");
33         EXPECT_EQUAL(tz.get_offset(), Time::zero);
34 }
35
36 void TimeZoneTests::local()
37 {
38         Time::TimeZone tz = Time::TimeZone::local();
39         info(format("'%s' %s", tz.get_name(), tz.get_offset()));
40 }
41
42 void TimeZoneTests::custom()
43 {
44         Time::TimeZone tz1(120);
45         EXPECT_EQUAL(tz1.get_name(), "UTC+2");
46         Time::TimeZone tz2(345);
47         EXPECT_EQUAL(tz2.get_name(), "UTC+5:45");
48 }