diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso index b4c9aec5ea50d..4f55202030660 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso @@ -506,8 +506,7 @@ type Date Date -> sign = Time_Utils.compare_to_localdate self that 0 == sign - _ -> - False + _ -> False ## PRIVATE week_days_between start end = diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java index 5d07340b6ce90..218a2031fee8b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java @@ -47,17 +47,43 @@ Object doBigInteger(EnsoBigInteger value) { return ctx.getBuiltins().number().getInteger(); } - @Specialization(guards = "isError(value)") - Object doError(Object value) { - return Context.get(this).getBuiltins().dataflowError(); + @Specialization(guards = {"interop.isDate(value)", "interop.isTime(value)"}) + Object doDateTime(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { + Context ctx = Context.get(this); + return ctx.getBuiltins().dateTime(); + } + + @Specialization( + guards = {"!interop.isDate(value)", "!interop.isTime(value)", "interop.isTimeZone(value)"}) + Object doTimeZone(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { + Context ctx = Context.get(this); + return ctx.getBuiltins().timeZone(); } - boolean isError(Object value) { - return TypesGen.isDataflowError(value); + @Specialization(guards = {"interop.isDate(value)", "!interop.isTime(value)"}) + Object doDate(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { + Context ctx = Context.get(this); + return ctx.getBuiltins().date(); + } + + @Specialization(guards = {"!interop.isDate(value)", "interop.isTime(value)"}) + Object doTime(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { + Context ctx = Context.get(this); + return ctx.getBuiltins().timeOfDay(); } - @Specialization(guards = "interop.hasMetaObject(value)") - Object doMetaObject(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { + @Specialization( + guards = { + "interop.hasMetaObject(value)", + "!types.hasType(value)", + "!interop.isDate(value)", + "!interop.isTime(value)", + "!interop.isTimeZone(value)" + }) + Object doMetaObject( + Object value, + @CachedLibrary(limit = "3") InteropLibrary interop, + @CachedLibrary(limit = "3") TypesLibrary types) { try { return interop.getMetaObject(value); } catch (UnsupportedMessageException e) { @@ -67,8 +93,11 @@ Object doMetaObject(Object value, @CachedLibrary(limit = "3") InteropLibrary int } } - @Specialization(guards = "types.hasType(value)") - Object doType(Object value, @CachedLibrary(limit = "3") TypesLibrary types) { + @Specialization(guards = {"types.hasType(value)", "!interop.isNumber(value)"}) + Object doType( + Object value, + @CachedLibrary(limit = "3") InteropLibrary interop, + @CachedLibrary(limit = "3") TypesLibrary types) { return types.getType(value); } diff --git a/test/Tests/src/Data/Time/Date_Spec.enso b/test/Tests/src/Data/Time/Date_Spec.enso index fe124dbba1b90..0a54db7386ff4 100644 --- a/test/Tests/src/Data/Time/Date_Spec.enso +++ b/test/Tests/src/Data/Time/Date_Spec.enso @@ -13,12 +13,12 @@ polyglot java import java.time.LocalDate polyglot java import java.time.format.DateTimeFormatter spec = - spec_with "Date" Date.new Date.parse Date.Date - spec_with "JavaScriptDate" js_date js_parse Date.Date - spec_with "JavaDate" java_date java_parse LocalDate - spec_with "JavaScriptArrayWithADate" js_array_date js_parse Date.Date + spec_with "Date" Date.new Date.parse + spec_with "JavaScriptDate" js_date js_parse + spec_with "JavaDate" java_date java_parse + spec_with "JavaScriptArrayWithADate" js_array_date js_parse -spec_with name create_new_date parse_date date_tpe = +spec_with name create_new_date parse_date date_tpe=Date.Date = Test.group name <| Test.specify "should create local date" <| diff --git a/test/Tests/src/Data/Time/Date_Time_Spec.enso b/test/Tests/src/Data/Time/Date_Time_Spec.enso index 05bebf06d799c..0b24492c1e7f1 100644 --- a/test/Tests/src/Data/Time/Date_Time_Spec.enso +++ b/test/Tests/src/Data/Time/Date_Time_Spec.enso @@ -14,10 +14,10 @@ polyglot java import java.time.ZoneOffset polyglot java import java.time.format.DateTimeFormatter spec = - spec_with "Date_Time" Date_Time.new Date_Time.parse datetime_tpe=Date_Time.Date_Time - spec_with "JavascriptDate" js_datetime js_parse datetime_tpe=ZonedDateTime nanoseconds_loss_in_precision=True - spec_with "JavaZonedDateTime" java_datetime java_parse datetime_tpe=ZonedDateTime - spec_with "JavascriptDataInArray" js_array_datetime js_parse datetime_tpe=ZonedDateTime nanoseconds_loss_in_precision=True + spec_with "Date_Time" Date_Time.new Date_Time.parse + spec_with "JavascriptDate" js_datetime js_parse nanoseconds_loss_in_precision=True + spec_with "JavaZonedDateTime" java_datetime java_parse + spec_with "JavascriptDataInArray" js_array_datetime js_parse nanoseconds_loss_in_precision=True Test.group "Date_Time equality" <| Test.specify "should work with values coming from various sources" <| @@ -32,7 +32,7 @@ spec = d3 . should_equal d4 d4 . should_equal d5 -spec_with name create_new_datetime parse_datetime datetime_tpe nanoseconds_loss_in_precision=False = +spec_with name create_new_datetime parse_datetime datetime_tpe=Date_Time.Date_Time nanoseconds_loss_in_precision=False = Test.group name <| Test.specify "should create time" <| diff --git a/test/Tests/src/Data/Time/Time_Of_Day_Spec.enso b/test/Tests/src/Data/Time/Time_Of_Day_Spec.enso index 5f3bda48d0c03..5ee20b93ebf44 100644 --- a/test/Tests/src/Data/Time/Time_Of_Day_Spec.enso +++ b/test/Tests/src/Data/Time/Time_Of_Day_Spec.enso @@ -9,10 +9,10 @@ polyglot java import java.time.LocalTime polyglot java import java.time.format.DateTimeFormatter spec = - specWith "Time_Of_Day" enso_time Time_Of_Day.parse Time_Of_Day.Time_Of_Day - specWith "JavaLocalTime" java_time java_parse LocalTime + specWith "Time_Of_Day" enso_time Time_Of_Day.parse + specWith "JavaLocalTime" java_time java_parse -specWith name create_new_time parse_time timeofday_tpe = +specWith name create_new_time parse_time timeofday_tpe=Time_Of_Day.Time_Of_Day = Test.group name <| Test.specify "should create local time" <| diff --git a/test/Tests/src/Data/Time/Time_Zone_Spec.enso b/test/Tests/src/Data/Time/Time_Zone_Spec.enso index 2ba488929c3dc..56768ae594d41 100644 --- a/test/Tests/src/Data/Time/Time_Zone_Spec.enso +++ b/test/Tests/src/Data/Time/Time_Zone_Spec.enso @@ -67,6 +67,6 @@ spec = Json.from_pairs [["type", "Time_Zone"], ["id", "UTC"]] Test.specify "should correctly determine the type of zone" <| zone = ZoneId.systemDefault - Meta.type_of zone . should_equal_type ZoneRegion + Meta.type_of zone . should_equal_type Time_Zone.Time_Zone main = Test.Suite.run_main spec diff --git a/test/Tests/src/Semantic/Case_Spec.enso b/test/Tests/src/Semantic/Case_Spec.enso index 2c513ccc537d2..41dfa93d1e721 100644 --- a/test/Tests/src/Semantic/Case_Spec.enso +++ b/test/Tests/src/Semantic/Case_Spec.enso @@ -88,6 +88,37 @@ spec = Test.group "Pattern Matches" <| case Any of Any -> Nothing _ -> Test.fail "Expected the Any constructor to match." + Test.specify "should be able to match on date/time values" <| + new_date = Date.new 2020 6 1 + new_date_time = Date_Time.new 2020 6 1 + new_time = Time_Of_Day.new 11 11 + new_zone = Time_Zone.system + + case new_date of + Date_Time.Date_Time -> Test.fail "Expected date value to match Date." + Time_Of_Day.Time_Of_Day -> Test.fail "Expected date value to match Date." + Date.Date -> Nothing + _ -> Test.fail "Expected date value to match Date." + + case new_date_time of + Date.Date -> Test.fail "Expected datetime value to match Date_Time." + Time_Of_Day.Time_Of_Day -> Test.fail "Expected datetime value to match Date_Time." + Date_Time.Date_Time -> Nothing + _ -> Test.fail "Expected datetime value to match Date_Time." + + case new_time of + Date.Date -> Test.fail "Expected time value to match Time_Of_Day." + Date_Time.Date_Time -> Test.fail "Expected time value to match Time_Of_Day." + Time_Of_Day.Time_Of_Day -> Nothing + _ -> Test.fail "Expected time value to match Time_Of_Day." + + case new_zone of + Date.Date -> Test.fail "Expected timezone value to match Time_Zone." + Date_Time.Date_Time -> Test.fail "Expected timezone to match Time_Zone." + Time_Of_Day.Time_Of_Day -> Test.fail "Expected timezone to match Time_Zone." + Time_Zone.Time_Zone -> Nothing + _ -> Test.fail "Expected timezone value to match Time_Zone." + Test.specify "should be able to match on literal values" <| value_1 = 42 value_2 = "foo" @@ -112,8 +143,6 @@ spec = Test.group "Pattern Matches" <| "ę" -> Test.fail "Expected value to match constant." '\u0065\u{301}' -> Nothing _ -> Test.fail "Expected value to match constant." - - Test.specify "should be able to match on literal values nested in constructors" <| value_1 = Cons 42 Nil value_2 = Cons (Cons 42 Nil) Nil diff --git a/test/Tests/src/Semantic/Meta_Spec.enso b/test/Tests/src/Semantic/Meta_Spec.enso index 13f047a8d7c6f..7df530bf88f2b 100644 --- a/test/Tests/src/Semantic/Meta_Spec.enso +++ b/test/Tests/src/Semantic/Meta_Spec.enso @@ -127,6 +127,8 @@ spec = Test.group "Meta-Value Manipulation" <| (Meta.type_of Time_Of_Day.now) . should_not_equal_type Date.Date (Meta.type_of Date_Time.now.zone) . should_equal_type Time_Zone.Time_Zone (Meta.type_of Date_Time.now.zone) . should_not_equal_type Date.Date + (Meta.type_of Time_Zone.local) . should_equal_type Time_Zone.Time_Zone + (Meta.type_of Time_Zone.system) . should_equal_type Time_Zone.Time_Zone list = ArrayList.new list.add 123 @@ -145,9 +147,10 @@ spec = Test.group "Meta-Value Manipulation" <| location_pending = case Platform.os of Platform.Windows -> "This test is disabled on Windows until issue 1561 is fixed." _ -> Nothing + Test.specify "should allow to get the source location of a frame" pending=location_pending <| src = Meta.get_source_location 0 - loc = "Meta_Spec.enso:149:15-40" + loc = "Meta_Spec.enso:152:15-40" src.take (Last loc.length) . should_equal loc Test.specify "should allow to get qualified type names of values" <|