29 31, 31, 30, 31, 30, 31};
35 Intl::CreateTimeZoneCache()
37 base::OS::CreateTimezoneCache()
83 if (new_day >= 1 && new_day <= 28) {
111 int yd3 =
days / 365;
115 bool is_leap = (!yd1 || yd2) && !yd3;
120 DCHECK(is_leap == ((*year % 4 == 0) && (*year % 100 || (*year % 400 == 0))));
127 if (
days >= 31 + 28 + (is_leap ? 1 : 0)) {
128 days -= 31 + 28 + (is_leap ? 1 : 0);
130 for (
int i = 2;
i < 12;
i++) {
145 *day =
days - 31 + 1;
157 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
158 181, 212, 243, 273, 304, 334};
159 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
160 182, 213, 244, 274, 305, 335};
180 static const int year_delta = 399999;
181 static const int base_day =
182 365 * (1970 + year_delta) + (1970 + year_delta) / 4 -
183 (1970 + year_delta) / 100 + (1970 + year_delta) / 400;
185 int year1 = year + year_delta;
187 365 * year1 + year1 / 4 - year1 / 100 + year1 / 400 - base_day;
189 if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
190 return day_from_year + day_from_month[month];
192 return day_from_year + day_from_month_leap[month];
196 int* weekday,
int*
hour,
int* min,
int* sec,
202 *
hour = time_in_day_ms / (60 * 60 * 1000);
203 *min = (time_in_day_ms / (60 * 1000)) % 60;
204 *sec = (time_in_day_ms / 1000) % 60;
205 *ms = time_in_day_ms % 1000;
212#ifdef V8_INTL_SUPPORT
262 const int kMsPerHour = 3600 * 1000;
263 time_ms -= (
offset + kMsPerHour);
266#ifdef V8_INTL_SUPPORT
270 return static_cast<int>(
offset);
276 time_ms <= after_->end_ms) {
296#ifdef ENABLE_SLOW_DCHECKS
297 int known_correct_result = 0;
337 if (time_ms <= before_->end_ms) {
363 int64_t new_after_start_ms =
387 for (
int i = 4;
i >= 0; --
i) {
389 int64_t middle_sec = (
i == 0) ? time_ms :
before_->
end_ms + delta / 2;
393 if (time_ms <= before_->end_ms) {
428 if (
cache_[
i].start_ms <= time_ms) {
432 }
else if (time_ms <
cache_[
i].end_ms) {
441 if (before ==
nullptr) {
445 if (after ==
nullptr) {
457 before->end_ms < after->start_ms);
466 if (&
cache_[
i] == skip)
continue;
478const double kMinYear = -1000000.0;
479const double kMaxYear = -kMinYear;
480const double kMinMonth = -10000000.0;
481const double kMaxMonth = -kMinMonth;
483const double kMsPerDay = 86400000.0;
485const double kMsPerSecond = 1000.0;
486const double kMsPerMinute = 60000.0;
487const double kMsPerHour = 3600000.0;
492 if (std::isfinite(day) && std::isfinite(time)) {
493 return time + day * kMsPerDay;
495 return std::numeric_limits<double>::quiet_NaN();
499 if ((kMinYear <= year && year <= kMaxYear) &&
500 (kMinMonth <= month && month <= kMaxMonth) && std::isfinite(
date)) {
520 static const int kYearDelta = 399999;
521 static const int kBaseDay =
522 365 * (1970 + kYearDelta) + (1970 + kYearDelta) / 4 -
523 (1970 + kYearDelta) / 100 + (1970 + kYearDelta) / 400;
524 int day_from_year = 365 * (
y + kYearDelta) + (
y + kYearDelta) / 4 -
525 (
y + kYearDelta) / 100 + (
y + kYearDelta) / 400 -
527 if ((
y % 4 != 0) || (
y % 100 == 0 &&
y % 400 != 0)) {
528 static const int kDayFromMonth[] = {0, 31, 59, 90, 120, 151,
529 181, 212, 243, 273, 304, 334};
530 day_from_year += kDayFromMonth[
m];
532 static const int kDayFromMonth[] = {0, 31, 60, 91, 121, 152,
533 182, 213, 244, 274, 305, 335};
534 day_from_year += kDayFromMonth[
m];
538 return std::numeric_limits<double>::quiet_NaN();
542 if (std::isfinite(
hour) && std::isfinite(min) && std::isfinite(sec) &&
548 return h * kMsPerHour +
m * kMsPerMinute + s * kMsPerSecond + milli;
550 return std::numeric_limits<double>::quiet_NaN();
555const char* kShortWeekDays[] = {
"Sun",
"Mon",
"Tue",
"Wed",
556 "Thu",
"Fri",
"Sat"};
557const char* kShortMonths[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
558 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
560template <
class... Args>
563 SmallStringOptimizedAllocator<DateBuffer::kInlineSize> allocator(&buffer);
564 StringStream sstream(&allocator);
565 sstream.Add(format,
args...);
566 buffer.resize(sstream.length());
574 if (std::isnan(time_val)) {
575 return FormatDate(
"Invalid Date");
577 int64_t time_ms =
static_cast<int64_t
>(time_val);
581 : date_cache->
ToLocal(time_ms);
582 int year, month, day, weekday,
hour, min, sec, ms;
586 int timezone_hour = std::abs(timezone_offset) / 60;
587 int timezone_min = std::abs(timezone_offset) % 60;
588 const char* local_timezone = date_cache->
LocalTimezone(time_ms);
591 return FormatDate((year < 0) ?
"%s %s %02d %05d" :
"%s %s %02d %04d",
592 kShortWeekDays[weekday], kShortMonths[month], day,
595 return FormatDate(
"%02d:%02d:%02d GMT%c%02d%02d (%s)",
hour, min, sec,
596 (timezone_offset < 0) ?
'-' :
'+', timezone_hour,
597 timezone_min, local_timezone);
600 (year < 0) ?
"%s %s %02d %05d %02d:%02d:%02d GMT%c%02d%02d (%s)"
601 :
"%s %s %02d %04d %02d:%02d:%02d GMT%c%02d%02d (%s)",
602 kShortWeekDays[weekday], kShortMonths[month], day, year,
hour, min,
603 sec, (timezone_offset < 0) ?
'-' :
'+', timezone_hour, timezone_min,
606 return FormatDate((year < 0) ?
"%s, %02d %s %05d %02d:%02d:%02d GMT"
607 :
"%s, %02d %s %04d %02d:%02d:%02d GMT",
608 kShortWeekDays[weekday], day, kShortMonths[month], year,
611 if (year >= 0 && year <= 9999) {
612 return FormatDate(
"%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year,
613 month + 1, day,
hour, min, sec, ms);
614 }
else if (year < 0) {
615 return FormatDate(
"-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year,
616 month + 1, day,
hour, min, sec, ms);
618 return FormatDate(
"+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year,
619 month + 1, day,
hour, min, sec, ms);
637 if (!
result)
return std::numeric_limits<double>::quiet_NaN();
647 date = isolate->date_cache()->ToUTC(
static_cast<int64_t
>(
date));
649 return std::numeric_limits<double>::quiet_NaN();
655 return std::numeric_limits<double>::quiet_NaN();
#define SLOW_DCHECK(condition)
virtual double LocalTimeOffset(double time_ms, bool is_utc)=0
virtual void Clear(TimeZoneDetection time_zone_detection)=0
int DaysFromYearMonth(int year, int month)
void BreakDownTime(int64_t time_ms, int *year, int *month, int *day, int *weekday, int *hour, int *min, int *sec, int *ms)
static int TimeInDay(int64_t time_ms, int days)
bool InvalidSegment(CacheItem *segment)
int DaylightSavingsOffsetInMs(int64_t time_ms)
int LocalOffsetInMs(int64_t time, bool is_utc)
void YearMonthDayFromDays(int days, int *year, int *month, int *day)
void ExtendTheAfterSegment(int64_t time_sec, int offset_ms)
static const int kDefaultTimeZoneOffsetDeltaInMs
static const int kInvalidStamp
const char * LocalTimezone(int64_t time_ms)
base::TimezoneCache * tz_cache_
int64_t ToLocal(int64_t time_ms)
CacheItem * LeastRecentlyUsedCacheItem(CacheItem *skip)
static bool TryTimeClip(double *time)
CacheItem cache_[kCacheSize]
static int DaysFromTime(int64_t time_ms)
static const int kInvalidLocalOffsetInMs
void ClearSegment(CacheItem *segment)
virtual int GetLocalOffsetFromOS(int64_t time_ms, bool is_utc)
void ResetDateCache(base::TimezoneCache::TimeZoneDetection time_zone_detection)
void ProbeCache(int64_t time_ms)
const char * dst_tz_name_
int TimezoneOffset(int64_t time_ms)
static const int kCacheSize
static const int64_t kMaxTimeBeforeUTCInMs
static bool Parse(Isolate *isolate, base::Vector< Char > str, double *output)
static constexpr Tagged< Smi > FromInt(int value)
static constexpr Tagged< Smi > zero()
static constexpr int kMaxValue
base::Vector< const uint8_t > ToOneByteVector() const
base::Vector< const base::uc16 > ToUC16Vector() const
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
V8_INLINE constexpr int32_t value() const
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
static const int kDaysOffset
static const char kDaysInMonths[]
double MakeDate(double day, double time)
static const int kDaysIn4Years
double DoubleToInteger(double x)
static const int kDaysIn100Years
DateBuffer ToDateString(double time_val, DateCache *date_cache, ToDateStringMode mode)
base::SmallVector< char, 128 > DateBuffer
static const int kDays1970to2000
double MakeDay(double year, double month, double date)
double MakeTime(double hour, double min, double sec, double ms)
V8_EXPORT_PRIVATE FlagValues v8_flags
static const int kYearsOffset
static constexpr Address kNullAddress
double ParseDateTimeString(Isolate *isolate, DirectHandle< String > str)
static const int kDaysIn400Years
#define DCHECK_LE(v1, v2)
#define DCHECK_NOT_NULL(val)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)