检测夏令时算法

时间:2016-03-04 14:06:43

标签: c++ dst

我写了一个课程function advanced_wp_pagination(){ global $wp_query; $big = 999999999; echo paginate_links(array( 'base' => str_replace($big, '%#%', get_pagenum_link($big)), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages )); } function remove_page_from_query_string($query_string){ if ($query_string['name'] == 'page' && isset($query_string['page'])) { unset($query_string['name']); // 'page' in the query_string looks like '/2', so i'm spliting it out list($delim, $page_index) = split('/', $query_string['page']); $query_string['paged'] = $page_index; } return $query_string; } add_filter('request', 'remove_page_from_query_string'); function fix_category_pagination($qs){ if(isset($qs['category_name']) && isset($qs['paged'])){ $qs['post_type'] = get_post_types($args = array( 'public' => true, '_builtin' => false )); array_push($qs['post_type'],'pt-news'); } return $qs; } add_filter('request', 'fix_category_pagination'); 来管理时区和一些夏令时算法(InstantEurope)的日期和时间。 到目前为止,我让该类的用户使用USA作为默认值指定DST算法。但现在我想自动检测它的默认值。

这是我的第一个实施。它似乎在我的Windows 7工作站上运行(编译器:intel 14.0)(我juste必须澄清列表),但它在Linux openSUSE(编译器:gcc 4.8.3)上不起作用,因为Europe始终为0

tz.tz_dsttime

这样做的好方法是什么?

1 个答案:

答案 0 :(得分:1)

来自the gettimeofday man page

  

在Linux上,使用glibc,tz_dsttimesettimeofday()的结构时区 gettimeofday()字段的设置从未使用过。因此,以下纯粹具有历史价值。

     

在旧系统上,字段tz_dsttime包含符号常量......

     

......当然事实证明,夏令时生效的时期不能通过简单的算法给出,每个国家一个;实际上,这个时期是由不可预测的政治决定决定的。 所以这种表示时区的方法已被放弃

原始问题中的评论是正确的。您不应该尝试自己实现,尤其是使用废弃的API。

即使在示例代码的Windows部分中,您也会对DaylightName字段中可能找到的内容做出很多假设。你意识到时区比你正在测试的时区多得多,对吧?此外,在用户选择了除英语之外的主要语言的系统上,这些字符串的出现方式会完全不同。

C ++有很多好的时区库。任何有价值的事情都将使用the IANA tz database作为其来源。我会好好看看the best practices FAQthe timezone tag wiki。特别是,常见问题解答推荐CCTZICUTZ,并警告不要使用Boost来实现此功能。