Skip to content

Commit

Permalink
Fix for issue#17. DateTime,parse() now supports microseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Feb 9, 2016
1 parent 551719d commit 8465825
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 11 deletions.
13 changes: 9 additions & 4 deletions LibTest/core/DateTime/parse_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
/**
* @assertion DateTime.parse(String formattedString)
* Constructs a new [DateTime] instance based on [formattedString]
* @description Checks that the DateTime instance is created.
* @description Checks that the output of toString is parsed back into
* a DateTime object with the same time as the original.
* @author hlodvig
* @reviewer msyabro
* @author sgrekhov@unipro.ru
*/
import "../../../Utils/expect.dart";

main(){
Expect.isTrue(DateTime.parse(new DateTime.now().toString()) is DateTime);

main() {
DateTime now = new DateTime.now();
DateTime parsed = DateTime.parse(now.toString());
Expect.equals(now.microsecondsSinceEpoch, parsed.microsecondsSinceEpoch);
Expect.equals(now.toString(), parsed.toString());
}
10 changes: 3 additions & 7 deletions LibTest/core/DateTime/parse_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* @description Checks that from the correct string the correct data is created.
* @author msyabro
* @reviewer pagolubev
* @needsreview Format is not specified. The assumption was made by the results of [toString()].
*/
import "../../../Utils/expect.dart";

check(String str, int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) {
check(String str, int year, int month, int day, int hours, int minutes,
int seconds, int milliseconds) {
DateTime d = DateTime.parse(str);
Expect.equals(year, d.year);
Expect.equals(month, d.month);
Expand All @@ -31,11 +31,7 @@ main() {
check("0005-01-01 00:00:00.0", 5, 1, 1, 0, 0, 0, 0);
check("1845-11-30 12:00:00.275", 1845, 11, 30, 12, 0, 0, 275);
check("30000-11-30 12:00:00.275", 30000, 11, 30, 12, 0, 0, 275);

//Seconds are rounded to 3 decimal places
check("2001-01-01 00:00:00.9994", 2001, 1, 1, 0, 0, 0, 999);
check("2001-01-01 00:00:00.9995", 2001, 1, 1, 0, 0, 1, 0);


//Without some components
check("2000-01-01", 2000, 1, 1, 0, 0, 0, 0);
check("2000-01-01 12", 2000, 1, 1, 12, 0, 0, 0);
Expand Down
58 changes: 58 additions & 0 deletions LibTest/core/DateTime/parse_A01_t03.dart
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);
}
20 changes: 20 additions & 0 deletions LibTest/core/DateTime/parse_A01_t04.dart
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());
}

0 comments on commit 8465825

Please sign in to comment.