-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue#17. DateTime,parse() now supports microseconds
- Loading branch information
sgrekhov
committed
Feb 9, 2016
1 parent
551719d
commit 8465825
Showing
4 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion DateTime.parse(String formattedString) | ||
* Constructs a new [DateTime] instance based on [formattedString] | ||
* @description Checks that date is parsed up to microseconds | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "../../../Utils/expect.dart"; | ||
|
||
check(String str, int year, int month, int day, int hours, int minutes, | ||
int seconds, int milliseconds, int microseconds) { | ||
DateTime d = DateTime.parse(str); | ||
Expect.equals(year, d.year); | ||
Expect.equals(month, d.month); | ||
Expect.equals(day, d.day); | ||
Expect.equals(hours, d.hour); | ||
Expect.equals(minutes, d.minute); | ||
Expect.equals(seconds, d.second); | ||
Expect.equals(milliseconds, d.millisecond); | ||
Expect.equals(microseconds, d.microsecond); | ||
} | ||
|
||
main() { | ||
check("2001-01-01 23:23:23.23", 2001, 1, 1, 23, 23, 23, 230, 0); | ||
check("-2001-05-20 02:03:00.0", -2001, 5, 20, 2, 3, 0, 0, 0); | ||
check("2001-01-01 23:23:23.023", 2001, 1, 1, 23, 23, 23, 23, 0); | ||
check("0005-01-01 00:00:00.0", 5, 1, 1, 0, 0, 0, 0, 0); | ||
check("1845-11-30 12:00:00.275", 1845, 11, 30, 12, 0, 0, 275, 0); | ||
check("30000-11-30 12:00:00.275", 30000, 11, 30, 12, 0, 0, 275, 0); | ||
|
||
//Seconds are rounded to 6 decimal places | ||
check("2001-01-01 00:00:00.9994", 2001, 1, 1, 0, 0, 0, 999, 400); | ||
check("2001-01-01 00:00:00.9995", 2001, 1, 1, 0, 0, 0, 999, 500); | ||
check("2001-01-01 00:00:00.99949", 2001, 1, 1, 0, 0, 0, 999, 490); | ||
check("2001-01-01 00:00:00.999501", 2001, 1, 1, 0, 0, 0, 999, 501); | ||
check("2001-01-01 00:00:00.999499", 2001, 1, 1, 0, 0, 0, 999, 499); | ||
|
||
//Without some components | ||
check("2000-01-01", 2000, 1, 1, 0, 0, 0, 0, 0); | ||
check("2000-01-01 12", 2000, 1, 1, 12, 0, 0, 0, 0); | ||
check("2000-01-01 12:55", 2000, 1, 1, 12, 55, 0, 0, 0); | ||
check("2001-01-01 23:23:23", 2001, 1, 1, 23, 23, 23, 0, 0); | ||
|
||
//DateTime jumping: is it correct behavior? | ||
check("2000-02-30 00:00:00", 2000, 3, 1, 0, 0, 0, 0, 0); | ||
check("2000-06-31 00:00:00", 2000, 7, 1, 0, 0, 0, 0, 0); | ||
|
||
//With 'T' separates date and time | ||
check("2000-01-01T15:25:12.03", 2000, 1, 1, 15, 25, 12, 30, 0); | ||
|
||
//UTC | ||
check('0001-01-01 00:00:00.000Z', 1, 1, 1, 0, 0, 0, 0, 0); | ||
check('1999-10-20 11:12:13.014Z', 1999, 10, 20, 11, 12, 13, 14, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion DateTime.parse(String formattedString) | ||
* Constructs a new [DateTime] instance based on [formattedString] | ||
* @description Checks that the output of toIso8601String is parsed back into | ||
* a DateTime object with the same time as the original. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "../../../Utils/expect.dart"; | ||
|
||
main() { | ||
DateTime now = new DateTime.now(); | ||
DateTime parsed = DateTime.parse(now.toIso8601String()); | ||
Expect.equals(now.microsecondsSinceEpoch, parsed.microsecondsSinceEpoch); | ||
Expect.equals(now.toIso8601String(), parsed.toIso8601String()); | ||
} |