xref: /aosp_15_r20/external/skia/tests/Time.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "include/core/SkTypes.h"
8 
9 #ifdef SK_SUPPORT_PDF
10 #include "include/core/SkString.h"
11 #include "include/docs/SkPDFDocument.h"
12 #include "include/private/base/SkTemplates.h"
13 #include "include/private/base/SkTo.h"
14 #include "src/pdf/SkPDFUtils.h"
15 #include "tests/Test.h"
16 
17 #include <cstdint>
18 
DEF_TEST(SkPDFUtils_GetDateTime,r)19 DEF_TEST(SkPDFUtils_GetDateTime, r) {
20     SkPDF::DateTime dateTime;
21     SkPDFUtils::GetDateTime(&dateTime);
22 
23     // TODO(future generation): update these values.
24     const uint16_t kMinimumSaneYear = 1964;
25     const uint16_t kMaximumSaneYear = 2064;
26 
27     if (dateTime.fYear < kMinimumSaneYear) {
28         ERRORF(r,
29                "SkPDFUtils::GetDateTime: %u (CurrentYear) < %u (MinimumSaneYear)",
30                static_cast<unsigned>(dateTime.fYear),
31                static_cast<unsigned>(kMinimumSaneYear));
32     }
33     if (dateTime.fYear > kMaximumSaneYear) {
34         ERRORF(r,
35                "SkPDFUtils::GetDateTime: %u (CurrentYear) > %u (MaximumSaneYear)",
36                static_cast<unsigned>(dateTime.fYear),
37                static_cast<unsigned>(kMaximumSaneYear));
38     }
39 
40     REPORTER_ASSERT(r, dateTime.fMonth >= 1);
41     REPORTER_ASSERT(r, dateTime.fMonth <= 12);
42 
43     REPORTER_ASSERT(r, dateTime.fDay >= 1);
44     REPORTER_ASSERT(r, dateTime.fDay <= 31);
45 
46     REPORTER_ASSERT(r, dateTime.fHour <= 23);
47 
48     REPORTER_ASSERT(r, dateTime.fMinute <= 59);
49 
50     REPORTER_ASSERT(r, dateTime.fSecond <= 60);  // leap seconds are 23:59:60
51 
52     // The westernmost timezone is -12:00.
53     // The easternmost timezone is +14:00.
54     REPORTER_ASSERT(r, SkTAbs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60);
55 
56     SkString timeStamp;
57     dateTime.toISO8601(&timeStamp);
58     REPORTER_ASSERT(r, timeStamp.size() > 0);
59     INFOF(r, "\nCurrent Time (ISO-8601 format): \"%s\"\n",
60           timeStamp.c_str());
61 }
62 #endif
63