#include "copyright.h"#include "autoconf.h"#include "config.h"#include "externs.h"#include <time.h>#include "timeutil.h"#include "stringutil.h"Include dependency graph for timeutil.cpp:

Go to the source code of this file.
Data Structures | |
| struct | OffsetEntry |
| struct | tag_pd_node |
| struct | tag_pd_breakdown |
| struct | tag_AllFields |
| struct | tag_pd_numeric_valid |
| struct | PD_TEXT_ENTRY |
| struct | tag_pd_cantbe |
Defines | |
| #define | PFSS_PRECISION 7 |
| #define | MAX_OFFSETS 50 |
| #define | PDTT_SYMBOL 1 |
| #define | PDTT_NUMERIC_UNSIGNED 2 |
| #define | PDTT_SPACES 3 |
| #define | PDTT_TEXT 4 |
| #define | PDTT_NUMERIC_SIGNED 5 |
| #define | PDCB_NOTHING 0x00000000 |
| #define | PDCB_TIME_FIELD_SEPARATOR 0x00000001 |
| #define | PDCB_DATE_FIELD_SEPARATOR 0x00000002 |
| #define | PDCB_WHITESPACE 0x00000004 |
| #define | PDCB_DAY_OF_MONTH_SUFFIX 0x00000008 |
| #define | PDCB_SIGN 0x00000010 |
| #define | PDCB_SECONDS_DECIMAL 0x00000020 |
| #define | PDCB_REMOVEABLE 0x00000040 |
| #define | PDCB_YEAR 0x00000080 |
| #define | PDCB_MONTH 0x00000100 |
| #define | PDCB_DAY_OF_MONTH 0x00000200 |
| #define | PDCB_DAY_OF_WEEK 0x00000400 |
| #define | PDCB_WEEK_OF_YEAR 0x00000800 |
| #define | PDCB_DAY_OF_YEAR 0x00001000 |
| #define | PDCB_YD 0x00002000 |
| #define | PDCB_YMD 0x00004000 |
| #define | PDCB_MDY 0x00008000 |
| #define | PDCB_DMY 0x00010000 |
| #define | PDCB_DATE_TIME_SEPARATOR 0x00020000 |
| #define | PDCB_TIMEZONE 0x00040000 |
| #define | PDCB_WEEK_OF_YEAR_PREFIX 0x00080000 |
| #define | PDCB_MERIDIAN 0x00100000 |
| #define | PDCB_MINUTE 0x00200000 |
| #define | PDCB_SECOND 0x00400000 |
| #define | PDCB_SUBSECOND 0x00800000 |
| #define | PDCB_HOUR_TIME 0x01000000 |
| #define | PDCB_HMS_TIME 0x02000000 |
| #define | PDCB_HOUR_TIMEZONE 0x04000000 |
| #define | PDCB_HMS_TIMEZONE 0x08000000 |
| #define | NOT_PRESENT -9999999 |
| #define | PD_LEX_INVALID 0 |
| #define | PD_LEX_SYMBOL 1 |
| #define | PD_LEX_DIGIT 2 |
| #define | PD_LEX_SPACE 3 |
| #define | PD_LEX_ALPHA 4 |
| #define | PD_LEX_EOS 5 |
| #define | MAX_NODES 200 |
| #define | PDCB_SEPS (PDCB_YEAR|PDCB_MONTH|PDCB_DAY_OF_MONTH|PDCB_DAY_OF_YEAR|PDCB_WEEK_OF_YEAR|PDCB_DAY_OF_WEEK) |
| #define | PDCB_SIGNABLES_POS (PDCB_HMS_TIME|PDCB_HMS_TIMEZONE) |
| #define | PDCB_SIGNABLES_NEG (PDCB_YEAR|PDCB_YD|PDCB_SIGNABLES_POS|PDCB_YMD) |
Typedefs | |
| typedef tag_pd_node | PD_Node |
| typedef void | BREAK_DOWN_FUNC (PD_Node *pNode) |
| typedef tag_pd_breakdown | PD_BREAKDOWN |
| typedef tag_AllFields | ALLFIELDS |
| typedef bool | PVALIDFUNC (size_t nStr, char *pStr, int iValue) |
| typedef tag_pd_numeric_valid | NUMERIC_VALID_RECORD |
| typedef tag_pd_cantbe | PD_CANTBE |
Functions | |
| int | iMod (int x, int y) |
| INT64 | i64Mod (INT64 x, INT64 y) |
| DCL_INLINE int | iRemainder (int x, int y) |
| DCL_INLINE int | iDivision (int x, int y) |
| static int | iFloorDivision (int x, int y) |
| INT64 | i64FloorDivision (INT64 x, INT64 y) |
| int | iFloorDivisionMod (int x, int y, int *piMod) |
| static INT64 | i64FloorDivisionMod (INT64 x, INT64 y, INT64 *piMod) |
| static void | GetUTCLinearTime (INT64 *plt) |
| bool | operator< (const CLinearTimeAbsolute <a, const CLinearTimeAbsolute <b) |
| bool | operator> (const CLinearTimeAbsolute <a, const CLinearTimeAbsolute <b) |
| bool | operator== (const CLinearTimeAbsolute <a, const CLinearTimeAbsolute <b) |
| bool | operator== (const CLinearTimeDelta <a, const CLinearTimeDelta <b) |
| bool | operator!= (const CLinearTimeDelta <a, const CLinearTimeDelta <b) |
| bool | operator<= (const CLinearTimeDelta <a, const CLinearTimeDelta <b) |
| bool | operator<= (const CLinearTimeAbsolute <a, const CLinearTimeAbsolute <b) |
| CLinearTimeAbsolute | operator- (const CLinearTimeAbsolute <a, const CLinearTimeDelta <d) |
| static bool | ParseFractionalSecondsString (INT64 &i64, char *str) |
| static void | ConvertToSecondsString (char *buffer, INT64 n64, int nFracDigits) |
| bool | isLeapYear (long iYear) |
| static bool | isValidDate (int iYear, int iMonth, int iDay) |
| static int | FixedFromGregorian (int iYear, int iMonth, int iDay) |
| static int | FixedFromGregorian_Adjusted (int iYear, int iMonth, int iDay) |
| static void | GregorianFromFixed (int iFixedDay, int &iYear, int &iMonth, int &iDayOfYear, int &iDayOfMonth, int &iDayOfWeek) |
| static void | GregorianFromFixed_Adjusted (int iFixedDay, int &iYear, int &iMonth, int &iDayOfYear, int &iDayOfMonth, int &iDayOfWeek) |
| static bool | ParseThreeLetters (const char **pp, int *piHash) |
| static void | ParseDecimalSeconds (size_t n, const char *p, unsigned short *iMilli, unsigned short *iMicro, unsigned short *iNano) |
| static bool | do_convtime (const char *str, FIELDEDTIME *ft) |
| CLinearTimeDelta | operator- (const CLinearTimeAbsolute <aA, const CLinearTimeAbsolute <aB) |
| CLinearTimeDelta | operator- (const CLinearTimeDelta <a, const CLinearTimeDelta <b) |
| CLinearTimeAbsolute | operator+ (const CLinearTimeAbsolute <aA, const CLinearTimeDelta <dB) |
| CLinearTimeDelta | operator * (const CLinearTimeDelta <d, int Scale) |
| int | operator/ (const CLinearTimeDelta <dA, const CLinearTimeDelta <dB) |
| bool | operator< (const CLinearTimeDelta <dA, const CLinearTimeDelta <dB) |
| bool | operator> (const CLinearTimeDelta <dA, const CLinearTimeDelta <dB) |
| static void | SetStructTm (FIELDEDTIME *ft, struct tm *ptm) |
| bool | FieldedTimeToLinearTime (FIELDEDTIME *ft, INT64 *plt) |
| bool | LinearTimeToFieldedTime (INT64 lt, FIELDEDTIME *ft) |
| static int | YearType (int iYear) |
| static time_t | time_t_midpoint (time_t tLower, time_t tUpper) |
| static time_t | time_t_largest (void) |
| static time_t | time_t_smallest (void) |
| static void | test_time_t (void) |
| void | TIME_Initialize (void) |
| static int | FindOffsetEntry (const CLinearTimeAbsolute <a) |
| static bool | QueryOffsetTable (CLinearTimeAbsolute lta, CLinearTimeDelta *pltdOffset, bool *pisDST, int *piEntry) |
| static void | UpdateOffsetTable (CLinearTimeAbsolute <a, CLinearTimeDelta ltdOffset, bool isDST, int i) |
| static CLinearTimeDelta | QueryLocalOffsetAt_Internal (CLinearTimeAbsolute lta, bool *pisDST, int iEntry) |
| static CLinearTimeDelta | QueryLocalOffsetAtUTC (const CLinearTimeAbsolute <a, bool *pisDST) |
| static PD_Node * | PD_NewNode (void) |
| static void | PD_AppendNode (PD_Node *pNode) |
| static void | PD_InsertAfter (PD_Node *pWhere, PD_Node *pNode) |
| static bool | isValidYear (size_t nStr, char *pStr, int iValue) |
| static bool | isValidMonth (size_t nStr, char *pStr, int iValue) |
| static bool | isValidDayOfMonth (size_t nStr, char *pStr, int iValue) |
| static bool | isValidDayOfWeek (size_t nStr, char *pStr, int iValue) |
| static bool | isValidDayOfYear (size_t nStr, char *pStr, int iValue) |
| static bool | isValidWeekOfYear (size_t nStr, char *pStr, int iValue) |
| static bool | isValidHour (size_t nStr, char *pStr, int iValue) |
| static bool | isValidMinute (size_t nStr, char *pStr, int iValue) |
| static bool | isValidSecond (size_t nStr, char *pStr, int iValue) |
| static bool | isValidSubSecond (size_t nStr, char *pStr, int iValue) |
| static bool | isValidHMS (size_t nStr, char *pStr, int iValue) |
| static void | SplitLastTwoDigits (PD_Node *pNode, unsigned mask) |
| static void | SplitLastThreeDigits (PD_Node *pNode, unsigned mask) |
| static void | BreakDownHMS (PD_Node *pNode) |
| static bool | isValidYMD (size_t nStr, char *pStr, int iValue) |
| static void | BreakDownYMD (PD_Node *pNode) |
| static bool | isValidMDY (size_t nStr, char *pStr, int iValue) |
| static void | BreakDownMDY (PD_Node *pNode) |
| static bool | isValidDMY (size_t nStr, char *pStr, int iValue) |
| static void | BreakDownDMY (PD_Node *pNode) |
| static bool | isValidYD (size_t nStr, char *pStr, int iValue) |
| static void | BreakDownYD (PD_Node *pNode) |
| static void | ClassifyNumericToken (PD_Node *pNode) |
| static void | PD_Reset (void) |
| static PD_Node * | PD_FirstNode (void) |
| static PD_Node * | PD_NextNode (PD_Node *pNode) |
| static PD_Node * | PD_PrevNode (PD_Node *pNode) |
| static void | PD_RemoveNode (PD_Node *pNode) |
| static PD_Node * | PD_ScanNextToken (char **ppString) |
| static void | PD_Pass2 (void) |
| static void | PD_Deduction (void) |
| static void | PD_BreakItDown (void) |
| static void | PD_Pass5 (void) |
| static void | PD_Pass6 (void) |
| static bool | PD_GetFields (ALLFIELDS *paf) |
| static bool | ConvertAllFieldsToLinearTime (CLinearTimeAbsolute <a, ALLFIELDS *paf) |
| bool | ParseDate (CLinearTimeAbsolute <, char *pDateString, bool *pbZoneSpecified) |
Variables | |
| CMuxAlarm | MuxAlarm |
| const INT64 | FACTOR_100NS_PER_SECOND = 10000000ull |
| const INT64 | FACTOR_100NS_PER_MINUTE = FACTOR_100NS_PER_SECOND*60 |
| const INT64 | FACTOR_100NS_PER_HOUR = FACTOR_100NS_PER_MINUTE*60 |
| const INT64 | FACTOR_100NS_PER_DAY = FACTOR_100NS_PER_HOUR*24 |
| const INT64 | FACTOR_100NS_PER_WEEK = FACTOR_100NS_PER_DAY*7 |
| char * | DayOfWeekString [7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" } |
| static const char | daystab [] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
| const char * | monthtab [] |
| static int | MonthTabHash [12] |
| static CLinearTimeAbsolute | ltaLowerBound |
| static CLinearTimeAbsolute | ltaUpperBound |
| static CLinearTimeDelta | ltdTimeZoneStandard |
| static int | NearestYearOfType [15] |
| static CLinearTimeDelta | ltdIntervalMinimum |
| static bool | bTimeInitialized = false |
| static int | nOffsetTable = 0 |
| static int | nTouched0 = 0 |
| static OffsetEntry | OffsetTable [MAX_OFFSETS] |
| static const int | InitialCouldBe [9] |
| const NUMERIC_VALID_RECORD | NumericSet [] |
| const PD_TEXT_ENTRY | PD_TextTable [] |
| const char | LexTable [256] |
| static int | nNodes = 0 |
| static PD_Node | Nodes [MAX_NODES] |
| static PD_Node * | PD_Head = 0 |
| static PD_Node * | PD_Tail = 0 |
| static const PD_BREAKDOWN | BreakDownTable [] |
| const PD_CANTBE | CantBeTable [] |
Date/Time code based on algorithms presented in "Calendrical Calculations", Cambridge Press, 1998.
The two primary classes are CLinearTimeAbsolute and CLinearTimeDelta deal with civil time from a fixed Epoch and time differences generally, respectively.
This file also contains code related to parsing date strings and glossing over time-related platform differences.
Definition in file timeutil.cpp.
| #define MAX_NODES 200 |
| #define MAX_OFFSETS 50 |
| #define NOT_PRESENT -9999999 |
Definition at line 2524 of file timeutil.cpp.
Referenced by ConvertAllFieldsToLinearTime(), ParseDate(), and PD_GetFields().
| #define PD_LEX_ALPHA 4 |
| #define PD_LEX_DIGIT 2 |
| #define PD_LEX_EOS 5 |
| #define PD_LEX_INVALID 0 |
| #define PD_LEX_SPACE 3 |
| #define PD_LEX_SYMBOL 1 |
| #define PDCB_DATE_FIELD_SEPARATOR 0x00000002 |
| #define PDCB_DATE_TIME_SEPARATOR 0x00020000 |
| #define PDCB_DAY_OF_MONTH 0x00000200 |
Definition at line 2494 of file timeutil.cpp.
Referenced by BreakDownDMY(), BreakDownMDY(), BreakDownYMD(), PD_GetFields(), PD_Pass2(), PD_Pass5(), and PD_Pass6().
| #define PDCB_DAY_OF_MONTH_SUFFIX 0x00000008 |
| #define PDCB_DAY_OF_WEEK 0x00000400 |
Definition at line 2495 of file timeutil.cpp.
Referenced by PD_GetFields(), PD_Pass5(), and PD_Pass6().
| #define PDCB_DAY_OF_YEAR 0x00001000 |
Definition at line 2497 of file timeutil.cpp.
Referenced by BreakDownYD(), PD_GetFields(), PD_Pass5(), and PD_Pass6().
| #define PDCB_DMY 0x00010000 |
| #define PDCB_HMS_TIME 0x02000000 |
Definition at line 2510 of file timeutil.cpp.
Referenced by BreakDownHMS(), PD_Pass2(), PD_Pass5(), and PD_Pass6().
| #define PDCB_HMS_TIMEZONE 0x08000000 |
| #define PDCB_HOUR_TIME 0x01000000 |
Definition at line 2509 of file timeutil.cpp.
Referenced by BreakDownHMS(), PD_GetFields(), PD_Pass2(), PD_Pass5(), and PD_Pass6().
| #define PDCB_HOUR_TIMEZONE 0x04000000 |
Definition at line 2511 of file timeutil.cpp.
Referenced by BreakDownHMS(), PD_GetFields(), PD_Pass2(), and PD_Pass5().
| #define PDCB_MDY 0x00008000 |
| #define PDCB_MERIDIAN 0x00100000 |
| #define PDCB_MINUTE 0x00200000 |
Definition at line 2506 of file timeutil.cpp.
Referenced by BreakDownHMS(), PD_GetFields(), PD_Pass2(), and PD_Pass5().
| #define PDCB_MONTH 0x00000100 |
Definition at line 2493 of file timeutil.cpp.
Referenced by BreakDownDMY(), BreakDownMDY(), BreakDownYMD(), PD_GetFields(), PD_Pass5(), and PD_Pass6().
| #define PDCB_NOTHING 0x00000000 |
| #define PDCB_REMOVEABLE 0x00000040 |
Definition at line 2491 of file timeutil.cpp.
Referenced by PD_Pass2(), PD_Pass5(), and PD_ScanNextToken().
| #define PDCB_SECOND 0x00400000 |
Definition at line 2507 of file timeutil.cpp.
Referenced by BreakDownHMS(), PD_GetFields(), PD_Pass2(), and PD_Pass5().
| #define PDCB_SECONDS_DECIMAL 0x00000020 |
| #define PDCB_SEPS (PDCB_YEAR|PDCB_MONTH|PDCB_DAY_OF_MONTH|PDCB_DAY_OF_YEAR|PDCB_WEEK_OF_YEAR|PDCB_DAY_OF_WEEK) |
Referenced by PD_Pass2().
| #define PDCB_SIGN 0x00000010 |
Definition at line 2489 of file timeutil.cpp.
Referenced by PD_GetFields(), PD_Pass2(), and PD_ScanNextToken().
| #define PDCB_SIGNABLES_NEG (PDCB_YEAR|PDCB_YD|PDCB_SIGNABLES_POS|PDCB_YMD) |
Referenced by PD_Pass2().
| #define PDCB_SIGNABLES_POS (PDCB_HMS_TIME|PDCB_HMS_TIMEZONE) |
Referenced by PD_Pass2().
| #define PDCB_SUBSECOND 0x00800000 |
Definition at line 2508 of file timeutil.cpp.
Referenced by PD_GetFields(), PD_Pass2(), and PD_Pass5().
| #define PDCB_TIME_FIELD_SEPARATOR 0x00000001 |
| #define PDCB_TIMEZONE 0x00040000 |
| #define PDCB_WEEK_OF_YEAR 0x00000800 |
Definition at line 2496 of file timeutil.cpp.
Referenced by PD_GetFields(), PD_Pass5(), and PD_Pass6().
| #define PDCB_WEEK_OF_YEAR_PREFIX 0x00080000 |
| #define PDCB_WHITESPACE 0x00000004 |
| #define PDCB_YD 0x00002000 |
| #define PDCB_YEAR 0x00000080 |
Definition at line 2492 of file timeutil.cpp.
Referenced by BreakDownDMY(), BreakDownMDY(), BreakDownYD(), BreakDownYMD(), PD_GetFields(), PD_Pass5(), and PD_Pass6().
| #define PDCB_YMD 0x00004000 |
Definition at line 2499 of file timeutil.cpp.
| #define PDTT_NUMERIC_SIGNED 5 |
Definition at line 2471 of file timeutil.cpp.
| #define PDTT_NUMERIC_UNSIGNED 2 |
| #define PDTT_SPACES 3 |
| #define PDTT_SYMBOL 1 |
| #define PDTT_TEXT 4 |
| #define PFSS_PRECISION 7 |
Referenced by ParseFractionalSecondsString().
| typedef struct tag_AllFields ALLFIELDS |
| typedef void BREAK_DOWN_FUNC(PD_Node *pNode) |
Definition at line 2517 of file timeutil.cpp.
| typedef struct tag_pd_numeric_valid NUMERIC_VALID_RECORD |
| typedef struct tag_pd_breakdown PD_BREAKDOWN |
| typedef struct tag_pd_cantbe PD_CANTBE |
| typedef struct tag_pd_node PD_Node |
| typedef bool PVALIDFUNC(size_t nStr, char *pStr, int iValue) |
Definition at line 2908 of file timeutil.cpp.
| static void BreakDownDMY | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2863 of file timeutil.cpp.
References PDCB_DAY_OF_MONTH, PDCB_MONTH, PDCB_YEAR, SplitLastTwoDigits(), and tag_pd_node::uCouldBe.
02864 { 02865 pNode->uCouldBe = PDCB_DAY_OF_MONTH; 02866 SplitLastTwoDigits(pNode, PDCB_YEAR); 02867 SplitLastTwoDigits(pNode, PDCB_MONTH); 02868 }
| static void BreakDownHMS | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2761 of file timeutil.cpp.
References tag_pd_node::nToken, PDCB_HMS_TIME, PDCB_HOUR_TIME, PDCB_HOUR_TIMEZONE, PDCB_MINUTE, PDCB_SECOND, SplitLastTwoDigits(), and tag_pd_node::uCouldBe.
02762 { 02763 if (pNode->uCouldBe & PDCB_HMS_TIME) 02764 { 02765 pNode->uCouldBe = PDCB_HOUR_TIME; 02766 } 02767 else 02768 { 02769 pNode->uCouldBe = PDCB_HOUR_TIMEZONE; 02770 } 02771 switch (pNode->nToken) 02772 { 02773 case 5: 02774 case 6: 02775 SplitLastTwoDigits(pNode, PDCB_SECOND); 02776 02777 case 3: 02778 case 4: 02779 SplitLastTwoDigits(pNode, PDCB_MINUTE); 02780 } 02781 }
| static void BreakDownMDY | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2834 of file timeutil.cpp.
References PDCB_DAY_OF_MONTH, PDCB_MONTH, PDCB_YEAR, SplitLastTwoDigits(), and tag_pd_node::uCouldBe.
02835 { 02836 pNode->uCouldBe = PDCB_MONTH; 02837 SplitLastTwoDigits(pNode, PDCB_YEAR); 02838 SplitLastTwoDigits(pNode, PDCB_DAY_OF_MONTH); 02839 }
| static void BreakDownYD | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2889 of file timeutil.cpp.
References PDCB_DAY_OF_YEAR, PDCB_YEAR, SplitLastThreeDigits(), and tag_pd_node::uCouldBe.
02890 { 02891 pNode->uCouldBe = PDCB_YEAR; 02892 SplitLastThreeDigits(pNode, PDCB_DAY_OF_YEAR); 02893 }
| static void BreakDownYMD | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2805 of file timeutil.cpp.
References PDCB_DAY_OF_MONTH, PDCB_MONTH, PDCB_YEAR, SplitLastTwoDigits(), and tag_pd_node::uCouldBe.
02806 { 02807 pNode->uCouldBe = PDCB_YEAR; 02808 SplitLastTwoDigits(pNode, PDCB_DAY_OF_MONTH); 02809 SplitLastTwoDigits(pNode, PDCB_MONTH); 02810 }
| static void ClassifyNumericToken | ( | PD_Node * | pNode | ) | [static] |
Definition at line 2939 of file timeutil.cpp.
References tag_pd_node::iToken, tag_pd_node::nToken, NumericSet, tag_pd_node::pToken, and tag_pd_node::uCouldBe.
Referenced by PD_ScanNextToken().
02940 { 02941 size_t nToken = pNode->nToken; 02942 char *pToken = pNode->pToken; 02943 int iToken = pNode->iToken; 02944 02945 unsigned int uCouldBe = InitialCouldBe[nToken-1]; 02946 02947 int i = 0; 02948 int mask = 0; 02949 while ((mask = NumericSet[i].mask) != 0) 02950 { 02951 if ( (mask & uCouldBe) 02952 && !(NumericSet[i].fnValid(nToken, pToken, iToken))) 02953 { 02954 uCouldBe &= ~mask; 02955 } 02956 i++; 02957 } 02958 pNode->uCouldBe = uCouldBe; 02959 }
| static bool ConvertAllFieldsToLinearTime | ( | CLinearTimeAbsolute & | lta, | |
| ALLFIELDS * | paf | |||
| ) | [static] |
Definition at line 3927 of file timeutil.cpp.
References i64FloorDivisionMod(), tag_AllFields::iDayOfMonth, tag_AllFields::iDayOfWeek, tag_AllFields::iDayOfYear, tag_AllFields::iHourTime, tag_AllFields::iMicrosecondTime, tag_AllFields::iMillisecondTime, tag_AllFields::iMinuteTime, tag_AllFields::iMinuteTimeZone, tag_AllFields::iMonthOfYear, tag_AllFields::iNanosecondTime, tag_AllFields::iSecondTime, tag_AllFields::iWeekOfYear, tag_AllFields::iYear, NOT_PRESENT, CLinearTimeAbsolute::Return100ns(), CLinearTimeAbsolute::ReturnFields(), CLinearTimeDelta::Set100ns(), CLinearTimeAbsolute::Set100ns(), CLinearTimeAbsolute::SetFields(), and CLinearTimeDelta::SetSeconds().
Referenced by ParseDate().
03928 { 03929 FIELDEDTIME ft; 03930 memset(&ft, 0, sizeof(ft)); 03931 03932 int iExtraDays = 0; 03933 if (paf->iYear == NOT_PRESENT) 03934 { 03935 return false; 03936 } 03937 ft.iYear = paf->iYear; 03938 03939 if (paf->iMonthOfYear != NOT_PRESENT && paf->iDayOfMonth != NOT_PRESENT) 03940 { 03941 ft.iMonth = paf->iMonthOfYear; 03942 ft.iDayOfMonth = paf->iDayOfMonth; 03943 } 03944 else if (paf->iDayOfYear != NOT_PRESENT) 03945 { 03946 iExtraDays = paf->iDayOfYear - 1; 03947 ft.iMonth = 1; 03948 ft.iDayOfMonth = 1; 03949 } 03950 else if (paf->iWeekOfYear != NOT_PRESENT && paf->iDayOfWeek != NOT_PRESENT) 03951 { 03952 // Remember that iYear in this case represents an ISO year, which 03953 // is not exactly the same thing as a Gregorian year. 03954 // 03955 FIELDEDTIME ftWD; 03956 memset(&ftWD, 0, sizeof(ftWD)); 03957 ftWD.iYear = paf->iYear - 1; 03958 ftWD.iMonth = 12; 03959 ftWD.iDayOfMonth = 27; 03960 if (!lta.SetFields(&ftWD)) 03961 { 03962 return false; 03963 } 03964 INT64 i64 = lta.Return100ns(); 03965 INT64 j64; 03966 i64FloorDivisionMod(i64+FACTOR_100NS_PER_DAY, FACTOR_100NS_PER_WEEK, &j64); 03967 i64 -= j64; 03968 03969 // i64 now corresponds to the Sunday that strickly preceeds before 03970 // December 28th, and the 28th is guaranteed to be in the previous 03971 // year so that the ISO and Gregorian Years are the same thing. 03972 // 03973 i64 += FACTOR_100NS_PER_WEEK*paf->iWeekOfYear; 03974 i64 += FACTOR_100NS_PER_DAY*paf->iDayOfWeek; 03975 lta.Set100ns(i64); 03976 lta.ReturnFields(&ft); 03977 03978 // Validate that this week actually has a week 53. 03979 // 03980 if (paf->iWeekOfYear == 53) 03981 { 03982 int iDOW_ISO = (ft.iDayOfWeek == 0) ? 7 : ft.iDayOfWeek; 03983 int j = ft.iDayOfMonth - iDOW_ISO; 03984 if (ft.iMonth == 12) 03985 { 03986 if (28 <= j) 03987 { 03988 return false; 03989 } 03990 } 03991 else // if (ft.iMonth == 1) 03992 { 03993 if (-3 <= j) 03994 { 03995 return false; 03996 } 03997 } 03998 } 03999 } 04000 else 04001 { 04002 // Under-specified. 04003 // 04004 return false; 04005 } 04006 04007 if (paf->iHourTime != NOT_PRESENT) 04008 { 04009 ft.iHour = paf->iHourTime; 04010 if (paf->iMinuteTime != NOT_PRESENT) 04011 { 04012 ft.iMinute = paf->iMinuteTime; 04013 if (paf->iSecondTime != NOT_PRESENT) 04014 { 04015 ft.iSecond = paf->iSecondTime; 04016 if (paf->iMillisecondTime != NOT_PRESENT) 04017 { 04018 ft.iMillisecond = paf->iMillisecondTime; 04019 ft.iMicrosecond = paf->iMicrosecondTime; 04020 ft.iNanosecond = paf->iNanosecondTime; 04021 } 04022 } 04023 } 04024 } 04025 04026 if (lta.SetFields(&ft)) 04027 { 04028 CLinearTimeDelta ltd; 04029 if (paf->iMinuteTimeZone != NOT_PRESENT) 04030 { 04031 ltd.SetSeconds(60 * paf->iMinuteTimeZone); 04032 lta -= ltd; 04033 } 04034 if (iExtraDays) 04035 { 04036 ltd.Set100ns(FACTOR_100NS_PER_DAY); 04037 lta += ltd * iExtraDays; 04038 } 04039 return true; 04040 } 04041 return false; 04042 }
| static void ConvertToSecondsString | ( | char * | buffer, | |
| INT64 | n64, | |||
| int | nFracDigits | |||
| ) | [static] |
Definition at line 621 of file timeutil.cpp.
References i64FloorDivisionMod(), and mux_i64toa().
Referenced by CLinearTimeAbsolute::ReturnSecondsString(), and CLinearTimeDelta::ReturnSecondsString().
00622 { 00623 INT64 Leftover; 00624 INT64 lt = i64FloorDivisionMod(n64, FACTOR_100NS_PER_SECOND, &Leftover); 00625 00626 size_t n = mux_i64toa(lt, buffer); 00627 if (Leftover == 0) 00628 { 00629 return; 00630 } 00631 00632 // Sanitize Precision Request. 00633 // 00634 const int maxFracDigits = 7; 00635 const int minFracDigits = 0; 00636 if (nFracDigits < minFracDigits) 00637 { 00638 nFracDigits = minFracDigits; 00639 } 00640 else if (maxFracDigits < nFracDigits) 00641 { 00642 nFracDigits = maxFracDigits; 00643 } 00644