blob: f6bf9ff3f5904bd3f876e92555b3f51688592bc3 [file] [log] [blame]
halcanary8e74b152014-11-10 09:20:22 -08001/*
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 "Test.h"
10
11// Sanity checks for the GetDateTime function.
12DEF_TEST(Time_GetDateTime, r) {
13 SkTime::DateTime dateTime;
14 SkTime::GetDateTime(&dateTime);
15
16 // TODO(future generation): update these values.
halcanaryac6c4fc2014-11-10 14:39:24 -080017 const uint16_t kMinimumSaneYear = 1964;
halcanary8e74b152014-11-10 09:20:22 -080018 const uint16_t kMaximumSaneYear = 2064;
halcanaryac6c4fc2014-11-10 14:39:24 -080019
20 if (dateTime.fYear < kMinimumSaneYear) {
21 ERRORF(r,
22 "SkTime::GetDateTime: %u (CurrentYear) < %u (MinimumSaneYear)",
23 static_cast<unsigned>(dateTime.fYear),
24 static_cast<unsigned>(kMinimumSaneYear));
25 }
26 if (dateTime.fYear > kMaximumSaneYear) {
27 ERRORF(r,
28 "SkTime::GetDateTime: %u (CurrentYear) > %u (MaximumSaneYear)",
29 static_cast<unsigned>(dateTime.fYear),
30 static_cast<unsigned>(kMaximumSaneYear));
31 }
halcanary8e74b152014-11-10 09:20:22 -080032
33 REPORTER_ASSERT(r, dateTime.fMonth >= 1);
34 REPORTER_ASSERT(r, dateTime.fMonth <= 12);
35
36 REPORTER_ASSERT(r, dateTime.fDay >= 1);
37 REPORTER_ASSERT(r, dateTime.fDay <= 31);
38
39 REPORTER_ASSERT(r, dateTime.fHour <= 23);
40
41 REPORTER_ASSERT(r, dateTime.fMinute <= 59);
42
43 REPORTER_ASSERT(r, dateTime.fSecond <= 60); // leap seconds are 23:59:60
halcanary0b9d4112015-05-01 07:06:23 -070044
45 // The westernmost timezone is -12:00.
46 // The easternmost timezone is +14:00.
bungeman60e0fee2015-08-26 05:15:46 -070047 REPORTER_ASSERT(r, SkTAbs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60);
halcanary0b9d4112015-05-01 07:06:23 -070048
49 SkString timeStamp;
50 dateTime.toISO8601(&timeStamp);
51 REPORTER_ASSERT(r, timeStamp.size() > 0);
halcanary7d571242016-02-24 17:59:16 -080052 INFOF(r, "\nCurrent Time (ISO-8601 format): \"%s\"\n",
53 timeStamp.c_str());
halcanary8e74b152014-11-10 09:20:22 -080054}