|
6 | 6 | import java.io.InputStreamReader; |
7 | 7 | import java.io.Reader; |
8 | 8 | import java.io.StringReader; |
| 9 | +import java.util.GregorianCalendar; |
9 | 10 |
|
10 | 11 | /* |
11 | 12 | Copyright (c) 2002 JSON.org |
@@ -358,7 +359,7 @@ public Object nextValue() throws JSONException { |
358 | 359 | switch (c) { |
359 | 360 | case '"': |
360 | 361 | case '\'': |
361 | | - return this.nextString(c); |
| 362 | + return this.checkDates(this.nextString(c)); |
362 | 363 | case '{': |
363 | 364 | this.back(); |
364 | 365 | return new JSONObject(this); |
@@ -390,6 +391,34 @@ public Object nextValue() throws JSONException { |
390 | 391 | return JSONObject.stringToValue(string); |
391 | 392 | } |
392 | 393 |
|
| 394 | + /** |
| 395 | + * Checks a string for dates. |
| 396 | + * |
| 397 | + * @param s string to check |
| 398 | + * @return passed through string or a Date object |
| 399 | + */ |
| 400 | + private Object checkDates(String s) { |
| 401 | + if (s.length() == 10 || s.length() == 20) { |
| 402 | + if (s.charAt(4) == '-' && s.charAt(7) == '-') { |
| 403 | + int year = Integer.valueOf(s.substring(0, 4)); |
| 404 | + int month = Integer.valueOf(s.substring(5, 7)); |
| 405 | + int day = Integer.valueOf(s.substring(8, 10)); |
| 406 | + |
| 407 | + if (s.length() == 20 && s.charAt(10) == 'T' && s.charAt(13) == ':' && s.charAt(16) == ':' && s.charAt(19) == 'Z') { |
| 408 | + int hour = Integer.valueOf(s.substring(11, 13)); |
| 409 | + int mins = Integer.valueOf(s.substring(14, 16)); |
| 410 | + int secs = Integer.valueOf(s.substring(17, 19)); |
| 411 | + |
| 412 | + return new GregorianCalendar(year, month, day, hour, mins, secs).getTime(); |
| 413 | + } |
| 414 | + |
| 415 | + return new GregorianCalendar(year, month, day).getTime(); |
| 416 | + } |
| 417 | + } |
| 418 | + |
| 419 | + return s; |
| 420 | + } |
| 421 | + |
393 | 422 |
|
394 | 423 | /** |
395 | 424 | * Skip characters until the next character is the requested character. |
|
0 commit comments