| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "dateparser.h" | 30 #include "dateparser.h" |
| 31 | 31 |
| 32 namespace v8 { | 32 namespace v8 { |
| 33 namespace internal { | 33 namespace internal { |
| 34 | 34 |
| 35 bool DateParser::DayComposer::Write(FixedArray* output) { | 35 bool DateParser::DayComposer::Write(FixedArray* output) { |
| 36 // Set year to 0 by default. |
| 37 if (index_ < 1) { |
| 38 comp_[index_++] = 1; |
| 39 } |
| 40 |
| 41 // Day and month defaults to 1. |
| 42 while (index_ < kSize) { |
| 43 comp_[index_++] = 1; |
| 44 } |
| 45 |
| 36 int year = 0; // Default year is 0 (=> 2000) for KJS compatibility. | 46 int year = 0; // Default year is 0 (=> 2000) for KJS compatibility. |
| 37 int month = kNone; | 47 int month = kNone; |
| 38 int day = kNone; | 48 int day = kNone; |
| 39 | 49 |
| 40 if (named_month_ == kNone) { | 50 if (named_month_ == kNone) { |
| 41 if (index_ < 2) return false; | 51 if (index_ < 2) return false; |
| 42 if (index_ == 3 && !IsDay(comp_[0])) { | 52 if (index_ == 3 && !IsDay(comp_[0])) { |
| 43 // YMD | 53 // YMD |
| 44 year = comp_[0]; | 54 year = comp_[0]; |
| 45 month = comp_[1]; | 55 month = comp_[1]; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 91 |
| 82 bool DateParser::TimeComposer::Write(FixedArray* output) { | 92 bool DateParser::TimeComposer::Write(FixedArray* output) { |
| 83 // All time slots default to 0 | 93 // All time slots default to 0 |
| 84 while (index_ < kSize) { | 94 while (index_ < kSize) { |
| 85 comp_[index_++] = 0; | 95 comp_[index_++] = 0; |
| 86 } | 96 } |
| 87 | 97 |
| 88 int& hour = comp_[0]; | 98 int& hour = comp_[0]; |
| 89 int& minute = comp_[1]; | 99 int& minute = comp_[1]; |
| 90 int& second = comp_[2]; | 100 int& second = comp_[2]; |
| 101 int& millisecond = comp_[3]; |
| 91 | 102 |
| 92 if (hour_offset_ != kNone) { | 103 if (hour_offset_ != kNone) { |
| 93 if (!IsHour12(hour)) return false; | 104 if (!IsHour12(hour)) return false; |
| 94 hour %= 12; | 105 hour %= 12; |
| 95 hour += hour_offset_; | 106 hour += hour_offset_; |
| 96 } | 107 } |
| 97 | 108 |
| 98 if (!IsHour(hour) || !IsMinute(minute) || !IsSecond(second)) return false; | 109 if (!IsHour(hour) || !IsMinute(minute) || |
| 110 !IsSecond(second) || !IsMillisecond(millisecond)) return false; |
| 99 | 111 |
| 100 output->set(HOUR, Smi::FromInt(hour)); | 112 output->set(HOUR, Smi::FromInt(hour)); |
| 101 output->set(MINUTE, Smi::FromInt(minute)); | 113 output->set(MINUTE, Smi::FromInt(minute)); |
| 102 output->set(SECOND, Smi::FromInt(second)); | 114 output->set(SECOND, Smi::FromInt(second)); |
| 115 output->set(MILLISECOND, Smi::FromInt(millisecond)); |
| 103 return true; | 116 return true; |
| 104 } | 117 } |
| 105 | 118 |
| 106 bool DateParser::TimeZoneComposer::Write(FixedArray* output) { | 119 bool DateParser::TimeZoneComposer::Write(FixedArray* output) { |
| 107 if (sign_ != kNone) { | 120 if (sign_ != kNone) { |
| 108 if (hour_ == kNone) hour_ = 0; | 121 if (hour_ == kNone) hour_ = 0; |
| 109 if (minute_ == kNone) minute_ = 0; | 122 if (minute_ == kNone) minute_ = 0; |
| 110 int total_seconds = sign_ * (hour_ * 3600 + minute_ * 60); | 123 int total_seconds = sign_ * (hour_ * 3600 + minute_ * 60); |
| 111 if (!Smi::IsValid(total_seconds)) return false; | 124 if (!Smi::IsValid(total_seconds)) return false; |
| 112 output->set(UTC_OFFSET, Smi::FromInt(total_seconds)); | 125 output->set(UTC_OFFSET, Smi::FromInt(total_seconds)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 {'j', 'u', 'l', DateParser::MONTH_NAME, 7}, | 140 {'j', 'u', 'l', DateParser::MONTH_NAME, 7}, |
| 128 {'a', 'u', 'g', DateParser::MONTH_NAME, 8}, | 141 {'a', 'u', 'g', DateParser::MONTH_NAME, 8}, |
| 129 {'s', 'e', 'p', DateParser::MONTH_NAME, 9}, | 142 {'s', 'e', 'p', DateParser::MONTH_NAME, 9}, |
| 130 {'o', 'c', 't', DateParser::MONTH_NAME, 10}, | 143 {'o', 'c', 't', DateParser::MONTH_NAME, 10}, |
| 131 {'n', 'o', 'v', DateParser::MONTH_NAME, 11}, | 144 {'n', 'o', 'v', DateParser::MONTH_NAME, 11}, |
| 132 {'d', 'e', 'c', DateParser::MONTH_NAME, 12}, | 145 {'d', 'e', 'c', DateParser::MONTH_NAME, 12}, |
| 133 {'a', 'm', '\0', DateParser::AM_PM, 0}, | 146 {'a', 'm', '\0', DateParser::AM_PM, 0}, |
| 134 {'p', 'm', '\0', DateParser::AM_PM, 12}, | 147 {'p', 'm', '\0', DateParser::AM_PM, 12}, |
| 135 {'u', 't', '\0', DateParser::TIME_ZONE_NAME, 0}, | 148 {'u', 't', '\0', DateParser::TIME_ZONE_NAME, 0}, |
| 136 {'u', 't', 'c', DateParser::TIME_ZONE_NAME, 0}, | 149 {'u', 't', 'c', DateParser::TIME_ZONE_NAME, 0}, |
| 150 {'z', '\0', '\0', DateParser::TIME_ZONE_NAME, 0}, |
| 137 {'g', 'm', 't', DateParser::TIME_ZONE_NAME, 0}, | 151 {'g', 'm', 't', DateParser::TIME_ZONE_NAME, 0}, |
| 138 {'c', 'd', 't', DateParser::TIME_ZONE_NAME, -5}, | 152 {'c', 'd', 't', DateParser::TIME_ZONE_NAME, -5}, |
| 139 {'c', 's', 't', DateParser::TIME_ZONE_NAME, -6}, | 153 {'c', 's', 't', DateParser::TIME_ZONE_NAME, -6}, |
| 140 {'e', 'd', 't', DateParser::TIME_ZONE_NAME, -4}, | 154 {'e', 'd', 't', DateParser::TIME_ZONE_NAME, -4}, |
| 141 {'e', 's', 't', DateParser::TIME_ZONE_NAME, -5}, | 155 {'e', 's', 't', DateParser::TIME_ZONE_NAME, -5}, |
| 142 {'m', 'd', 't', DateParser::TIME_ZONE_NAME, -6}, | 156 {'m', 'd', 't', DateParser::TIME_ZONE_NAME, -6}, |
| 143 {'m', 's', 't', DateParser::TIME_ZONE_NAME, -7}, | 157 {'m', 's', 't', DateParser::TIME_ZONE_NAME, -7}, |
| 144 {'p', 'd', 't', DateParser::TIME_ZONE_NAME, -7}, | 158 {'p', 'd', 't', DateParser::TIME_ZONE_NAME, -7}, |
| 145 {'p', 's', 't', DateParser::TIME_ZONE_NAME, -8}, | 159 {'p', 's', 't', DateParser::TIME_ZONE_NAME, -8}, |
| 146 {'\0', '\0', '\0', DateParser::INVALID, 0}, | 160 {'\0', '\0', '\0', DateParser::INVALID, 0}, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 161 if (j == kPrefixLength && | 175 if (j == kPrefixLength && |
| 162 (len <= kPrefixLength || array[i][kTypeOffset] == MONTH_NAME)) { | 176 (len <= kPrefixLength || array[i][kTypeOffset] == MONTH_NAME)) { |
| 163 return i; | 177 return i; |
| 164 } | 178 } |
| 165 } | 179 } |
| 166 return i; | 180 return i; |
| 167 } | 181 } |
| 168 | 182 |
| 169 | 183 |
| 170 } } // namespace v8::internal | 184 } } // namespace v8::internal |
| OLD | NEW |