1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <sys/time.h> 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <time.h> 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.orgvoid SkTime::GetDateTime(DateTime* dt) 16d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org{ 17d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org if (dt) 18d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org { 190b9d4118ba4f3f1190c063492894e324c63e8fd8halcanary tzset(); // initialize timezone variable; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com time_t m_time; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com time(&m_time); 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct tm* tstruct; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tstruct = localtime(&m_time); 240b9d4118ba4f3f1190c063492894e324c63e8fd8halcanary int offset = tstruct->tm_isdst == 1 ? 60 : 0; 250b9d4118ba4f3f1190c063492894e324c63e8fd8halcanary 268e74b1565c5573a0be40060cebbc112fc156f26dhalcanary // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html 270b9d4118ba4f3f1190c063492894e324c63e8fd8halcanary dt->fTimeZoneMinutes = SkToS16(offset - timezone / 60); 288e74b1565c5573a0be40060cebbc112fc156f26dhalcanary dt->fYear = tstruct->tm_year + 1900; 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fMonth = SkToU8(tstruct->tm_mon + 1); 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fDayOfWeek = SkToU8(tstruct->tm_wday); 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fDay = SkToU8(tstruct->tm_mday); 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fHour = SkToU8(tstruct->tm_hour); 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fMinute = SkToU8(tstruct->tm_min); 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dt->fSecond = SkToU8(tstruct->tm_sec); 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 38d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.orgSkMSec SkTime::GetMSecs() 39d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org{ 40d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org struct timeval tv; 41d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org gettimeofday(&tv, NULL); 42d0306a15938a971e10dd8648d3e17b001c4b0014commit-bot@chromium.org return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds 43d361e7eaa6ef399989914a56ff377005f8d44daebsalomon@google.com} 44