DataFormatter should infer datetime from values without seconds (#3668)

Fixes https://www.pivotaltracker.com/story/show/183033133
This commit is contained in:
Radosław Waśko 2022-08-26 23:10:52 +02:00 committed by GitHub
parent d7ebc4a338
commit e6e4692692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 6 deletions

View File

@ -53,7 +53,7 @@ type Data_Formatter
- datetime_locale: The locale to use when parsing dates and times.
- true_values: Values representing True.
- false_values: Values representing False.
type Data_Formatter trim_values:Boolean=True allow_leading_zeros:Boolean=False decimal_point:Text='.' thousand_separator:Text='' allow_exponential_notation:Boolean=False datetime_formats:[Text]=["yyyy-MM-dd HH:mm:ss"] date_formats:[Text]=["yyyy-MM-dd"] time_formats:[Text]=["HH:mm:ss"] datetime_locale:Locale=Locale.default true_values:[Text]=["True","true","TRUE"] false_values:[Text]=["False","false","FALSE"]
type Data_Formatter trim_values:Boolean=True allow_leading_zeros:Boolean=False decimal_point:Text='.' thousand_separator:Text='' allow_exponential_notation:Boolean=False datetime_formats:[Text]=["yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm"] date_formats:[Text]=["yyyy-MM-dd"] time_formats:[Text]=["HH:mm:ss", "HH:mm"] datetime_locale:Locale=Locale.default true_values:[Text]=["True","true","TRUE"] false_values:[Text]=["False","false","FALSE"]
## Parse a Text into a value.

View File

@ -1,7 +1,7 @@
Serial number,Movement type,Posting date
2LMXK1,101,2015-01-05 09:00:00
2LMXK1,301,2015-01-05 14:00:00
2LMXK1,301,2015-01-05 14:00
JEMLP3,101,2015-01-06 09:00:00
JEMLP3,203,2015-01-07 17:30:00
BR83GP,101,2011-01-05 09:00:00
BR83GP,301,2011-01-09 15:30:00
BR83GP,101,2011-01-05 09:00
BR83GP,301,2011-01-09 15:30

1 Serial number Movement type Posting date
2 2LMXK1 101 2015-01-05 09:00:00
3 2LMXK1 301 2015-01-05 14:00:00 2015-01-05 14:00
4 JEMLP3 101 2015-01-06 09:00:00
5 JEMLP3 203 2015-01-07 17:30:00
6 BR83GP 101 2011-01-05 09:00:00 2011-01-05 09:00
7 BR83GP 301 2011-01-09 15:30:00 2011-01-09 15:30

View File

@ -1,7 +1,7 @@
Serial number,Movement type,Posting time
2LMXK1,101,09:00:00
2LMXK1,101,09:00
2LMXK1,301,14:00:12
JEMLP3,101,09:00:00
JEMLP3,203,17:30:00
JEMLP3,203,17:30
BR83GP,101,09:00:04
BR83GP,301,15:30:00

1 Serial number Movement type Posting time
2 2LMXK1 101 09:00:00 09:00
3 2LMXK1 301 14:00:12
4 JEMLP3 101 09:00:00
5 JEMLP3 203 17:30:00 17:30
6 BR83GP 101 09:00:04
7 BR83GP 301 15:30:00

View File

@ -84,6 +84,36 @@ spec =
formatter.parse "000" . should_equal 0
formatter.parse "000.0" . should_equal 0.0
Test.specify "should parse booleans" <|
formatter = Data_Formatter
formatter.parse "True" . should_equal True
formatter.parse "False" . should_equal False
Test.specify "should allow custom boolean formats" <|
formatter = Data_Formatter true_values=["YES", "1", "true"] false_values=["NO", "0", "false"]
formatter.parse "YES" . should_equal True
formatter.parse "NO" . should_equal False
(Data_Formatter true_values=[] false_values=[]).parse "True" datatype=Boolean . should_equal Nothing
Test.specify "should parse dates" <|
formatter = Data_Formatter
formatter.parse "2022-01-01" . should_equal (Date.new 2022)
formatter.parse "2020-05-07" . should_equal (Date.new 2020 5 7)
formatter.parse "1999-01-01 00:00:00" . should_equal (Date_Time.new 1999)
formatter.parse "1999-02-03 04:05:06" . should_equal (Date_Time.new 1999 2 3 4 5 6)
formatter.parse "1999-01-01 00:00" datatype=Date_Time . should_equal (Date_Time.new 1999)
formatter.parse "1999-02-03 04:05" . should_equal (Date_Time.new 1999 2 3 4 5 0)
formatter.parse "00:00:00" . should_equal (Time_Of_Day.new)
formatter.parse "17:34:59" . should_equal (Time_Of_Day.new 17 34 59)
formatter.parse "00:00" . should_equal (Time_Of_Day.new)
formatter.parse "17:34" datatype=Time_Of_Day . should_equal (Time_Of_Day.new 17 34)
formatter.parse "00:00:65" datatype=Time_Of_Day . should_equal Nothing
formatter.parse "30:00:65" datatype=Time_Of_Day . should_equal Nothing
formatter.parse "1999-01-01 00:00" datatype=Time_Of_Day . should_equal Nothing
formatter.parse "1999-01-01 00:00" datatype=Date . should_equal Nothing
formatter.parse "30:00:65" . should_equal "30:00:65"
Test.specify "should fallback to Text" <|
formatter = Data_Formatter
formatter.parse "Text" . should_equal "Text"