digitalmars.D.learn - How to get the current Timezone
- wobbles (6/6) Aug 28 2015 From the docs in std.datetime, I figured I could write:
- Adam D. Ruppe (16/18) Aug 28 2015 from the doc:
- Kagamin (1/1) Aug 28 2015 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation ...
- WhatMeWorry (3/11) Aug 28 2015 Stupid question. If it always returns an empty string, why is it
- Adam D. Ruppe (7/9) Aug 28 2015 It can return meaningful information in other subclasses; it is a
- Jonathan M Davis via Digitalmars-d-learn (12/21) Aug 28 2015 A prime example would be PosixTimeZone. It knows exactly what its name i...
- rumbu (3/6) Aug 28 2015 Starting with Windows 8.1, it does, but only in Windows Runtime
- Jonathan M Davis via Digitalmars-d-learn (7/15) Aug 30 2015 Well, that's good news but ultimately pretty useless. If it's really goi...
From the docs in std.datetime, I figured I could write: Clock.currTime.timezone().name() to get the timezone this system is in. However, it just returns an empty string. Anyone know how to get the timezone of the machine easily? Thanks!
Aug 28 2015
On Friday, 28 August 2015 at 14:07:37 UTC, wobbles wrote:However, it just returns an empty string.from the doc: Note that this always returns the empty string. This is because time zones cannot be uniquely identified by the attributes given by the OS (such as the stdName and dstName), and neither Posix systems nor Windows systems provide an easy way to get the TZ Database name of the local time zone.Anyone know how to get the timezone of the machine easily?Best you can do is try the stdName or dstName properties of Timezone, perhaps checking if dstInEffect to choose which one to print. Or ou could use the utcOffsetAt function to print a number (like UTC-4:00, after formatting it) The actual location the user sets in the timezone settings of the computer I think the docs are right about - it isn't available on either OS, even using platform specific APIs... though I'm sure it is stored somewhere and maybe you could e.g. dig into the Windows registry to find it.
Aug 28 2015
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation ?
Aug 28 2015
On Friday, 28 August 2015 at 14:18:24 UTC, Adam D. Ruppe wrote:On Friday, 28 August 2015 at 14:07:37 UTC, wobbles wrote:Stupid question. If it always returns an empty string, why is it even there?However, it just returns an empty string.from the doc: Note that this always returns the empty string. This is because time zones cannot be uniquely identified by the attributes given by the OS (such as the stdName and dstName), and neither Posix systems nor Windows systems provide an easy way to get the TZ Database name of the local time zone.
Aug 28 2015
On Friday, 28 August 2015 at 17:59:06 UTC, WhatMeWorry wrote:Stupid question. If it always returns an empty string, why is it even there?It can return meaningful information in other subclasses; it is a method from the interface and is just blank in the LocalTime class. If you construct one of the other subclasses, you may provide a name which can be retrieved through it, or perhaps some future class might implement it too.
Aug 28 2015
On Friday, August 28, 2015 18:04:16 Adam D. Ruppe via Digitalmars-d-learn wrote:On Friday, 28 August 2015 at 17:59:06 UTC, WhatMeWorry wrote:A prime example would be PosixTimeZone. It knows exactly what its name is. Ultimately though, the name field probably isn't very useful - particularly since I really need to deprecate the functions for converting between the TZ database names and Microsft's names, because it's system dependent, and they keep changing it, so there's no guarantee that the mapping is correct or even that the result exists on a given box (since that box could be out-of-date, or the D program may not have been updated). That being the case, the name property really just becomes applicable to PosixTimeZone. I _really_ wish that Microsoft would just use the TZ database like everyone else... - Jonathan M DavisStupid question. If it always returns an empty string, why is it even there?It can return meaningful information in other subclasses; it is a method from the interface and is just blank in the LocalTime class. If you construct one of the other subclasses, you may provide a name which can be retrieved through it, or perhaps some future class might implement it too.
Aug 28 2015
On Friday, 28 August 2015 at 23:03:16 UTC, Jonathan M Davis wrote:I _really_ wish that Microsoft would just use the TZ database like everyone else... - Jonathan M DavisStarting with Windows 8.1, it does, but only in Windows Runtime (so called modern/store apps).
Aug 28 2015
On Saturday, August 29, 2015 05:25:33 rumbu via Digitalmars-d-learn wrote:On Friday, 28 August 2015 at 23:03:16 UTC, Jonathan M Davis wrote:Well, that's good news but ultimately pretty useless. If it's really going ot be of any use to applications in general, then the OS itself needs to be using the TZ database files, and that needs to be accessible via their normal C API, not just the WinRT stuff. But maybe this is a good sign for the future. - Jonathan M DavisI _really_ wish that Microsoft would just use the TZ database like everyone else... - Jonathan M DavisStarting with Windows 8.1, it does, but only in Windows Runtime (so called modern/store apps).
Aug 30 2015