有没有一种可移植的方法可以将本地系统时区转换为 libical icaltimetype?
Is there a portable way to get the local system timezone into a libical icaltimetype?
libical 似乎只接受奥尔森城市名称以在其数据库中查找时区。
我得到的可移植的是一个 struct tm ,它有一个 GMT 偏移量和 shorthand 3-4 字母代码(EST/EDT 等)但是在 libical 中没有接受它的函数。
我有一个非常糟糕的方法,我从 libical 扫描 tz 列表试图匹配 tznames,这可能会起作用,但我很清楚这是一个坏主意。但是我还没有找到任何其他方法将本地时区转换为 libical icaltimetype。
我是不是漏掉了一些简单的东西?
我所说的便携式是指 windows、osx 和 linux。
这是我正在写的一个c程序。
但我现在看到 tz 偏移量不是 posix,所以那不行。
所以我认为答案是没有答案。反正没什么可移植的。
所以我有 linux 和 osx 的单独构建路径,但我还没有达到 windows..
linux 实现只是从 /etc/timezone 读取(更多关于 How do I find the current system timezone?)
并且 osx 实现就是这样做的。
CFTimeZoneRef tzlocal = CFTimeZoneCopyDefault();
CFStringRef me = CFTimeZoneGetName(tzlocal);
NSString *local = (__bridge NSString *)me;
const char *tzname = [local cStringUsingEncoding:NSUTF8StringEncoding];
log.debug("Looking up timezone for %s", tzname);
// this is a built-in timezone so we don't have to free it.
local_timezone = icaltimezone_get_builtin_timezone(tzname);
不可移植但至少它是正确的。
libical 似乎只接受奥尔森城市名称以在其数据库中查找时区。 我得到的可移植的是一个 struct tm ,它有一个 GMT 偏移量和 shorthand 3-4 字母代码(EST/EDT 等)但是在 libical 中没有接受它的函数。
我有一个非常糟糕的方法,我从 libical 扫描 tz 列表试图匹配 tznames,这可能会起作用,但我很清楚这是一个坏主意。但是我还没有找到任何其他方法将本地时区转换为 libical icaltimetype。
我是不是漏掉了一些简单的东西?
我所说的便携式是指 windows、osx 和 linux。
这是我正在写的一个c程序。 但我现在看到 tz 偏移量不是 posix,所以那不行。
所以我认为答案是没有答案。反正没什么可移植的。
所以我有 linux 和 osx 的单独构建路径,但我还没有达到 windows..
linux 实现只是从 /etc/timezone 读取(更多关于 How do I find the current system timezone?)
并且 osx 实现就是这样做的。
CFTimeZoneRef tzlocal = CFTimeZoneCopyDefault();
CFStringRef me = CFTimeZoneGetName(tzlocal);
NSString *local = (__bridge NSString *)me;
const char *tzname = [local cStringUsingEncoding:NSUTF8StringEncoding];
log.debug("Looking up timezone for %s", tzname);
// this is a built-in timezone so we don't have to free it.
local_timezone = icaltimezone_get_builtin_timezone(tzname);
不可移植但至少它是正确的。