blob: 60dcd5527cdc5a2f30c8f55655c022323455c219 [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.
47 REPORTER_ASSERT(r, abs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60);
48
49 SkString timeStamp;
50 dateTime.toISO8601(&timeStamp);
51 REPORTER_ASSERT(r, timeStamp.size() > 0);
52 if (r->verbose()) { // `dm --veryVerbose`
53 SkDebugf("\nCurrent Time (ISO-8601 format): \"%s\"\n",
54 timeStamp.c_str());
55 }
halcanary8e74b152014-11-10 09:20:22 -080056}