Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** | 7 /** |
| 8 * Utility functions for working with dates with HTTP specific date | 8 * Utility functions for working with dates with HTTP specific date |
| 9 * formats. | 9 * formats. |
| 10 */ | 10 */ |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 * Format a date according to | 36 * Format a date according to |
| 37 * [RFC-1123](http://tools.ietf.org/html/rfc1123 "RFC-1123"), | 37 * [RFC-1123](http://tools.ietf.org/html/rfc1123 "RFC-1123"), |
| 38 * e.g. `Thu, 1 Jan 1970 00:00:00 GMT`. | 38 * e.g. `Thu, 1 Jan 1970 00:00:00 GMT`. |
| 39 */ | 39 */ |
| 40 static String format(DateTime date) { | 40 static String format(DateTime date) { |
| 41 const List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; | 41 const List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; |
| 42 const List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", | 42 const List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 43 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | 43 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; |
| 44 | 44 |
| 45 DateTime d = date.toUtc(); | 45 DateTime d = date.toUtc(); |
| 46 StringBuffer sb = new StringBuffer(); | 46 StringBuffer sb = new StringBuffer() |
|
Ivan Posva
2014/01/08 17:35:38
Lasse,
Can you please explain the motivation of t
| |
| 47 sb.write(wkday[d.weekday - 1]); | 47 ..write(wkday[d.weekday - 1]) |
| 48 sb.write(", "); | 48 ..write(", ") |
| 49 sb.write(d.day.toString()); | 49 ..write(d.day.toString()) |
| 50 sb.write(" "); | 50 ..write(" ") |
| 51 sb.write(month[d.month - 1]); | 51 ..write(month[d.month - 1]) |
| 52 sb.write(" "); | 52 ..write(" ") |
| 53 sb.write(d.year.toString()); | 53 ..write(d.year.toString()) |
| 54 sb.write(d.hour < 9 ? " 0" : " "); | 54 ..write(d.hour < 9 ? " 0" : " ") |
| 55 sb.write(d.hour.toString()); | 55 ..write(d.hour.toString()) |
| 56 sb.write(d.minute < 9 ? ":0" : ":"); | 56 ..write(d.minute < 9 ? ":0" : ":") |
| 57 sb.write(d.minute.toString()); | 57 ..write(d.minute.toString()) |
| 58 sb.write(d.second < 9 ? ":0" : ":"); | 58 ..write(d.second < 9 ? ":0" : ":") |
| 59 sb.write(d.second.toString()); | 59 ..write(d.second.toString()) |
| 60 sb.write(" GMT"); | 60 ..write(" GMT"); |
| 61 return sb.toString(); | 61 return sb.toString(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Parse a date string in either of the formats | 65 * Parse a date string in either of the formats |
| 66 * [RFC-1123](http://tools.ietf.org/html/rfc1123 "RFC-1123"), | 66 * [RFC-1123](http://tools.ietf.org/html/rfc1123 "RFC-1123"), |
| 67 * [RFC-850](http://tools.ietf.org/html/rfc850 "RFC-850") or | 67 * [RFC-850](http://tools.ietf.org/html/rfc850 "RFC-850") or |
| 68 * ANSI C's asctime() format. These formats are listed here. | 68 * ANSI C's asctime() format. These formats are listed here. |
| 69 * | 69 * |
| 70 * Thu, 1 Jan 1970 00:00:00 GMT | 70 * Thu, 1 Jan 1970 00:00:00 GMT |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", | 208 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", |
| 209 "jun", "jul", "aug", "sep", "oct", | 209 "jun", "jul", "aug", "sep", "oct", |
| 210 "nov", "dec"]; | 210 "nov", "dec"]; |
| 211 | 211 |
| 212 int position = 0; | 212 int position = 0; |
| 213 | 213 |
| 214 void error() { | 214 void error() { |
| 215 throw new HttpException("Invalid cookie date $date"); | 215 throw new HttpException("Invalid cookie date $date"); |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool isEnd() { | 218 bool isEnd() => position == date.length; |
| 219 return position == date.length; | |
| 220 } | |
| 221 | 219 |
| 222 bool isDelimiter(String s) { | 220 bool isDelimiter(String s) { |
| 223 int char = s.codeUnitAt(0); | 221 int char = s.codeUnitAt(0); |
| 224 if (char == 0x09) return true; | 222 if (char == 0x09) return true; |
| 225 if (char >= 0x20 && char <= 0x2F) return true; | 223 if (char >= 0x20 && char <= 0x2F) return true; |
| 226 if (char >= 0x3B && char <= 0x40) return true; | 224 if (char >= 0x3B && char <= 0x40) return true; |
| 227 if (char >= 0x5B && char <= 0x60) return true; | 225 if (char >= 0x5B && char <= 0x60) return true; |
| 228 if (char >= 0x7B && char <= 0x7E) return true; | 226 if (char >= 0x7B && char <= 0x7E) return true; |
| 229 return false; | 227 return false; |
| 230 } | 228 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 int hour = toInt(timeList[0]); | 305 int hour = toInt(timeList[0]); |
| 308 int minute = toInt(timeList[1]); | 306 int minute = toInt(timeList[1]); |
| 309 int second = toInt(timeList[2]); | 307 int second = toInt(timeList[2]); |
| 310 if (hour > 23) error(); | 308 if (hour > 23) error(); |
| 311 if (minute > 59) error(); | 309 if (minute > 59) error(); |
| 312 if (second > 59) error(); | 310 if (second > 59) error(); |
| 313 | 311 |
| 314 return new DateTime.utc(year, month, dayOfMonth, hour, minute, second, 0); | 312 return new DateTime.utc(year, month, dayOfMonth, hour, minute, second, 0); |
| 315 } | 313 } |
| 316 } | 314 } |
| OLD | NEW |