Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: sdk/lib/io/http_utils.dart

Issue 11770004: Rename Date to DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and keep Backwards-compatibility class Date. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_session.dart ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpUtils { 7 class _HttpUtils {
8 static String decodeUrlEncodedString(String urlEncoded) { 8 static String decodeUrlEncodedString(String urlEncoded) {
9 // First check the string for any encoding. 9 // First check the string for any encoding.
10 int index = 0; 10 int index = 0;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // ; 00:00:00 - 23:59:59 90 // ; 00:00:00 - 23:59:59
91 // wkday = "Mon" | "Tue" | "Wed" 91 // wkday = "Mon" | "Tue" | "Wed"
92 // | "Thu" | "Fri" | "Sat" | "Sun" 92 // | "Thu" | "Fri" | "Sat" | "Sun"
93 // weekday = "Monday" | "Tuesday" | "Wednesday" 93 // weekday = "Monday" | "Tuesday" | "Wednesday"
94 // | "Thursday" | "Friday" | "Saturday" | "Sunday" 94 // | "Thursday" | "Friday" | "Saturday" | "Sunday"
95 // month = "Jan" | "Feb" | "Mar" | "Apr" 95 // month = "Jan" | "Feb" | "Mar" | "Apr"
96 // | "May" | "Jun" | "Jul" | "Aug" 96 // | "May" | "Jun" | "Jul" | "Aug"
97 // | "Sep" | "Oct" | "Nov" | "Dec" 97 // | "Sep" | "Oct" | "Nov" | "Dec"
98 98
99 // Format as RFC 1123 date. 99 // Format as RFC 1123 date.
100 static String formatDate(Date date) { 100 static String formatDate(DateTime date) {
101 const List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; 101 const List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
102 const List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 102 const List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
103 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 103 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
104 104
105 Date d = date.toUtc(); 105 DateTime d = date.toUtc();
106 StringBuffer sb = new StringBuffer(); 106 StringBuffer sb = new StringBuffer();
107 sb.add(wkday[d.weekday - 1]); 107 sb.add(wkday[d.weekday - 1]);
108 sb.add(", "); 108 sb.add(", ");
109 sb.add(d.day.toString()); 109 sb.add(d.day.toString());
110 sb.add(" "); 110 sb.add(" ");
111 sb.add(month[d.month - 1]); 111 sb.add(month[d.month - 1]);
112 sb.add(" "); 112 sb.add(" ");
113 sb.add(d.year.toString()); 113 sb.add(d.year.toString());
114 sb.add(d.hour < 9 ? " 0" : " "); 114 sb.add(d.hour < 9 ? " 0" : " ");
115 sb.add(d.hour.toString()); 115 sb.add(d.hour.toString());
116 sb.add(d.minute < 9 ? ":0" : ":"); 116 sb.add(d.minute < 9 ? ":0" : ":");
117 sb.add(d.minute.toString()); 117 sb.add(d.minute.toString());
118 sb.add(d.second < 9 ? ":0" : ":"); 118 sb.add(d.second < 9 ? ":0" : ":");
119 sb.add(d.second.toString()); 119 sb.add(d.second.toString());
120 sb.add(" GMT"); 120 sb.add(" GMT");
121 return sb.toString(); 121 return sb.toString();
122 } 122 }
123 123
124 static Date parseDate(String date) { 124 static DateTime parseDate(String date) {
125 final int SP = 32; 125 final int SP = 32;
126 const List wkdays = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; 126 const List wkdays = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
127 const List weekdays = const ["Monday", "Tuesday", "Wednesday", "Thursday", 127 const List weekdays = const ["Monday", "Tuesday", "Wednesday", "Thursday",
128 "Friday", "Saturday", "Sunday"]; 128 "Friday", "Saturday", "Sunday"];
129 const List months = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 129 const List months = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
130 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 130 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
131 const List wkdaysLowerCase = 131 const List wkdaysLowerCase =
132 const ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; 132 const ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
133 const List weekdaysLowerCase = const ["monday", "tuesday", "wednesday", 133 const List weekdaysLowerCase = const ["monday", "tuesday", "wednesday",
134 "thursday", "friday", "saturday", 134 "thursday", "friday", "saturday",
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 expect(" "); 239 expect(" ");
240 day = expectNum(format == formatRfc1123 ? " " : "-"); 240 day = expectNum(format == formatRfc1123 ? " " : "-");
241 month = expectMonth(format == formatRfc1123 ? " " : "-"); 241 month = expectMonth(format == formatRfc1123 ? " " : "-");
242 year = expectNum(" "); 242 year = expectNum(" ");
243 hours = expectNum(":"); 243 hours = expectNum(":");
244 minutes = expectNum(":"); 244 minutes = expectNum(":");
245 seconds = expectNum(" "); 245 seconds = expectNum(" ");
246 expect("GMT"); 246 expect("GMT");
247 } 247 }
248 expectEnd(); 248 expectEnd();
249 return new Date.utc(year, month + 1, day, hours, minutes, seconds, 0); 249 return new DateTime.utc(year, month + 1, day, hours, minutes, seconds, 0);
250 } 250 }
251 251
252 static Date parseCookieDate(String date) { 252 static DateTime parseCookieDate(String date) {
253 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", 253 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may",
254 "jun", "jul", "aug", "sep", "oct", 254 "jun", "jul", "aug", "sep", "oct",
255 "nov", "dec"]; 255 "nov", "dec"];
256 256
257 int position = 0; 257 int position = 0;
258 258
259 void error() { 259 void error() {
260 throw new HttpException("Invalid cookie date $date"); 260 throw new HttpException("Invalid cookie date $date");
261 } 261 }
262 262
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 var timeList = timeStr.split(":"); 350 var timeList = timeStr.split(":");
351 if (timeList.length != 3) error(); 351 if (timeList.length != 3) error();
352 int hour = toInt(timeList[0]); 352 int hour = toInt(timeList[0]);
353 int minute = toInt(timeList[1]); 353 int minute = toInt(timeList[1]);
354 int second = toInt(timeList[2]); 354 int second = toInt(timeList[2]);
355 if (hour > 23) error(); 355 if (hour > 23) error();
356 if (minute > 59) error(); 356 if (minute > 59) error();
357 if (second > 59) error(); 357 if (second > 59) error();
358 358
359 return new Date.utc(year, month, dayOfMonth, hour, minute, second, 0); 359 return new DateTime.utc(year, month, dayOfMonth, hour, minute, second, 0);
360 } 360 }
361 } 361 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_session.dart ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698