Lines Matching defs:pTime

254  * @returns pTime.
255 * @param pTime Where to store the exploded time.
258 RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec)
267 AssertMsg(VALID_PTR(pTime), ("%p\n", pTime));
268 AssertMsg(VALID_PTR(pTimeSpec), ("%p\n", pTime));
273 pTime->fFlags = RTTIME_FLAGS_TYPE_UTC;
282 pTime->u32Nanosecond = i32Rem;
292 pTime->u8Second = i32Rem;
303 pTime->u8Minute = i32Rem;
313 pTime->u8Hour = i32Rem;
316 pTime->u8WeekDay = ((int)(i32Div % 7) + 3 + 7) % 7;
329 pTime->i32Year = iYear + OFF_YEAR_IDX_0_YEAR;
331 pTime->u16YearDay = i32Div + 1;
337 if (rtTimeIsLeapYear(pTime->i32Year))
339 pTime->fFlags |= RTTIME_FLAGS_LEAP_YEAR;
344 pTime->fFlags |= RTTIME_FLAGS_COMMON_YEAR;
351 pTime->u8Month = iMonth + 1;
353 pTime->u8MonthDay = i32Div + 1;
356 pTime->offUTC = 0;
358 return pTime;
366 * @returns pTime on success.
367 * @returns NULL if the pTime data is invalid.
369 * If pTime specifies a time which outside the range, maximum or
371 * @param pTime Pointer to the exploded time to implode.
377 RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime)
387 AssertReturn(VALID_PTR(pTime), NULL);
388 AssertReturn(pTime->u32Nanosecond < 1000000000, NULL);
389 AssertReturn(pTime->u8Second < 60, NULL);
390 AssertReturn(pTime->u8Minute < 60, NULL);
391 AssertReturn(pTime->u8Hour < 24, NULL);
392 AssertReturn(pTime->u16YearDay >= 1, NULL);
393 AssertReturn(pTime->u16YearDay <= (rtTimeIsLeapYear(pTime->i32Year) ? 366 : 365), NULL);
394 AssertMsgReturn(pTime->i32Year <= RTTIME_MAX_YEAR && pTime->i32Year >= RTTIME_MIN_YEAR, ("%RI32\n", pTime->i32Year), NULL);
399 i32Days = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
400 + pTime->u16YearDay - 1;
403 u32Secs = pTime->u8Second
404 + pTime->u8Minute * 60
405 + pTime->u8Hour * 3600;
406 i64Nanos = (uint64_t)pTime->u32Nanosecond
423 static PRTTIME rtTimeNormalizeInternal(PRTTIME pTime)
433 fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
434 if (!pTime->u16YearDay)
439 AssertMsgReturn( pTime->u8Month
440 && pTime->u8MonthDay,
441 ("date=%d-%d-%d\n", pTime->i32Year, pTime->u8Month, pTime->u8MonthDay),
443 while (pTime->u8Month > 12)
445 pTime->u8Month -= 12;
446 pTime->i32Year++;
447 fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
448 pTime->fFlags &= ~(RTTIME_FLAGS_COMMON_YEAR | RTTIME_FLAGS_LEAP_YEAR);
454 ? g_acDaysInMonthsLeap[pTime->u8Month - 1]
455 : g_acDaysInMonths[pTime->u8Month - 1];
456 if (pTime->u8MonthDay <= cDaysInMonth)
458 pTime->u8MonthDay -= cDaysInMonth;
459 if (pTime->u8Month != 12)
460 pTime->u8Month++;
463 pTime->u8Month = 1;
464 pTime->i32Year++;
465 fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
466 pTime->fFlags &= ~(RTTIME_FLAGS_COMMON_YEAR | RTTIME_FLAGS_LEAP_YEAR);
470 pTime->u16YearDay = pTime->u8MonthDay - 1
472 ? g_aiDayOfYearLeap[pTime->u8Month - 1]
473 : g_aiDayOfYear[pTime->u8Month - 1]);
482 if ( pTime->u8Month
483 && pTime->u8MonthDay)
490 AssertBreak(pTime->u8Month <= 12);
491 AssertBreak(pTime->u8MonthDay <= (fLeapYear
492 ? g_acDaysInMonthsLeap[pTime->u8Month - 1]
493 : g_acDaysInMonths[pTime->u8Month - 1]));
494 u16YearDay = pTime->u8MonthDay - 1
496 ? g_aiDayOfYearLeap[pTime->u8Month - 1]
497 : g_aiDayOfYear[pTime->u8Month - 1]);
498 AssertBreak(u16YearDay == pTime->u16YearDay);
507 while (pTime->u16YearDay > (fLeapYear ? 366 : 365))
509 pTime->u16YearDay -= fLeapYear ? 366 : 365;
510 pTime->i32Year++;
511 fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
512 pTime->fFlags &= ~(RTTIME_FLAGS_COMMON_YEAR | RTTIME_FLAGS_LEAP_YEAR);
519 pTime->u8Month = 1;
520 while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month])
521 pTime->u8Month++;
522 Assert(pTime->u8Month >= 1 && pTime->u8Month <= 12);
523 pTime->u8MonthDay = pTime->u16YearDay - paiDayOfYear[pTime->u8Month - 1] + 1;
531 uSecond = pTime->u8Second;
532 uMinute = pTime->u8Minute;
533 uHour = pTime->u8Hour;
535 while (pTime->u32Nanosecond >= 1000000000)
537 pTime->u32Nanosecond -= 1000000000;
558 if (pTime->u16YearDay + 1 != (fLeapYear ? g_aiDayOfYearLeap[pTime->u8Month] : g_aiDayOfYear[pTime->u8Month]))
560 pTime->u16YearDay++;
561 pTime->u8MonthDay++;
563 else if (pTime->u8Month != 12)
565 pTime->u16YearDay++;
566 pTime->u8Month++;
567 pTime->u8MonthDay = 1;
571 pTime->i32Year++;
572 fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
573 pTime->fFlags &= ~(RTTIME_FLAGS_COMMON_YEAR | RTTIME_FLAGS_LEAP_YEAR);
574 pTime->u16YearDay = 1;
575 pTime->u8Month = 1;
576 pTime->u8MonthDay = 1;
580 pTime->u8Second = uSecond;
581 pTime->u8Minute = uMinute;
582 pTime->u8Hour = uHour;
590 Assert(!(pTime->fFlags & RTTIME_FLAGS_COMMON_YEAR));
591 pTime->fFlags &= ~RTTIME_FLAGS_COMMON_YEAR;
592 pTime->fFlags |= RTTIME_FLAGS_LEAP_YEAR;
596 Assert(!(pTime->fFlags & RTTIME_FLAGS_LEAP_YEAR));
597 pTime->fFlags &= ~RTTIME_FLAGS_LEAP_YEAR;
598 pTime->fFlags |= RTTIME_FLAGS_COMMON_YEAR;
610 if ( pTime->i32Year >= OFF_YEAR_IDX_0_YEAR
611 && pTime->i32Year < OFF_YEAR_IDX_0_YEAR + (int32_t)RT_ELEMENTS(g_aoffYear))
613 int32_t offDays = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
614 + pTime->u16YearDay -1;
615 pTime->u8WeekDay = ((offDays % 7) + 3 + 7) % 7;
619 int32_t i32Year = pTime->i32Year;
622 uint64_t offDays = pTime->u16YearDay - 1;
625 pTime->u8WeekDay = (uint8_t)((offDays + 3) % 7);
629 int64_t offDays = (fLeapYear ? -366 - 1 : -365 - 1) + pTime->u16YearDay;
632 pTime->u8WeekDay = ((int)(offDays % 7) + 3 + 7) % 7;
635 return pTime;
654 * @returns pTime on success.
657 * @param pTime The time structure to normalize.
661 RTDECL(PRTTIME) RTTimeNormalize(PRTTIME pTime)
666 AssertReturn(VALID_PTR(pTime), NULL);
667 AssertMsgReturn(!(pTime->fFlags & ~RTTIME_FLAGS_MASK), ("%#x\n", pTime->fFlags), NULL);
668 AssertMsgReturn((pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) != RTTIME_FLAGS_TYPE_LOCAL, ("Use RTTimeLocalNormalize!\n"), NULL);
669 AssertMsgReturn(pTime->offUTC == 0, ("%d; Use RTTimeLocalNormalize!\n", pTime->offUTC), NULL);
671 pTime = rtTimeNormalizeInternal(pTime);
672 if (pTime)
673 pTime->fFlags |= RTTIME_FLAGS_TYPE_UTC;
674 return pTime;
684 * @param pTime The time. Caller should've normalized this.
688 RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb)
693 if ( (pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL
694 && pTime->offUTC)
696 int32_t offUTCHour = pTime->offUTC / 60;
697 int32_t offUTCMinute = pTime->offUTC % 60;
699 Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
700 if (pTime->offUTC >= 0)
710 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
711 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
720 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
721 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond);
736 * @param pTime The time spec.
740 RTDECL(char *) RTTimeSpecToString(PCRTTIMESPEC pTime, char *psz, size_t cb)
743 return RTTimeToString(RTTimeExplode(&Time, pTime), psz, cb);
755 * @retval pTime on success,
757 * @param pTime Where to store the time on success.
760 RTDECL(PRTTIME) RTTimeFromString(PRTTIME pTime, const char *pszString)
769 pTime->fFlags = RTTIME_FLAGS_TYPE_LOCAL;
770 pTime->offUTC = 0;
777 int rc = RTStrToInt32Ex(pszString, (char **)&pszString, 10, &pTime->i32Year);
781 bool const fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
783 pTime->fFlags |= RTTIME_FLAGS_LEAP_YEAR;
789 rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Month);
792 if (pTime->u8Month == 0 || pTime->u8Month > 12)
798 rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8MonthDay);
802 ? g_acDaysInMonthsLeap[pTime->u8Month - 1]
803 : g_acDaysInMonthsLeap[pTime->u8Month - 1];
804 if (pTime->u8MonthDay == 0 || pTime->u8MonthDay > cDaysInMonth)
808 pTime->u16YearDay = pTime->u8MonthDay - 1
810 ? g_aiDayOfYearLeap[pTime->u8Month - 1]
811 : g_aiDayOfYear[pTime->u8Month - 1]);
820 rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Hour);
823 if (pTime->u8Hour > 23)
829 rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Minute);
832 if (pTime->u8Minute > 59)
838 rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Minute);
841 if (pTime->u8Second > 59)
847 rc = RTStrToUInt32Ex(pszString + 1, (char **)&pszString, 10, &pTime->u32Nanosecond);
850 if (pTime->u32Nanosecond >= 1000000000)
854 pTime->u32Nanosecond = 0;
862 pTime->fFlags &= ~RTTIME_FLAGS_TYPE_MASK;
863 pTime->fFlags |= ~RTTIME_FLAGS_TYPE_UTC;
864 pTime->offUTC = 0;
869 rc = RTStrToInt32Ex(pszString, (char **)&pszString, 10, &pTime->offUTC);
883 return pTime;
894 * @retval pTime on success,
896 * @param pTime The time spec.
899 RTDECL(PRTTIMESPEC) RTTimeSpecFromString(PRTTIMESPEC pTime, const char *pszString)
903 return RTTimeImplode(pTime, &Time);