Flutter Engine
The Flutter Engine
Time.cpp
Go to the documentation of this file.
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 */
8
9#ifdef SK_SUPPORT_PDF
14#include "src/pdf/SkPDFUtils.h"
15#include "tests/Test.h"
16
17#include <cstdint>
18
19DEF_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
static T SkTAbs(T value)
Definition: SkTemplates.h:43
constexpr int SkToInt(S x)
Definition: SkTo.h:29
#define DEF_TEST(name, reporter)
Definition: Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define INFOF(REPORTER,...)
Definition: Test.h:298
#define ERRORF(r,...)
Definition: Test.h:293
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
void GetDateTime(SkPDF::DateTime *)
Definition: SkPDFUtils.cpp:431
uint8_t fMinute
0..59
Definition: SkPDFDocument.h:77
uint8_t fMonth
1..12
Definition: SkPDFDocument.h:73
uint8_t fDay
1..31
Definition: SkPDFDocument.h:75
uint16_t fYear
e.g. 2005
Definition: SkPDFDocument.h:72
void toISO8601(SkString *dst) const
uint8_t fSecond
0..59
Definition: SkPDFDocument.h:78
int16_t fTimeZoneMinutes
Definition: SkPDFDocument.h:70
uint8_t fHour
0..23
Definition: SkPDFDocument.h:76