mirror of
https://github.com/godotengine/godot.git
synced 2025-10-24 18:33:36 +00:00
Add OS.get_time_zone_info function
The returned dictionary maps "name" to the name of the current time zone, and "bias" to a bias from UTC in minutes.
This commit is contained in:
parent
803069886e
commit
c5338fd6c4
8 changed files with 119 additions and 2 deletions
|
|
@ -246,9 +246,36 @@ OS::Time OS_Unix::get_time(bool utc) const {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue