| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // HTML5 specification defines maximum week of year is 53. | 47 // HTML5 specification defines maximum week of year is 53. |
| 48 const int DateComponents::maximumWeekNumber = 53; | 48 const int DateComponents::maximumWeekNumber = 53; |
| 49 | 49 |
| 50 static const int maximumMonthInMaximumYear = 8; // This is September, since mont
hs are 0 based. | 50 static const int maximumMonthInMaximumYear = 8; // This is September, since mont
hs are 0 based. |
| 51 static const int maximumDayInMaximumMonth = 13; | 51 static const int maximumDayInMaximumMonth = 13; |
| 52 static const int maximumWeekInMaximumYear = 37; // The week of 275760-09-13 | 52 static const int maximumWeekInMaximumYear = 37; // The week of 275760-09-13 |
| 53 | 53 |
| 54 static const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31}; | 54 static const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31}; |
| 55 | 55 |
| 56 static bool isLeapYear(int year) | |
| 57 { | |
| 58 if (year % 4) | |
| 59 return false; | |
| 60 if (!(year % 400)) | |
| 61 return true; | |
| 62 if (!(year % 100)) | |
| 63 return false; | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 // 'month' is 0-based. | 56 // 'month' is 0-based. |
| 68 static int maxDayOfMonth(int year, int month) | 57 static int maxDayOfMonth(int year, int month) |
| 69 { | 58 { |
| 70 if (month != 1) // February? | 59 if (month != 1) // February? |
| 71 return daysInMonth[month]; | 60 return daysInMonth[month]; |
| 72 return isLeapYear(year) ? 29 : 28; | 61 return isLeapYear(year) ? 29 : 28; |
| 73 } | 62 } |
| 74 | 63 |
| 75 // 'month' is 0-based. | 64 // 'month' is 0-based. |
| 76 static int dayOfWeek(int year, int month, int day) | 65 static int dayOfWeek(int year, int month, int day) |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 case Week: | 703 case Week: |
| 715 return String::format("%04d-W%02d", m_year, m_week); | 704 return String::format("%04d-W%02d", m_year, m_week); |
| 716 case Invalid: | 705 case Invalid: |
| 717 break; | 706 break; |
| 718 } | 707 } |
| 719 ASSERT_NOT_REACHED(); | 708 ASSERT_NOT_REACHED(); |
| 720 return String("(Invalid DateComponents)"); | 709 return String("(Invalid DateComponents)"); |
| 721 } | 710 } |
| 722 | 711 |
| 723 } // namespace WebCore | 712 } // namespace WebCore |
| OLD | NEW |