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