From 68f9fce21a5e941eaa036e11bf709e7540de3c62 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 17 Aug 2022 11:34:31 +0200 Subject: [PATCH] Use Java's LocalDate for parsing date in tests (#3650) Rather than using `Date.parse`, which is already being tested in other tests, we use `LocalDate.parse`. Making use of a helper class to mitigate API differences. --- test/Tests/src/Data/Time/Date_Spec.enso | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/Tests/src/Data/Time/Date_Spec.enso b/test/Tests/src/Data/Time/Date_Spec.enso index 2694c1b834..99a28570f2 100644 --- a/test/Tests/src/Data/Time/Date_Spec.enso +++ b/test/Tests/src/Data/Time/Date_Spec.enso @@ -9,12 +9,13 @@ import Standard.Base.Data.Time.Zone import Standard.Test polyglot java import java.time.LocalDate +polyglot java import java.time.format.DateTimeFormatter spec = specWith "Date" Date.new Date.parse specWith "JavaScriptDate" js_date js_parse - specWith "JavaDate" java_date Date.parse - specWith "JavaScriptArrayWithADate" js_array_date Date.parse + specWith "JavaDate" java_date java_parse + specWith "JavaScriptArrayWithADate" js_array_date js_parse specWith name create_new_date parse_date = Test.group name <| @@ -150,11 +151,15 @@ js_parse text format=Nothing = js_date year month=1 day=1 = Panic.catch Any (js_date_impl year month day) (err -> Error.throw (Time.Time_Error err.payload.cause)) - js_array_date year month=1 day=1 = arr = Panic.catch Any (js_array_dateCreate year month day) (err -> Error.throw (Time.Time_Error err.payload.cause)) arr.at(0) +java_parse date_text pattern=Nothing = + if pattern == Nothing then Panic.catch Polyglot_Error (LocalDate.parse date_text) (err -> Error.throw (Time.Time_Error err.payload.cause.getMessage)) else + formatter = DateTimeFormatter.ofPattern(pattern) + Panic.catch Polyglot_Error (LocalDate.parse date_text formatter) (err -> Error.throw (Time.Time_Error err.payload.cause.getMessage)) + java_date year month=1 day=1 = Panic.catch Any (LocalDate.of year month day) (err -> Error.throw (Time.Time_Error <| err.payload.to_display_text.drop (Text_Sub_Range.First 16)))