#include "stdafx.h"#include "UsTimezone.h"#include <algorithm>/*** 含义:每行的两个时间戳(含)之间的时间为夏令时*/static INT64 g_arUSTimeRange[] = {513154800, 530690400 , //1986/4/6 2:0:0 - 1986年10月26日 1:0:0544604400, 562140000 , //1987/4/5 2:0:0 - 1987年10月25日 1:0:0576054000, 594194400 , //1988/4/3 2:0:0 - 1988年10月30日 1:0:0607503600, 625644000 , //1989/4/2 2:0:0 - 1989年10月29日 1:0:0638953200, 657093600 , //1990/4/1 2:0:0 - 1990年10月28日 1:0:0671007600, 688543200 , //1991/4/7 2:0:0 - 1991年10月27日 1:0:0702457200, 719992800 , //1992/4/5 2:0:0 - 1992年10月25日 1:0:0733906800, 752047200 , //1993/4/4 2:0:0 - 1993年10月31日 1:0:0765356400, 783496800 , //1994/4/3 2:0:0 - 1994年10月30日 1:0:0796806000, 814946400 , //1995/4/2 2:0:0 - 1995年10月29日 1:0:0828860400, 846396000 , //1996/4/7 2:0:0 - 1996年10月27日 1:0:0860310000, 877845600 , //1997/4/6 2:0:0 - 1997年10月26日 1:0:0891759600, 909295200 , //1998/4/5 2:0:0 - 1998年10月25日 1:0:0923209200, 941349600 , //1999/4/4 2:0:0 - 1999年10月31日 1:0:0954658800, 972799200 , //2000/4/2 2:0:0 - 2000年10月29日 1:0:0986108400, 1004248800 , //2001/4/1 2:0:0 - 2001年10月28日 1:0:01018162800, 1035698400 , //2002/4/7 2:0:0 - 2002年10月27日 1:0:01049612400, 1067148000 , //2003/4/6 2:0:0 - 2003年10月26日 1:0:01081062000, 1099202400 , //2004/4/4 2:0:0 - 2004年10月31日 1:0:01112511600, 1130652000 , //2005/4/3 2:0:0 - 2005年10月30日 1:0:01143961200, 1162101600 , //2006/4/2 2:0:0 - 2006年10月29日 1:0:01173596400, 1194156000 , //2007/3/11 2:0:0 - 2007年11月4日 1:0:01205046000, 1225605600 , //2008/3/9 2:0:0 - 2008年11月2日 1:0:01236495600, 1257055200 , //2009/3/8 2:0:0 - 2009年11月1日 1:0:01268550000, 1289109600 , //2010/3/14 2:0:0 - 2010年11月7日 1:0:01299999600, 1320559200 , //2011/3/13 2:0:0 - 2011年11月6日 1:0:01331449200, 1352008800 , //2012/3/11 2:0:0 - 2012年11月4日 1:0:01362898800, 1383458400 , //2013/3/10 2:0:0 - 2013年11月3日 1:0:01394348400, 1414908000 , //2014/3/9 2:0:0 - 2014年11月2日 1:0:01425798000, 1446357600 , //2015/3/8 2:0:0 - 2015年11月1日 1:0:01457852400, 1478412000 , //2016/3/13 2:0:0 - 2016年11月6日 1:0:01489302000, 1509861600 , //2017/3/12 2:0:0 - 2017年11月5日 1:0:01520751600, 1541311200 , //2018/3/11 2:0:0 - 2018年11月4日 1:0:01552201200, 1572760800 , //2019/3/10 2:0:0 - 2019年11月3日 1:0:01583650800, 1604210400 , //2020/3/8 2:0:0 - 2020年11月1日 1:0:01615705200, 1636264800 , //2021/3/14 2:0:0 - 2021年11月7日 1:0:01647154800, 1667714400 , //2022/3/13 2:0:0 - 2022年11月6日 1:0:01678604400, 1699164000 , //2023/3/12 2:0:0 - 2023年11月5日 1:0:01710054000, 1730613600 , //2024/3/10 2:0:0 - 2024年11月3日 1:0:01741503600, 1762063200 , //2025/3/9 2:0:0 - 2025年11月2日 1:0:01772953200, 1793512800 , //2026/3/8 2:0:0 - 2026年11月1日 1:0:01805007600, 1825567200 , //2027/3/14 2:0:0 - 2027年11月7日 1:0:01836457200, 1857016800 , //2028/3/12 2:0:0 - 2028年11月5日 1:0:01867906800, 1888466400 , //2029/3/11 2:0:0 - 2029年11月4日 1:0:01899356400, 1919916000 , //2030/3/10 2:0:0 - 2030年11月3日 1:0:01930806000, 1951365600 , //2031/3/9 2:0:0 - 2031年11月2日 1:0:01962860400, 1983420000 , //2032/3/14 2:0:0 - 2032年11月7日 1:0:01994310000, 2014869600 , //2033/3/13 2:0:0 - 2033年11月6日 1:0:02025759600, 2046319200 , //2034/3/12 2:0:0 - 2034年11月5日 1:0:02057209200, 2077768800 , //2035/3/11 2:0:0 - 2035年11月4日 1:0:02088658800, 2109218400 , //2036/3/9 2:0:0 - 2036年11月2日 1:0:02120108400, 2140668000 , //2037/3/8 2:0:0 - 2037年11月1日 1:0:02152162800, 2172722400 , //2038/3/14 2:0:0 - 2038年11月7日 1:0:02183612400, 2204172000 , //2039/3/13 2:0:0 - 2039年11月6日 1:0:02215062000, 2235621600 , //2040/3/11 2:0:0 - 2040年11月4日 1:0:02246511600, 2267071200 , //2041/3/10 2:0:0 - 2041年11月3日 1:0:02277961200, 2298520800 , //2042/3/9 2:0:0 - 2042年11月2日 1:0:02309410800, 2329970400 , //2043/3/8 2:0:0 - 2043年11月1日 1:0:02341465200, 2362024800 , //2044/3/13 2:0:0 - 2044年11月6日 1:0:02372914800, 2393474400 , //2045/3/12 2:0:0 - 2045年11月5日 1:0:02404364400, 2424924000 , //2046/3/11 2:0:0 - 2046年11月4日 1:0:02435814000, 2456373600 , //2047/3/10 2:0:0 - 2047年11月3日 1:0:02467263600, 2487823200 , //2048/3/8 2:0:0 - 2048年11月1日 1:0:02499318000, 2519877600 , //2049/3/14 2:0:0 - 2049年11月7日 1:0:02530767600, 2551327200 , //2050/3/13 2:0:0 - 2050年11月6日 1:0:0};/*** 含义:每行的两个时间戳(含)之间的时间为夏令时*/static int g_arUSYMDRange[] = {19860406, 19861026,19870405, 19871025,19880403, 19881030,19890402, 19891029,19900401, 19901028,19910407, 19911027,19920405, 19921025,19930404, 19931031,19940403, 19941030,19950402, 19951029,19960407, 19961027,19970406, 19971026,19980405, 19981025,19990404, 19991031,20000402, 20001029,20010401, 20011028,20020407, 20021027,20030406, 20031026,20040404, 20041031,20050403, 20051030,20060402, 20061029,20070311, 20071104,20080309, 20081102,20090308, 20091101,20100314, 20101107,20110313, 20111106,20120311, 20121104,20130310, 20131103,20140309, 20141102,20150308, 20151101,20160313, 20161106,20170312, 20171105,20180311, 20181104,20190310, 20191103,20200308, 20201101,20210314, 20211107,20220313, 20221106,20230312, 20231105,20240310, 20241103,20250309, 20251102,20260308, 20261101,20270314, 20271107,20280312, 20281105,20290311, 20291104,20300310, 20301103,20310309, 20311102,20320314, 20321107,20330313, 20331106,20340312, 20341105,20350311, 20351104,20360309, 20361102,20370308, 20371101,20380314, 20381107,20390313, 20391106,20400311, 20401104,20410310, 20411103,20420309, 20421102,20430308, 20431101,20440313, 20441106,20450312, 20451105,20460311, 20461104,20470310, 20471103,20480308, 20481101,20490314, 20491107,20500313, 20501106,};UsTimezone::UsTimezone(){}UsTimezone::~UsTimezone(){}int UsTimezone::GetTimestampTimezone(int nTimestamp){if ( nTimestamp < g_arUSTimeRange[0]|| nTimestamp > g_arUSTimeRange[_countof(g_arUSTimeRange) - 1] ){return -5;}INT64 *itFind = std::lower_bound(g_arUSTimeRange, g_arUSTimeRange + _countof(g_arUSTimeRange), (INT64)nTimestamp);int nFindIdx = int(itFind - g_arUSTimeRange);if ( (nFindIdx % 2 == 0) && (*itFind == (INT64)nTimestamp) ){return -4;}if ( nFindIdx % 2 != 0 ){return -4;}return -5;}//nYear, nMonth, nDay: 日常认知的年月日int UsTimezone::GetTMStructTimezone(int nYear, int nMonth, int nDay){if ( nYear < 0 || nMonth < 0 || nDay < 0 )return -5;int nYMD = nYear * 10000 + nMonth * 100 + nDay;if ( nYMD < g_arUSYMDRange[0]|| nYMD > g_arUSYMDRange[_countof(g_arUSYMDRange) - 1] ){return -5;}int *itFind = std::lower_bound(g_arUSYMDRange, g_arUSYMDRange + _countof(g_arUSYMDRange), (int)nYMD);int nFindIdx = int(itFind - g_arUSYMDRange);if ( (nFindIdx % 2 == 0) && (*itFind == (int)nYMD) ){return -4;}if ( nFindIdx % 2 != 0 ){return -4;}return -5;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。