OLD | NEW |
1 /* Portions are Copyright (C) 2011 Google Inc */ | 1 /* Portions are Copyright (C) 2011 Google Inc */ |
2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // This is important, we want to make sure multiplications are | 105 // This is important, we want to make sure multiplications are |
106 // done with the correct precision. | 106 // done with the correct precision. |
107 static const PRTime kSecondsToMicroseconds = static_cast<PRTime>(1000000); | 107 static const PRTime kSecondsToMicroseconds = static_cast<PRTime>(1000000); |
108 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
109 // Create the system struct representing our exploded time. | 109 // Create the system struct representing our exploded time. |
110 SYSTEMTIME st = {0}; | 110 SYSTEMTIME st = {0}; |
111 FILETIME ft = {0}; | 111 FILETIME ft = {0}; |
112 ULARGE_INTEGER uli = {0}; | 112 ULARGE_INTEGER uli = {0}; |
113 | 113 |
114 st.wYear = exploded->tm_year; | 114 st.wYear = exploded->tm_year; |
115 st.wMonth = exploded->tm_month + 1; | 115 st.wMonth = static_cast<WORD>(exploded->tm_month + 1); |
116 st.wDayOfWeek = exploded->tm_wday; | 116 st.wDayOfWeek = exploded->tm_wday; |
117 st.wDay = exploded->tm_mday; | 117 st.wDay = static_cast<WORD>(exploded->tm_mday); |
118 st.wHour = exploded->tm_hour; | 118 st.wHour = static_cast<WORD>(exploded->tm_hour); |
119 st.wMinute = exploded->tm_min; | 119 st.wMinute = static_cast<WORD>(exploded->tm_min); |
120 st.wSecond = exploded->tm_sec; | 120 st.wSecond = static_cast<WORD>(exploded->tm_sec); |
121 st.wMilliseconds = exploded->tm_usec/1000; | 121 st.wMilliseconds = static_cast<WORD>(exploded->tm_usec/1000); |
122 // Convert to FILETIME. | 122 // Convert to FILETIME. |
123 if (!SystemTimeToFileTime(&st, &ft)) { | 123 if (!SystemTimeToFileTime(&st, &ft)) { |
124 NOTREACHED() << "Unable to convert time"; | 124 NOTREACHED() << "Unable to convert time"; |
125 return 0; | 125 return 0; |
126 } | 126 } |
127 // Apply offsets. | 127 // Apply offsets. |
128 uli.LowPart = ft.dwLowDateTime; | 128 uli.LowPart = ft.dwLowDateTime; |
129 uli.HighPart = ft.dwHighDateTime; | 129 uli.HighPart = ft.dwHighDateTime; |
130 // Convert from Windows epoch to NSPR epoch, and 100-nanoseconds units | 130 // Convert from Windows epoch to NSPR epoch, and 100-nanoseconds units |
131 // to microsecond units. | 131 // to microsecond units. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 time->tm_mday += time->tm_hour / 24; | 373 time->tm_mday += time->tm_hour / 24; |
374 time->tm_hour %= 24; | 374 time->tm_hour %= 24; |
375 if (time->tm_hour < 0) { | 375 if (time->tm_hour < 0) { |
376 time->tm_hour += 24; | 376 time->tm_hour += 24; |
377 time->tm_mday--; | 377 time->tm_mday--; |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 /* Normalize month and year before mday */ | 381 /* Normalize month and year before mday */ |
382 if (time->tm_month < 0 || time->tm_month >= 12) { | 382 if (time->tm_month < 0 || time->tm_month >= 12) { |
383 time->tm_year += time->tm_month / 12; | 383 time->tm_year += static_cast<PRInt16>(time->tm_month / 12); |
384 time->tm_month %= 12; | 384 time->tm_month %= 12; |
385 if (time->tm_month < 0) { | 385 if (time->tm_month < 0) { |
386 time->tm_month += 12; | 386 time->tm_month += 12; |
387 time->tm_year--; | 387 time->tm_year--; |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 /* Now that month and year are in proper range, normalize mday */ | 391 /* Now that month and year are in proper range, normalize mday */ |
392 | 392 |
393 if (time->tm_mday < 1) { | 393 if (time->tm_mday < 1) { |
(...skipping 15 matching lines...) Expand all Loading... |
409 time->tm_month++; | 409 time->tm_month++; |
410 if (time->tm_month > 11) { | 410 if (time->tm_month > 11) { |
411 time->tm_month = 0; | 411 time->tm_month = 0; |
412 time->tm_year++; | 412 time->tm_year++; |
413 } | 413 } |
414 daysInMonth = nDays[IsLeapYear(time->tm_year)][time->tm_month]; | 414 daysInMonth = nDays[IsLeapYear(time->tm_year)][time->tm_month]; |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 /* Recompute yday and wday */ | 418 /* Recompute yday and wday */ |
419 time->tm_yday = time->tm_mday + | 419 time->tm_yday = static_cast<PRInt16>(time->tm_mday + |
420 lastDayOfMonth[IsLeapYear(time->tm_year)][time->tm_month]; | 420 lastDayOfMonth[IsLeapYear(time->tm_year)][time->tm_month]); |
421 » | 421 |
422 numDays = DAYS_BETWEEN_YEARS(1970, time->tm_year) + time->tm_yday; | 422 numDays = DAYS_BETWEEN_YEARS(1970, time->tm_year) + time->tm_yday; |
423 time->tm_wday = (numDays + 4) % 7; | 423 time->tm_wday = (numDays + 4) % 7; |
424 if (time->tm_wday < 0) { | 424 if (time->tm_wday < 0) { |
425 time->tm_wday += 7; | 425 time->tm_wday += 7; |
426 } | 426 } |
427 | 427 |
428 /* Recompute time parameters */ | 428 /* Recompute time parameters */ |
429 | 429 |
430 time->tm_params = params(time); | 430 time->tm_params = params(time); |
431 | 431 |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 | 1125 |
1126 /* If we didn't find a year, month, or day-of-the-month, we can't | 1126 /* If we didn't find a year, month, or day-of-the-month, we can't |
1127 possibly parse this, and in fact, mktime() will do something random | 1127 possibly parse this, and in fact, mktime() will do something random |
1128 (I'm seeing it return "Tue Feb 5 06:28:16 2036", which is no doubt | 1128 (I'm seeing it return "Tue Feb 5 06:28:16 2036", which is no doubt |
1129 a numerologically significant date... */ | 1129 a numerologically significant date... */ |
1130 if (month == TT_UNKNOWN || date == -1 || year == -1 || year > PR_INT16_MAX) | 1130 if (month == TT_UNKNOWN || date == -1 || year == -1 || year > PR_INT16_MAX) |
1131 return PR_FAILURE; | 1131 return PR_FAILURE; |
1132 | 1132 |
1133 memset(result, 0, sizeof(*result)); | 1133 memset(result, 0, sizeof(*result)); |
1134 if (usec != -1) | 1134 if (usec != -1) |
1135 result->tm_usec = usec; | 1135 result->tm_usec = usec; |
1136 if (sec != -1) | 1136 if (sec != -1) |
1137 result->tm_sec = sec; | 1137 result->tm_sec = sec; |
1138 if (min != -1) | 1138 if (min != -1) |
1139 result->tm_min = min; | 1139 result->tm_min = min; |
1140 if (hour != -1) | 1140 if (hour != -1) |
1141 result->tm_hour = hour; | 1141 result->tm_hour = hour; |
1142 if (date != -1) | 1142 if (date != -1) |
1143 result->tm_mday = date; | 1143 result->tm_mday = date; |
1144 if (month != TT_UNKNOWN) | 1144 if (month != TT_UNKNOWN) |
1145 result->tm_month = (((int)month) - ((int)TT_JAN)); | 1145 result->tm_month = (((int)month) - ((int)TT_JAN)); |
1146 if (year != -1) | 1146 if (year != -1) |
1147 result->tm_year = year; | 1147 result->tm_year = static_cast<PRInt16>(year); |
1148 if (dotw != TT_UNKNOWN) | 1148 if (dotw != TT_UNKNOWN) |
1149 result->tm_wday = (((int)dotw) - ((int)TT_SUN)); | 1149 result->tm_wday = static_cast<PRInt8>(((int)dotw) - ((int)TT_SUN)); |
1150 /* | 1150 /* |
1151 * Mainly to compute wday and yday, but normalized time is also required | 1151 * Mainly to compute wday and yday, but normalized time is also required |
1152 * by the check below that works around a Visual C++ 2005 mktime problem. | 1152 * by the check below that works around a Visual C++ 2005 mktime problem. |
1153 */ | 1153 */ |
1154 PR_NormalizeTime(result, PR_GMTParameters); | 1154 PR_NormalizeTime(result, PR_GMTParameters); |
1155 /* The remaining work is to set the gmt and dst offsets in tm_params. */ | 1155 /* The remaining work is to set the gmt and dst offsets in tm_params. */ |
1156 | 1156 |
1157 if (zone == TT_UNKNOWN && default_to_gmt) | 1157 if (zone == TT_UNKNOWN && default_to_gmt) |
1158 { | 1158 { |
1159 /* No zone was specified, so pretend the zone was GMT. */ | 1159 /* No zone was specified, so pretend the zone was GMT. */ |
(...skipping 12 matching lines...) Expand all Loading... |
1172 result->tm_mday > 0 && | 1172 result->tm_mday > 0 && |
1173 result->tm_hour > -1 && | 1173 result->tm_hour > -1 && |
1174 result->tm_min > -1 && | 1174 result->tm_min > -1 && |
1175 result->tm_sec > -1); | 1175 result->tm_sec > -1); |
1176 | 1176 |
1177 /* | 1177 /* |
1178 * To obtain time_t from a tm structure representing the local | 1178 * To obtain time_t from a tm structure representing the local |
1179 * time, we call mktime(). However, we need to see if we are | 1179 * time, we call mktime(). However, we need to see if we are |
1180 * on 1-Jan-1970 or before. If we are, we can't call mktime() | 1180 * on 1-Jan-1970 or before. If we are, we can't call mktime() |
1181 * because mktime() will crash on win16. In that case, we | 1181 * because mktime() will crash on win16. In that case, we |
1182 * calculate zone_offset based on the zone offset at | 1182 * calculate zone_offset based on the zone offset at |
1183 * 00:00:00, 2 Jan 1970 GMT, and subtract zone_offset from the | 1183 * 00:00:00, 2 Jan 1970 GMT, and subtract zone_offset from the |
1184 * date we are parsing to transform the date to GMT. We also | 1184 * date we are parsing to transform the date to GMT. We also |
1185 * do so if mktime() returns (time_t) -1 (time out of range). | 1185 * do so if mktime() returns (time_t) -1 (time out of range). |
1186 */ | 1186 */ |
1187 | 1187 |
1188 /* month, day, hours, mins and secs are always non-negative | 1188 /* month, day, hours, mins and secs are always non-negative |
1189 so we dont need to worry about them. */ | 1189 so we dont need to worry about them. */ |
1190 if (result->tm_year >= 1970) | 1190 if (result->tm_year >= 1970) |
1191 { | 1191 { |
1192 localTime.tm_sec = result->tm_sec; | 1192 localTime.tm_sec = result->tm_sec; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 + 60 * localTime.tm_hour | 1243 + 60 * localTime.tm_hour |
1244 + 1440 * (localTime.tm_mday - 2); | 1244 + 1440 * (localTime.tm_mday - 2); |
1245 } | 1245 } |
1246 | 1246 |
1247 result->tm_params.tp_gmt_offset = zone_offset * 60; | 1247 result->tm_params.tp_gmt_offset = zone_offset * 60; |
1248 result->tm_params.tp_dst_offset = dst_offset * 60; | 1248 result->tm_params.tp_dst_offset = dst_offset * 60; |
1249 | 1249 |
1250 *result_imploded = PR_ImplodeTime(result); | 1250 *result_imploded = PR_ImplodeTime(result); |
1251 return PR_SUCCESS; | 1251 return PR_SUCCESS; |
1252 } | 1252 } |
OLD | NEW |