Changeset 44508 in webkit for trunk/JavaScriptCore/wtf/DateMath.cpp
- Timestamp:
- Jun 8, 2009, 3:37:06 PM (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/DateMath.cpp
r44501 r44508 2 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 3 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 4 * 4 * Copyright (C) 2009 Google Inc. All rights reserved. 5 * 5 6 * The Original Code is Mozilla Communicator client code, released 6 7 * March 31, 1998. … … 43 44 #include "DateMath.h" 44 45 45 #include "JSNumberCell.h" 46 #include <math.h> 46 #include "Assertions.h" 47 #include "ASCIICType.h" 48 #include "CurrentTime.h" 49 #include "MathExtras.h" 50 #include "StringExtras.h" 51 52 #include <limits> 47 53 #include <stdint.h> 48 54 #include <time.h> 49 #include <wtf/ASCIICType.h> 50 #include <wtf/Assertions.h> 51 #include <wtf/CurrentTime.h> 52 #include <wtf/MathExtras.h> 53 #include <wtf/StringExtras.h> 55 54 56 55 57 #if HAVE(ERRNO_H) … … 69 71 #endif 70 72 71 using namespace WTF; 72 73 namespace JSC{73 #define NaN std::numeric_limits<double>::quiet_NaN() 74 75 namespace WTF { 74 76 75 77 /* Constants */ … … 497 499 } 498 500 499 void init DateMath()501 void initializeDates() 500 502 { 501 503 #ifndef NDEBUG … … 593 595 } 594 596 595 double parseDate (const UString &date)597 double parseDateFromNullTerminatedCharacters(const char* dateString) 596 598 { 597 599 // This parses a date in the form: … … 608 610 // 609 611 // We ignore the weekday. 610 611 CString dateCString = date.UTF8String();612 const char *dateString = dateCString.c_str();613 612 614 613 // Skip leading space … … 716 715 return NaN; 717 716 } 718 717 719 718 // Don't fail if the time is missing. 720 719 long hour = 0; … … 773 772 return NaN; 774 773 dateString = newPosStr; 775 774 776 775 if (second < 0 || second > 59) 777 776 return NaN; … … 849 848 dateString = newPosStr; 850 849 } 851 850 852 851 skipSpacesAndComments(dateString); 853 852 854 853 // Trailing garbage 855 854 if (*dateString) … … 891 890 } 892 891 893 UString formatDate(const GregorianDateTime &t) 894 { 895 char buffer[100]; 896 snprintf(buffer, sizeof(buffer), "%s %s %02d %04d", 897 weekdayName[(t.weekDay + 6) % 7], 898 monthName[t.month], t.monthDay, t.year + 1900); 899 return buffer; 900 } 901 902 UString formatDateUTCVariant(const GregorianDateTime &t) 903 { 904 char buffer[100]; 905 snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d", 906 weekdayName[(t.weekDay + 6) % 7], 907 t.monthDay, monthName[t.month], t.year + 1900); 908 return buffer; 909 } 910 911 UString formatTime(const GregorianDateTime &t, bool utc) 912 { 913 char buffer[100]; 914 if (utc) { 915 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second); 916 } else { 917 int offset = abs(gmtoffset(t)); 918 char timeZoneName[70]; 919 struct tm gtm = t; 920 strftime(timeZoneName, sizeof(timeZoneName), "%Z", >m); 921 922 if (timeZoneName[0]) { 923 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)", 924 t.hour, t.minute, t.second, 925 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName); 926 } else { 927 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d", 928 t.hour, t.minute, t.second, 929 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60); 930 } 931 } 932 return UString(buffer); 933 } 934 935 } // namespace JSC 892 893 } // namespace WTF
Note:
See TracChangeset
for help on using the changeset viewer.