aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-05-01 07:06:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-01 07:06:23 -0700
commit0b9d4118ba4f3f1190c063492894e324c63e8fd8 (patch)
treed7b7faaa33d11420c02097b1653d08871f845f98 /src
parentd309e7aa0efa2d5dd7e7b1af97026fcd3a047e98 (diff)
SkTime: return timezone information; format in ISO-8601
Motivation: PDF/A metadata will need the creation date embedded in it. Also, GetDateTime returns local time in Win32. This now behaves the same as on Unix systems. BUG=skia:3110 Review URL: https://codereview.chromium.org/1109593002
Diffstat (limited to 'src')
-rw-r--r--src/core/SkTime.cpp24
-rw-r--r--src/ports/SkTime_Unix.cpp4
-rw-r--r--src/ports/SkTime_win.cpp18
3 files changed, 44 insertions, 2 deletions
diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp
new file mode 100644
index 0000000000..b8e42365ef
--- /dev/null
+++ b/src/core/SkTime.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkString.h"
+#include "SkTime.h"
+
+void SkTime::DateTime::toISO8601(SkString* dst) const {
+ if (dst) {
+ int timeZoneMinutes = SkToInt(fTimeZoneMinutes);
+ char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
+ int timeZoneHours = abs(timeZoneMinutes) / 60;
+ timeZoneMinutes = abs(timeZoneMinutes) % 60;
+ dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d",
+ static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth),
+ static_cast<unsigned>(fDay), static_cast<unsigned>(fHour),
+ static_cast<unsigned>(fMinute),
+ static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours,
+ timeZoneMinutes);
+ }
+}
diff --git a/src/ports/SkTime_Unix.cpp b/src/ports/SkTime_Unix.cpp
index 6e305a16f6..2d5fa279b4 100644
--- a/src/ports/SkTime_Unix.cpp
+++ b/src/ports/SkTime_Unix.cpp
@@ -16,11 +16,15 @@ void SkTime::GetDateTime(DateTime* dt)
{
if (dt)
{
+ tzset(); // initialize timezone variable;
time_t m_time;
time(&m_time);
struct tm* tstruct;
tstruct = localtime(&m_time);
+ int offset = tstruct->tm_isdst == 1 ? 60 : 0;
+
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
+ dt->fTimeZoneMinutes = SkToS16(offset - timezone / 60);
dt->fYear = tstruct->tm_year + 1900;
dt->fMonth = SkToU8(tstruct->tm_mon + 1);
dt->fDayOfWeek = SkToU8(tstruct->tm_wday);
diff --git a/src/ports/SkTime_win.cpp b/src/ports/SkTime_win.cpp
index bc0f8f0084..19f4695a86 100644
--- a/src/ports/SkTime_win.cpp
+++ b/src/ports/SkTime_win.cpp
@@ -14,8 +14,22 @@ void SkTime::GetDateTime(DateTime* dt)
if (dt)
{
SYSTEMTIME st;
- GetSystemTime(&st);
-
+ TIME_ZONE_INFORMATION timeZoneInfo;
+ int tz_bias;
+ GetLocalTime(&st);
+ // https://gist.github.com/wrl/8924636
+ switch (GetTimeZoneInformation(&timeZoneInfo)) {
+ case TIME_ZONE_ID_STANDARD:
+ tz_bias = -timeZoneInfo.Bias - timeZoneInfo.StandardBias;
+ break;
+ case TIME_ZONE_ID_DAYLIGHT:
+ tz_bias = -timeZoneInfo.Bias - timeZoneInfo.DaylightBias;
+ break;
+ default:
+ tz_bias = -timeZoneInfo.Bias;
+ break;
+ }
+ dt->fTimeZoneMinutes = SkToS16(tz_bias);
dt->fYear = st.wYear;
dt->fMonth = SkToU8(st.wMonth);
dt->fDayOfWeek = SkToU8(st.wDayOfWeek);