summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/bind/core_bind.cpp22
-rw-r--r--core/bind/core_bind.h5
-rw-r--r--core/os/os.h12
-rw-r--r--drivers/unix/os_unix.cpp46
-rw-r--r--drivers/unix/os_unix.h5
-rw-r--r--platform/nacl/os_nacl.cpp42
-rw-r--r--platform/nacl/os_nacl.h4
-rw-r--r--platform/windows/os_windows.cpp44
-rw-r--r--platform/windows/os_windows.h4
-rw-r--r--platform/winrt/os_winrt.cpp32
-rw-r--r--platform/winrt/os_winrt.h4
11 files changed, 182 insertions, 38 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 128bc94989..26b1dac6f1 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -457,9 +457,9 @@ void _OS::set_icon(const Image& p_icon) {
OS::get_singleton()->set_icon(p_icon);
}
-Dictionary _OS::get_date() const {
+Dictionary _OS::get_date(bool utc) const {
- OS::Date date = OS::get_singleton()->get_date();
+ OS::Date date = OS::get_singleton()->get_date(utc);
Dictionary dated;
dated["year"]=date.year;
dated["month"]=date.month;
@@ -470,9 +470,9 @@ Dictionary _OS::get_date() const {
}
-Dictionary _OS::get_time() const {
+Dictionary _OS::get_time(bool utc) const {
- OS::Time time = OS::get_singleton()->get_time();
+ OS::Time time = OS::get_singleton()->get_time(utc);
Dictionary timed;
timed["hour"]=time.hour;
timed["minute"]=time.min;
@@ -480,6 +480,15 @@ Dictionary _OS::get_time() const {
return timed;
}
+
+Dictionary _OS::get_time_zone_info() const {
+ OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
+ Dictionary infod;
+ infod["bias"] = info.bias;
+ infod["name"] = info.name;
+ return infod;
+}
+
uint64_t _OS::get_unix_time() const {
return OS::get_singleton()->get_unix_time();
@@ -774,8 +783,9 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
ObjectTypeDB::bind_method(_MD("get_main_loop"),&_OS::get_main_loop);
- ObjectTypeDB::bind_method(_MD("get_date"),&_OS::get_date);
- ObjectTypeDB::bind_method(_MD("get_time"),&_OS::get_time);
+ ObjectTypeDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
ObjectTypeDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
ObjectTypeDB::bind_method(_MD("set_icon"),&_OS::set_icon);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 05f54dd64c..74f29c23e8 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -204,8 +204,9 @@ public:
void set_use_file_access_save_and_swap(bool p_enable);
void set_icon(const Image& p_icon);
- Dictionary get_date() const;
- Dictionary get_time() const;
+ Dictionary get_date(bool utc) const;
+ Dictionary get_time(bool utc) const;
+ Dictionary get_time_zone_info() const;
uint64_t get_unix_time() const;
int get_static_memory_usage() const;
diff --git a/core/os/os.h b/core/os/os.h
index 2f9957c2f8..0230a75ca0 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -244,9 +244,15 @@ public:
int min;
int sec;
};
-
- virtual Date get_date() const=0;
- virtual Time get_time() const=0;
+
+ struct TimeZoneInfo {
+ int bias;
+ String name;
+ };
+
+ virtual Date get_date(bool local=false) const=0;
+ virtual Time get_time(bool local=false) const=0;
+ virtual TimeZoneInfo get_time_zone_info() const=0;
virtual uint64_t get_unix_time() const;
virtual void delay_usec(uint32_t p_usec) const=0;
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index d558aadc8e..8ba56490d7 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,17 +235,47 @@ 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;
ret.sec=lt->tm_sec;
+ get_time_zone_info();
return ret;
}
-
+
+OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
+ time_t t = time(NULL);
+ struct tm *lt = localtime(&t);
+ char name[16];
+ strftime(name, 16, "%Z", lt);
+ name[15] = 0;
+ TimeZoneInfo ret;
+ ret.name = name;
+
+ char bias_buf[16];
+ strftime(bias_buf, 16, "%z", lt);
+ int bias;
+ bias_buf[15] = 0;
+ sscanf(bias_buf, "%d", &bias);
+
+ // convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes
+ int hour = (int)bias / 100;
+ int minutes = bias % 100;
+ if (bias < 0)
+ ret.bias = hour * 60 - minutes;
+ else
+ ret.bias = hour * 60 + minutes;
+
+ return ret;
+}
+
void OS_Unix::delay_usec(uint32_t p_usec) const {
usleep(p_usec);
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index 65df113956..8bb57eda12 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -88,8 +88,9 @@ public:
virtual String get_name();
- virtual Date get_date() const;
- virtual Time get_time() const;
+ virtual Date get_date(bool utc) const;
+ virtual Time get_time(bool utc) const;
+ virtual TimeZoneInfo get_time_zone_info() const;
virtual uint64_t get_unix_time() const;
diff --git a/platform/nacl/os_nacl.cpp b/platform/nacl/os_nacl.cpp
index ffa9915256..b282209d72 100644
--- a/platform/nacl/os_nacl.cpp
+++ b/platform/nacl/os_nacl.cpp
@@ -240,10 +240,14 @@ MainLoop *OSNacl::get_main_loop() const {
return main_loop;
};
-OS::Date OSNacl::get_date() const {
+OS::Date OSNacl::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=lt->tm_year;
ret.month=(Month)lt->tm_mon;
@@ -254,10 +258,14 @@ OS::Date OSNacl::get_date() const {
return ret;
};
-OS::Time OSNacl::get_time() const {
+OS::Time OSNacl::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;
@@ -265,6 +273,32 @@ OS::Time OSNacl::get_time() const {
return ret;
};
+OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
+ time_t t = time(NULL);
+ struct tm *lt = localtime(&t);
+ char name[16];
+ strftime(name, 16, "%Z", lt);
+ name[15] = 0;
+ TimeZoneInfo ret;
+ ret.name = name;
+
+ char bias_buf[16];
+ strftime(bias_buf, 16, "%z", lt);
+ int bias;
+ bias_buf[15] = 0;
+ sscanf(bias_buf, "%d", &bias);
+
+ // convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes
+ int hour = (int)bias / 100;
+ int minutes = bias % 100;
+ if (bias < 0)
+ ret.bias = hour * 60 - minutes;
+ else
+ ret.bias = hour * 60 + minutes;
+
+ return ret;
+};
+
void OSNacl::delay_usec(uint32_t p_usec) const {
//usleep(p_usec);
diff --git a/platform/nacl/os_nacl.h b/platform/nacl/os_nacl.h
index 1150b12edd..e033abb68d 100644
--- a/platform/nacl/os_nacl.h
+++ b/platform/nacl/os_nacl.h
@@ -137,8 +137,8 @@ public:
virtual MainLoop *get_main_loop() const;
- virtual Date get_date() const;
- virtual Time get_time() const;
+ virtual Date get_date(bool utc) const;
+ virtual Time get_time(bool utc) const;
virtual void delay_usec(uint32_t p_usec) const;
virtual uint64_t get_ticks_usec() const;
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 4e8f9fcd9b..cdf9b007d1 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1832,7 +1832,10 @@ String OS_Windows::get_name() {
OS::Date OS_Windows::get_date() const {
SYSTEMTIME systemtime;
- GetSystemTime(&systemtime);
+ if (local)
+ GetSystemTime(&systemtime);
+ else
+ GetLocalTime(&systemtime);
Date date;
date.day=systemtime.wDay;
date.month=Month(systemtime.wMonth);
@@ -1841,10 +1844,13 @@ OS::Date OS_Windows::get_date() const {
date.dst=false;
return date;
}
-OS::Time OS_Windows::get_time() const {
+OS::Time OS_Windows::get_time(bool utc) const {
SYSTEMTIME systemtime;
- GetLocalTime(&systemtime);
+ if (utc)
+ GetSystemTime(&systemtime);
+ else
+ GetLocalTime(&systemtime);
Time time;
time.hour=systemtime.wHour;
@@ -1852,8 +1858,38 @@ OS::Time OS_Windows::get_time() const {
time.sec=systemtime.wSecond;
return time;
}
+OS::Time OS_Windows::get_time(bool utc) const {
+
+ SYSTEMTIME systemtime;
+ if (utc)
+ GetSystemTime(&systemtime);
+ else
+ GetLocalTime(&systemtime);
+
+ Time time;
+ time.hour=systemtime.wHour;
+ time.min=systemtime.wMinute;
+ time.sec=systemtime.wSecond;
+ return time;
+}
+
+OS::TimeZoneInfo OS_Windows::get_time_zone_info() const {
+ TIME_ZONE_INFORMATION info;
+ bool daylight = false;
+ if (GetTimeZoneInformation(info) == TIME_ZONE_ID_DAYLIGHT)
+ daylight = true;
+
+ if (daylight) {
+ ret.name = info.DaylightName;
+ } else {
+ ret.name = info.StandardName;
+ }
+
+ ret.bias = info.Bias;
+ return ret;
+}
-uint64_t OS_Windows::get_unix_time() const {
+uint64_t OS_Windows::get_unix_time(bool local) const {
FILETIME ft;
SYSTEMTIME st;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 64fbbf23c0..6b2eb19a76 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -259,8 +259,8 @@ public:
virtual String get_name();
- virtual Date get_date() const;
- virtual Time get_time() const;
+ virtual Date get_date(bool utc) const;
+ virtual Time get_time(bool utc) const;
virtual uint64_t get_unix_time() const;
virtual bool can_draw() const;
diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp
index 21a77b89cb..24037f05d7 100644
--- a/platform/winrt/os_winrt.cpp
+++ b/platform/winrt/os_winrt.cpp
@@ -445,7 +445,7 @@ String OSWinrt::get_name() {
OS::Date OSWinrt::get_date() const {
SYSTEMTIME systemtime;
- GetSystemTime(&systemtime);
+ GetLocalTime(&systemtime);
Date date;
date.day=systemtime.wDay;
date.month=Month(systemtime.wMonth);
@@ -454,10 +454,13 @@ OS::Date OSWinrt::get_date() const {
date.dst=false;
return date;
}
-OS::Time OSWinrt::get_time() const {
+OS::Time OSWinrt::get_time(bool utc) const {
SYSTEMTIME systemtime;
- GetSystemTime(&systemtime);
+ if (utc)
+ GetSystemTime(&systemtime);
+ else
+ GetLocalTime(&systemtime);
Time time;
time.hour=systemtime.wHour;
@@ -466,11 +469,30 @@ OS::Time OSWinrt::get_time() const {
return time;
}
-uint64_t OSWinrt::get_unix_time() const {
+OS::TimeZoneInfo OS_Windows::get_time_zone_info() const {
+ TIME_ZONE_INFORMATION info;
+ bool daylight = false;
+ if (GetTimeZoneInformation(info) == TIME_ZONE_ID_DAYLIGHT)
+ daylight = true;
+
+ if (daylight) {
+ ret.name = info.DaylightName;
+ } else {
+ ret.name = info.StandardName;
+ }
+
+ ret.bias = info.Bias;
+ return ret;
+}
+
+uint64_t OSWinrt::get_unix_time(bool utc) const {
FILETIME ft;
SYSTEMTIME st;
- GetSystemTime(&st);
+ if (utc)
+ GetSystemTime(&systemtime);
+ else
+ GetLocalTime(&systemtime);
SystemTimeToFileTime(&st, &ft);
SYSTEMTIME ep;
diff --git a/platform/winrt/os_winrt.h b/platform/winrt/os_winrt.h
index 68236309a9..af44bd338e 100644
--- a/platform/winrt/os_winrt.h
+++ b/platform/winrt/os_winrt.h
@@ -198,8 +198,8 @@ public:
virtual String get_name();
- virtual Date get_date() const;
- virtual Time get_time() const;
+ virtual Date get_date(bool utc) const;
+ virtual Time get_time(bool utc) const;
virtual uint64_t get_unix_time() const;
virtual bool can_draw() const;