mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 17:34:10 +03:00
DataFormatter should infer datetime from values without seconds (#3668)
Fixes https://www.pivotaltracker.com/story/show/183033133
This commit is contained in:
parent
d7ebc4a338
commit
e6e4692692
@ -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.
|
||||
|
||||
|
@ -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,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
|
||||
|
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user