aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2014-11-10 09:20:22 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-10 09:20:22 -0800
commit8e74b1565c5573a0be40060cebbc112fc156f26d (patch)
tree000c2fc04406d633886696b886ef8088ab2c974d
parent7c74885e017a2473383fed72bd629cc07c773942 (diff)
Fix SkTime::GetDateTime Posix implementation, add unit test.
The year was off by 1900 Review URL: https://codereview.chromium.org/714633002
-rw-r--r--gyp/tests.gypi1
-rw-r--r--src/ports/SkTime_Unix.cpp4
-rw-r--r--tests/Time.cpp33
3 files changed, 36 insertions, 2 deletions
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index 8dfc671c47..4bdea1e1f0 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -200,6 +200,7 @@
'../tests/SurfaceTest.cpp',
'../tests/TArrayTest.cpp',
'../tests/THashCache.cpp',
+ '../tests/Time.cpp',
'../tests/TLSTest.cpp',
'../tests/TSetTest.cpp',
'../tests/TextBlobTest.cpp',
diff --git a/src/ports/SkTime_Unix.cpp b/src/ports/SkTime_Unix.cpp
index f519a69d07..6e305a16f6 100644
--- a/src/ports/SkTime_Unix.cpp
+++ b/src/ports/SkTime_Unix.cpp
@@ -20,8 +20,8 @@ void SkTime::GetDateTime(DateTime* dt)
time(&m_time);
struct tm* tstruct;
tstruct = localtime(&m_time);
-
- dt->fYear = tstruct->tm_year;
+ // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
+ dt->fYear = tstruct->tm_year + 1900;
dt->fMonth = SkToU8(tstruct->tm_mon + 1);
dt->fDayOfWeek = SkToU8(tstruct->tm_wday);
dt->fDay = SkToU8(tstruct->tm_mday);
diff --git a/tests/Time.cpp b/tests/Time.cpp
new file mode 100644
index 0000000000..65c01e26ff
--- /dev/null
+++ b/tests/Time.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTime.h"
+#include "Test.h"
+
+// Sanity checks for the GetDateTime function.
+DEF_TEST(Time_GetDateTime, r) {
+ SkTime::DateTime dateTime;
+ SkTime::GetDateTime(&dateTime);
+
+ // TODO(future generation): update these values.
+ const uint16_t kMinimumSaneYear = 2014;
+ const uint16_t kMaximumSaneYear = 2064;
+ REPORTER_ASSERT(r, dateTime.fYear >= kMinimumSaneYear);
+ REPORTER_ASSERT(r, dateTime.fYear <= kMaximumSaneYear);
+
+ REPORTER_ASSERT(r, dateTime.fMonth >= 1);
+ REPORTER_ASSERT(r, dateTime.fMonth <= 12);
+
+ REPORTER_ASSERT(r, dateTime.fDay >= 1);
+ REPORTER_ASSERT(r, dateTime.fDay <= 31);
+
+ REPORTER_ASSERT(r, dateTime.fHour <= 23);
+
+ REPORTER_ASSERT(r, dateTime.fMinute <= 59);
+
+ REPORTER_ASSERT(r, dateTime.fSecond <= 60); // leap seconds are 23:59:60
+}