From 803069886ebca492c0d5f47133ccf7833c716e5a Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 6 Jun 2015 03:40:56 +0200 Subject: Add utc param to get_time and get_date methods If utc == false, we return the local time, like before. Otherwise, we return UTC time. utc defaults to false to not break behaviour. --- drivers/unix/os_unix.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index d558aadc8e..afb85e49e8 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -218,10 +218,14 @@ uint64_t OS_Unix::get_unix_time() const { }; -OS::Date OS_Unix::get_date() const { +OS::Date OS_Unix::get_date(bool utc) const { time_t t=time(NULL); - struct tm *lt=localtime(&t); + struct tm *lt; + if (utc) + lt=gmtime(&t); + else + lt=localtime(&t); Date ret; ret.year=1900+lt->tm_year; ret.month=(Month)lt->tm_mon; @@ -231,10 +235,13 @@ OS::Date OS_Unix::get_date() const { return ret; } -OS::Time OS_Unix::get_time() const { - +OS::Time OS_Unix::get_time(bool utc) const { time_t t=time(NULL); - struct tm *lt=localtime(&t); + struct tm *lt; + if (utc) + lt=gmtime(&t); + else + lt=localtime(&t); Time ret; ret.hour=lt->tm_hour; ret.min=lt->tm_min; -- cgit v1.2.3