• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkTime.h"
9 #include "SkTo.h"
10 #include "Test.h"
11 
12 // Sanity checks for the GetDateTime function.
DEF_TEST(Time_GetDateTime,r)13 DEF_TEST(Time_GetDateTime, r) {
14     SkTime::DateTime dateTime;
15     SkTime::GetDateTime(&dateTime);
16 
17     // TODO(future generation): update these values.
18     const uint16_t kMinimumSaneYear = 1964;
19     const uint16_t kMaximumSaneYear = 2064;
20 
21     if (dateTime.fYear < kMinimumSaneYear) {
22         ERRORF(r,
23                "SkTime::GetDateTime: %u (CurrentYear) < %u (MinimumSaneYear)",
24                static_cast<unsigned>(dateTime.fYear),
25                static_cast<unsigned>(kMinimumSaneYear));
26     }
27     if (dateTime.fYear > kMaximumSaneYear) {
28         ERRORF(r,
29                "SkTime::GetDateTime: %u (CurrentYear) > %u (MaximumSaneYear)",
30                static_cast<unsigned>(dateTime.fYear),
31                static_cast<unsigned>(kMaximumSaneYear));
32     }
33 
34     REPORTER_ASSERT(r, dateTime.fMonth >= 1);
35     REPORTER_ASSERT(r, dateTime.fMonth <= 12);
36 
37     REPORTER_ASSERT(r, dateTime.fDay >= 1);
38     REPORTER_ASSERT(r, dateTime.fDay <= 31);
39 
40     REPORTER_ASSERT(r, dateTime.fHour <= 23);
41 
42     REPORTER_ASSERT(r, dateTime.fMinute <= 59);
43 
44     REPORTER_ASSERT(r, dateTime.fSecond <= 60);  // leap seconds are 23:59:60
45 
46     // The westernmost timezone is -12:00.
47     // The easternmost timezone is +14:00.
48     REPORTER_ASSERT(r, SkTAbs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60);
49 
50     SkString timeStamp;
51     dateTime.toISO8601(&timeStamp);
52     REPORTER_ASSERT(r, timeStamp.size() > 0);
53     INFOF(r, "\nCurrent Time (ISO-8601 format): \"%s\"\n",
54           timeStamp.c_str());
55 }
56