Changeset 72140 in vbox for trunk/src/VBox/Runtime/common/time
- Timestamp:
- May 7, 2018 2:21:31 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 122537
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/time/time.cpp
r72094 r72140 237 237 */ 238 238 239 /********************************************************************************************************************************* 240 * Internal Functions * 241 *********************************************************************************************************************************/ 242 static PRTTIME rtTimeConvertToZulu(PRTTIME pTime); 243 239 244 240 245 /** … … 390 395 * The fields u8Month, u8WeekDay and u8MonthDay are not used, 391 396 * and all the other fields are expected to be within their 392 * bounds. Use RTTimeNormalize() to calculate u16YearDay and393 * normalize the ranges of the fields.397 * bounds. Use RTTimeNormalize() or RTTimeLocalNormalize() to 398 * calculate u16YearDay and normalize the ranges of the fields. 394 399 */ 395 400 RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime) … … 412 417 AssertMsgReturn(pTime->i32Year <= RTTIME_MAX_YEAR && pTime->i32Year >= RTTIME_MIN_YEAR, ("%RI32\n", pTime->i32Year), NULL); 413 418 419 RTTIME TimeUTC; 420 if ((pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) != RTTIME_FLAGS_TYPE_UTC) 421 { 422 TimeUTC = *pTime; 423 pTime = rtTimeConvertToZulu(&TimeUTC); 424 } 425 414 426 /* 415 427 * Do the conversion to nanoseconds. … … 437 449 /** 438 450 * Internal worker for RTTimeNormalize and RTTimeLocalNormalize. 439 * It doesn't adjust the UCT offset but leaves that for RTTimeLocalNormalize.440 451 */ 441 452 static PRTTIME rtTimeNormalizeInternal(PRTTIME pTime) … … 536 547 : &g_aiDayOfYear[0]; 537 548 pTime->u8Month = 1; 538 while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month] )549 while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month] - 1) 539 550 pTime->u8Month++; 540 551 Assert(pTime->u8Month >= 1 && pTime->u8Month <= 12); … … 696 707 697 708 /** 709 * Normalizes the fields of a time structure, assuming local time. 710 * 711 * It is possible to calculate year-day from month/day and vice 712 * versa. If you adjust any of these, make sure to zero the 713 * other so you make it clear which of the fields to use. If 714 * it's ambiguous, the year-day field is used (and you get 715 * assertions in debug builds). 716 * 717 * All the time fields and the year-day or month/day fields will 718 * be adjusted for overflows. (Since all fields are unsigned, there 719 * is no underflows.) It is possible to exploit this for simple 720 * date math, though the recommended way of doing that to implode 721 * the time into a timespec and do the math on that. 722 * 723 * @returns pTime on success. 724 * @returns NULL if the data is invalid. 725 * 726 * @param pTime The time structure to normalize. 727 * 728 * @remarks This function doesn't work with UTC time, only with local time. 729 */ 730 RTDECL(PRTTIME) RTTimeLocalNormalize(PRTTIME pTime) 731 { 732 /* 733 * Validate that we've got the minimum of stuff handy. 734 */ 735 AssertReturn(VALID_PTR(pTime), NULL); 736 AssertMsgReturn(!(pTime->fFlags & ~RTTIME_FLAGS_MASK), ("%#x\n", pTime->fFlags), NULL); 737 AssertMsgReturn((pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) != RTTIME_FLAGS_TYPE_UTC, ("Use RTTimeNormalize!\n"), NULL); 738 739 pTime = rtTimeNormalizeInternal(pTime); 740 if (pTime) 741 pTime->fFlags |= RTTIME_FLAGS_TYPE_LOCAL; 742 return pTime; 743 } 744 RT_EXPORT_SYMBOL(RTTimeLocalNormalize); 745 746 747 /** 698 748 * Converts a time spec to a ISO date string. 699 749 * … … 967 1017 if (pTime->u16YearDay > 1) 968 1018 { 969 pTime->u16YearDay -= 0;1019 pTime->u16YearDay -= 1; 970 1020 pTime->u8Month = 0; 971 1021 pTime->u8MonthDay = 0; … … 977 1027 pTime->u8MonthDay = 31; 978 1028 pTime->u8Month = 12; 1029 pTime->fFlags &= ~(RTTIME_FLAGS_COMMON_YEAR | RTTIME_FLAGS_LEAP_YEAR); 979 1030 } 980 1031 return rtTimeNormalizeInternal(pTime); … … 1025 1076 * 1026 1077 * @returns pTime. 1027 * @param pTime What to conver s(in/out).1078 * @param pTime What to convert (in/out). 1028 1079 */ 1029 1080 static PRTTIME rtTimeConvertToZulu(PRTTIME pTime) … … 1037 1088 pTime->fFlags |= RTTIME_FLAGS_TYPE_UTC; 1038 1089 if (offUTC != 0) 1039 rtTimeAddMinutes(pTime, offUTC);1090 rtTimeAddMinutes(pTime, -offUTC); 1040 1091 } 1041 1092 return pTime; 1093 } 1094 1095 1096 /** 1097 * Converts a time structure to UTC, relying on UTC offset information if it contains local time. 1098 * 1099 * @returns pTime on success. 1100 * @returns NULL if the data is invalid. 1101 * @param pTime The time structure to convert. 1102 */ 1103 PRTTIME RTTimeConvertToZulu(PRTTIME pTime) 1104 { 1105 /* 1106 * Validate that we've got the minimum of stuff handy. 1107 */ 1108 AssertReturn(VALID_PTR(pTime), NULL); 1109 AssertMsgReturn(!(pTime->fFlags & ~RTTIME_FLAGS_MASK), ("%#x\n", pTime->fFlags), NULL); 1110 1111 return rtTimeConvertToZulu(rtTimeNormalizeInternal(pTime)); 1042 1112 } 1043 1113
Note:
See TracChangeset
for help on using the changeset viewer.