| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/DateComponents.h" | 32 #include "platform/DateComponents.h" |
| 33 | 33 |
| 34 #include <limits.h> | 34 #include <limits.h> |
| 35 #include "wtf/ASCIICType.h" | 35 #include "wtf/ASCIICType.h" |
| 36 #include "wtf/DateMath.h" | 36 #include "wtf/DateMath.h" |
| 37 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
| 38 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
| 39 | 39 |
| 40 using namespace std; | |
| 41 | |
| 42 namespace blink { | 40 namespace blink { |
| 43 | 41 |
| 44 // HTML5 specification defines minimum week of year is one. | 42 // HTML5 specification defines minimum week of year is one. |
| 45 const int DateComponents::minimumWeekNumber = 1; | 43 const int DateComponents::minimumWeekNumber = 1; |
| 46 | 44 |
| 47 // HTML5 specification defines maximum week of year is 53. | 45 // HTML5 specification defines maximum week of year is 53. |
| 48 const int DateComponents::maximumWeekNumber = 53; | 46 const int DateComponents::maximumWeekNumber = 53; |
| 49 | 47 |
| 50 static const int maximumMonthInMaximumYear = 8; // This is September, since mont
hs are 0 based. | 48 static const int maximumMonthInMaximumYear = 8; // This is September, since mont
hs are 0 based. |
| 51 static const int maximumDayInMaximumMonth = 13; | 49 static const int maximumDayInMaximumMonth = 13; |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 static inline double positiveFmod(double value, double divider) | 489 static inline double positiveFmod(double value, double divider) |
| 492 { | 490 { |
| 493 double remainder = fmod(value, divider); | 491 double remainder = fmod(value, divider); |
| 494 return remainder < 0 ? remainder + divider : remainder; | 492 return remainder < 0 ? remainder + divider : remainder; |
| 495 } | 493 } |
| 496 | 494 |
| 497 void DateComponents::setMillisecondsSinceMidnightInternal(double msInDay) | 495 void DateComponents::setMillisecondsSinceMidnightInternal(double msInDay) |
| 498 { | 496 { |
| 499 ASSERT(msInDay >= 0 && msInDay < msPerDay); | 497 ASSERT(msInDay >= 0 && msInDay < msPerDay); |
| 500 m_millisecond = static_cast<int>(fmod(msInDay, msPerSecond)); | 498 m_millisecond = static_cast<int>(fmod(msInDay, msPerSecond)); |
| 501 double value = floor(msInDay / msPerSecond); | 499 double value = std::floor(msInDay / msPerSecond); |
| 502 m_second = static_cast<int>(fmod(value, secondsPerMinute)); | 500 m_second = static_cast<int>(fmod(value, secondsPerMinute)); |
| 503 value = floor(value / secondsPerMinute); | 501 value = std::floor(value / secondsPerMinute); |
| 504 m_minute = static_cast<int>(fmod(value, minutesPerHour)); | 502 m_minute = static_cast<int>(fmod(value, minutesPerHour)); |
| 505 m_hour = static_cast<int>(value / minutesPerHour); | 503 m_hour = static_cast<int>(value / minutesPerHour); |
| 506 } | 504 } |
| 507 | 505 |
| 508 bool DateComponents::setMillisecondsSinceEpochForDateInternal(double ms) | 506 bool DateComponents::setMillisecondsSinceEpochForDateInternal(double ms) |
| 509 { | 507 { |
| 510 m_year = msToYear(ms); | 508 m_year = msToYear(ms); |
| 511 int yearDay = dayInYear(ms, m_year); | 509 int yearDay = dayInYear(ms, m_year); |
| 512 m_month = monthFromDayInYear(yearDay, isLeapYear(m_year)); | 510 m_month = monthFromDayInYear(yearDay, isLeapYear(m_year)); |
| 513 m_monthDay = dayInMonthFromDayInYear(yearDay, isLeapYear(m_year)); | 511 m_monthDay = dayInMonthFromDayInYear(yearDay, isLeapYear(m_year)); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 case Week: | 706 case Week: |
| 709 return String::format("%04d-W%02d", m_year, m_week); | 707 return String::format("%04d-W%02d", m_year, m_week); |
| 710 case Invalid: | 708 case Invalid: |
| 711 break; | 709 break; |
| 712 } | 710 } |
| 713 ASSERT_NOT_REACHED(); | 711 ASSERT_NOT_REACHED(); |
| 714 return String("(Invalid DateComponents)"); | 712 return String("(Invalid DateComponents)"); |
| 715 } | 713 } |
| 716 | 714 |
| 717 } // namespace blink | 715 } // namespace blink |
| OLD | NEW |