5 #include "src/dateparser.h" 7 #include "src/char-predicates-inl.h" 8 #include "src/objects-inl.h" 13 bool DateParser::DayComposer::Write(FixedArray output) {
14 if (index_ < 1)
return false;
16 while (index_ < kSize) {
24 if (named_month_ ==
kNone) {
25 if (is_iso_date_ || (index_ == 3 && !IsDay(comp_[0]))) {
34 if (index_ == 3) year = comp_[2];
41 }
else if (!IsDay(comp_[0])) {
53 if (Between(year, 0, 49)) year += 2000;
54 else if (Between(year, 50, 99)) year += 1900;
57 if (!Smi::IsValid(year) || !IsMonth(month) || !IsDay(day))
return false;
59 output->set(YEAR, Smi::FromInt(year));
60 output->set(MONTH, Smi::FromInt(month - 1));
61 output->set(DAY, Smi::FromInt(day));
65 bool DateParser::TimeComposer::Write(FixedArray output) {
67 while (index_ < kSize) {
72 int& minute = comp_[1];
73 int& second = comp_[2];
74 int& millisecond = comp_[3];
76 if (hour_offset_ !=
kNone) {
77 if (!IsHour12(hour))
return false;
82 if (!IsHour(hour) || !IsMinute(minute) ||
83 !IsSecond(second) || !IsMillisecond(millisecond)) {
85 if (hour != 24 || minute != 0 || second != 0 || millisecond != 0) {
90 output->set(HOUR, Smi::FromInt(hour));
91 output->set(MINUTE, Smi::FromInt(minute));
92 output->set(SECOND, Smi::FromInt(second));
93 output->set(MILLISECOND, Smi::FromInt(millisecond));
97 bool DateParser::TimeZoneComposer::Write(FixedArray output) {
99 if (hour_ ==
kNone) hour_ = 0;
100 if (minute_ ==
kNone) minute_ = 0;
103 unsigned total_seconds_unsigned = hour_ * 3600U + minute_ * 60U;
104 if (total_seconds_unsigned > Smi::kMaxValue)
return false;
105 int total_seconds =
static_cast<int>(total_seconds_unsigned);
107 total_seconds = -total_seconds;
109 DCHECK(Smi::IsValid(total_seconds));
110 output->set(UTC_OFFSET, Smi::FromInt(total_seconds));
112 output->set_null(UTC_OFFSET);
117 const int8_t DateParser::KeywordTable::
118 array[][DateParser::KeywordTable::kEntrySize] = {
119 {
'j',
'a',
'n', DateParser::MONTH_NAME, 1},
120 {
'f',
'e',
'b', DateParser::MONTH_NAME, 2},
121 {
'm',
'a',
'r', DateParser::MONTH_NAME, 3},
122 {
'a',
'p',
'r', DateParser::MONTH_NAME, 4},
123 {
'm',
'a',
'y', DateParser::MONTH_NAME, 5},
124 {
'j',
'u',
'n', DateParser::MONTH_NAME, 6},
125 {
'j',
'u',
'l', DateParser::MONTH_NAME, 7},
126 {
'a',
'u',
'g', DateParser::MONTH_NAME, 8},
127 {
's',
'e',
'p', DateParser::MONTH_NAME, 9},
128 {
'o',
'c',
't', DateParser::MONTH_NAME, 10},
129 {
'n',
'o',
'v', DateParser::MONTH_NAME, 11},
130 {
'd',
'e',
'c', DateParser::MONTH_NAME, 12},
131 {
'a',
'm',
'\0', DateParser::AM_PM, 0},
132 {
'p',
'm',
'\0', DateParser::AM_PM, 12},
133 {
'u',
't',
'\0', DateParser::TIME_ZONE_NAME, 0},
134 {
'u',
't',
'c', DateParser::TIME_ZONE_NAME, 0},
135 {
'z',
'\0',
'\0', DateParser::TIME_ZONE_NAME, 0},
136 {
'g',
'm',
't', DateParser::TIME_ZONE_NAME, 0},
137 {
'c',
'd',
't', DateParser::TIME_ZONE_NAME, -5},
138 {
'c',
's',
't', DateParser::TIME_ZONE_NAME, -6},
139 {
'e',
'd',
't', DateParser::TIME_ZONE_NAME, -4},
140 {
'e',
's',
't', DateParser::TIME_ZONE_NAME, -5},
141 {
'm',
'd',
't', DateParser::TIME_ZONE_NAME, -6},
142 {
'm',
's',
't', DateParser::TIME_ZONE_NAME, -7},
143 {
'p',
'd',
't', DateParser::TIME_ZONE_NAME, -7},
144 {
'p',
's',
't', DateParser::TIME_ZONE_NAME, -8},
145 {
't',
'\0',
'\0', DateParser::TIME_SEPARATOR, 0},
146 {
'\0',
'\0',
'\0', DateParser::INVALID, 0},
151 int DateParser::KeywordTable::Lookup(
const uint32_t* pre,
int len) {
153 for (
i = 0; array[
i][kTypeOffset] != INVALID;
i++) {
155 while (j < kPrefixLength &&
156 pre[j] == static_cast<uint32_t>(array[
i][j])) {
161 if (j == kPrefixLength &&
162 (len <= kPrefixLength || array[
i][kTypeOffset] == MONTH_NAME)) {
170 int DateParser::ReadMilliseconds(DateToken token) {
175 int number = token.number();
176 int length = token.length();
182 }
else if (length == 2) {
185 }
else if (length > 3) {
186 if (length > kMaxSignificantDigits) length = kMaxSignificantDigits;
191 DCHECK_LE(factor, 100000000);
194 }
while (length > 3);