From a20d43390e1d233797cac124d5a1a7888ecaef29 Mon Sep 17 00:00:00 2001 From: James Dunkerley Date: Fri, 26 Aug 2022 16:47:58 +0100 Subject: [PATCH] Adding DateTime part functions (#3669) - Added `Zone`, `Date_Time` and `Time_Of_Day` to `Standard.Base`. - Renamed `Zone` to `Time_Zone`. - Added `century`. - Added `is_leap_year`. - Added `length_of_year`. - Added `length_of_month`. - Added `quarter`. - Added `day_of_year`. - Added `Day_Of_Week` type and `day_of_week` function. - Updated `week_of_year` to support ISO. # Important Notes - Had to pass locale to formatter for date/time tests to work on my PC. - Changed default of `week_of_year` to use ISO. --- CHANGELOG.md | 7 +- .../Base/0.0.0-dev/src/Data/Time.enso | 9 -- .../Base/0.0.0-dev/src/Data/Time/Date.enso | 92 ++++++++----- .../0.0.0-dev/src/Data/Time/Date_Time.enso | 121 +++++++++++------- .../0.0.0-dev/src/Data/Time/Day_Of_Week.enso | 57 +++++++++ .../0.0.0-dev/src/Data/Time/Duration.enso | 4 +- .../0.0.0-dev/src/Data/Time/Time_Of_Day.enso | 69 +++++----- .../Data/Time/{Zone.enso => Time_Zone.enso} | 73 ++++++----- .../Base/0.0.0-dev/src/Error/Common.enso | 10 ++ .../lib/Standard/Base/0.0.0-dev/src/Main.enso | 8 ++ .../Base/0.0.0-dev/src/Network/Http.enso | 5 +- .../Base/0.0.0-dev/src/System/File.enso | 1 - .../Standard/Examples/0.0.0-dev/src/Main.enso | 3 +- .../src/Data_Science/Date_And_Time.enso | 13 +- .../src/Data/Column_Type_Selection.enso | 5 +- .../0.0.0-dev/src/Data/Data_Formatter.enso | 3 - .../lib/Standard/Test/0.0.0-dev/src/Main.enso | 1 - .../node/callable/InvokeMethodNode.java | 4 +- .../callable/resolver/HostMethodCallNode.java | 12 +- .../interpreter/runtime/builtin/Builtins.java | 18 +-- .../interpreter/runtime/data/EnsoDate.java | 2 +- .../runtime/data/EnsoDateTime.java | 12 +- .../runtime/data/EnsoTimeOfDay.java | 2 +- .../data/{EnsoZone.java => EnsoTimeZone.java} | 29 ++--- .../enso/interpreter/runtime/type/Types.java | 4 +- .../dsl/builtins/TypeWithKind.java | 2 +- .../main/java/org/enso/base/Time_Utils.java | 17 +++ test/Table_Tests/src/Data_Formatter_Spec.enso | 12 +- .../Table_Tests/src/Delimited_Write_Spec.enso | 1 - test/Table_Tests/src/Parse_Values_Spec.enso | 2 - .../src/Table_Time_Of_Day_Spec.enso | 2 - test/Table_Tests/src/Table_Time_Spec.enso | 2 - test/Tests/src/Data/Time/Date_Part_Spec.enso | 99 ++++++++++++++ test/Tests/src/Data/Time/Date_Spec.enso | 55 ++++---- .../{Time_Spec.enso => Date_Time_Spec.enso} | 105 +++++++-------- .../Tests/src/Data/Time/Day_Of_Week_Spec.enso | 55 ++++++++ test/Tests/src/Data/Time/Duration_Spec.enso | 2 - test/Tests/src/Data/Time/Spec.enso | 14 +- .../Tests/src/Data/Time/Time_Of_Day_Spec.enso | 28 ++-- .../{Zone_Spec.enso => Time_Zone_Spec.enso} | 35 +++-- 40 files changed, 635 insertions(+), 360 deletions(-) delete mode 100644 distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time.enso create mode 100644 distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Day_Of_Week.enso rename distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/{Zone.enso => Time_Zone.enso} (56%) rename engine/runtime/src/main/java/org/enso/interpreter/runtime/data/{EnsoZone.java => EnsoTimeZone.java} (78%) create mode 100644 test/Tests/src/Data/Time/Date_Part_Spec.enso rename test/Tests/src/Data/Time/{Time_Spec.enso => Date_Time_Spec.enso} (79%) create mode 100644 test/Tests/src/Data/Time/Day_Of_Week_Spec.enso rename test/Tests/src/Data/Time/{Zone_Spec.enso => Time_Zone_Spec.enso} (70%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 831cbed7d2..c162797881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,7 @@ "zombie" state, where processes were started but not visible to user. They could cause issues with starting further IDE instances. - [New nodes are created in the project source when the searcher is opened - and a new node is created.][5250] + and a new node is created.][3645] #### EnsoGL (rendering engine) @@ -185,6 +185,7 @@ - [Expanded `Table.at` to support index access and added `Table.column_count` method.][3644] - [Removed `Array.set_at`.][3634] +- [Added various date part functions to `Date` and `Date_Time`.][3669] [debug-shortcuts]: https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug @@ -287,11 +288,13 @@ [3617]: https://github.com/enso-org/enso/pull/3617 [3628]: https://github.com/enso-org/enso/pull/3628 [3629]: https://github.com/enso-org/enso/pull/3629 +[3641]: https://github.com/enso-org/enso/pull/3641 [3643]: https://github.com/enso-org/enso/pull/3643 [3644]: https://github.com/enso-org/enso/pull/3644 +[3645]: https://github.com/enso-org/enso/pull/3645 [3648]: https://github.com/enso-org/enso/pull/3648 -[5250]: https://github.com/enso-org/enso/pull/5250 [3634]: https://github.com/enso-org/enso/pull/3634 +[3669]: https://github.com/enso-org/enso/pull/3669 #### Enso Compiler diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time.enso deleted file mode 100644 index 4b911e44be..0000000000 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time.enso +++ /dev/null @@ -1,9 +0,0 @@ -type Time_Error - - ## UNSTABLE - - An error produced while working with time- and date-related methods. - - Arguments: - - error_message: The message for the error. - type Time_Error error_message 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 af68afcd41..674e074ca7 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 @@ -1,13 +1,13 @@ from Standard.Base import all -import Standard.Base.Data.Time -import Standard.Base.Data.Time.Date_Time import Standard.Base.Data.Time.Duration -import Standard.Base.Data.Time.Time_Of_Day -import Standard.Base.Data.Time.Zone + import Standard.Base.Polyglot +from Standard.Base.Error.Common import Time_Error polyglot java import org.enso.base.Time_Utils +polyglot java import java.time.temporal.ChronoField +polyglot java import java.time.temporal.IsoFields ## Obtains the current date from the system clock in the system timezone. @@ -41,7 +41,7 @@ today = now > Example Create a new local date at Unix epoch. - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_new = Date.new 1970 @@ -50,7 +50,7 @@ today = now example_new = Date.new 1986 8 5 -new : Integer -> Integer -> Integer -> Date ! Time.Time_Error +new : Integer -> Integer -> Integer -> Date ! Time_Error new year (month = 1) (day = 1) = ## TODO This is left using the old error handling approach, because magically, changing this to the `catch_java` (which is now preferred way @@ -60,7 +60,7 @@ new year (month = 1) (day = 1) = https://github.com/enso-org/enso/pull/3559 Then this should be switched to use `Panic.catch_java`. Panic.recover Any (Date.internal_new year month day) . catch Any e-> case e of - Polyglot_Error err -> Error.throw (Time.Time_Error err.getMessage) + Polyglot_Error err -> Error.throw (Time_Error err.getMessage) ex -> ex ## ALIAS Date from Text @@ -96,41 +96,43 @@ new year (month = 1) (day = 1) = > Example Parse the date of 23rd December 2020. - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_parse = Date.parse "2020-12-23" > Example Recover from an error due to a wrong format. - import Standard.Base.Data.Time + from Standard.Base import Date + from Standard.Base.Error.Common import Time_Error - example_parse_err = Date.parse "my birthday" . catch Time.Time_Error _-> + example_parse_err = Date.parse "my birthday" . catch Time_Error _-> Date.new 2000 1 1 > Example Parse "1999-1-1" as Date using a custom format. - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_parse = Date.parse "1999-1-1" "yyyy-M-d" > Example Recover from the parse error. - import Standard.base.Data.Time + from Standard.Base import Date + from Standard.Base.Error.Common import Time_Error example_parse_err = date = Date.parse "1999-1-1" "yyyy-MM-dd" - date.catch Time.Time_Error (_->Date.new 2000 1 1) -parse : Text -> (Text | Nothing) -> Date ! Time.Time_Error + date.catch Time_Error (_->Date.new 2000 1 1) +parse : Text -> (Text | Nothing) -> Date ! Time_Error parse text pattern=Nothing = result = Panic.recover Any <| case pattern of Nothing -> Date.internal_parse text 0 Text -> Date.internal_parse text pattern - _ -> Panic.throw (Time.Time_Error "An invalid pattern was provided.") + _ -> Panic.throw (Time_Error "An invalid pattern was provided.") result . map_error <| case _ of - Polyglot_Error err -> Time.Time_Error err.getMessage + Polyglot_Error err -> Time_Error err.getMessage ex -> ex type Date @@ -154,7 +156,7 @@ type Date > Example Get the current year. - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_year = Date.now.year year : Integer @@ -174,7 +176,7 @@ type Date > Example Get the current day. - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_day = Date.now.day day : Integer @@ -184,6 +186,7 @@ type Date Arguments: - locale: the locale used to define the notion of weeks of year. + If no locale is provided, then the ISO 8601 week of year is used. ! Locale Dependency Note that this operation is locale-specific. It varies both by the @@ -193,8 +196,40 @@ type Date other hand, the first day of the week is Monday, and week 1 is the week containing the first Thursday of the year. Therefore it is important to properly specify the `locale` argument. - week_of_year : Locale.Locale -> Integer - week_of_year self locale=Locale.default = Time_Utils.week_of_year_localdate self locale.java_locale + week_of_year : (Locale.Locale | Nothing) -> Integer + week_of_year self locale=Nothing = + if locale.is_nothing then Time_Utils.get_field_as_localdate self IsoFields.WEEK_OF_WEEK_BASED_YEAR else + Time_Utils.week_of_year_localdate self locale.java_locale + + ## Returns if the date is in a leap year. + is_leap_year : Boolean + is_leap_year self = Time_Utils.is_leap_year self + + ## Returns the number of days in the year represented by this date. + length_of_year : Integer + length_of_year self = if self.is_leap_year then 366 else 365 + + ## Returns the century of the date. + century : Integer + century self = if self.year > 0 then (self.year - 1).div 100 + 1 else + Error.throw (Illegal_Argument_Error "Century can only be given for AD years.") + + ## Returns the quarter of the year the date falls into. + quarter : Integer + quarter self = Time_Utils.get_field_as_localdate self IsoFields.QUARTER_OF_YEAR + + ## Returns the number of days in the month represented by this date. + length_of_month : Integer + length_of_month self = Time_Utils.length_of_month self + + ## Returns the day of the year. + day_of_year : Integer + day_of_year self = Time_Utils.get_field_as_localdate self ChronoField.DAY_OF_YEAR + + ## Returns the day of the week. + day_of_week : Day_Of_Week + day_of_week self = + Day_Of_Week.from (Time_Utils.get_field_as_localdate self ChronoField.DAY_OF_WEEK) Day_Of_Week.Monday ## ALIAS Date to Time @@ -207,12 +242,11 @@ type Date > Example Convert this date to midnight UTC time. - import Standard.Base.Data.Time.Time_Of_Day - import Standard.Base.Data.Time.Zone + from Standard.Base import Date, Time_Of_Day, Time_Zone - example_to_time = Date.new 2020 2 3 . to_time Time_Of_Day.new Zone.utc - to_time : Time_Of_Day -> Zone -> Date_Time - to_time self time_of_day (zone=Zone.system) = self.to_time_builtin time_of_day zone + example_to_time = Date.new 2020 2 3 . to_time Time_Of_Day.new Time_Zone.utc + to_time : Time_Of_Day -> Time_Zone -> Date_Time + to_time self time_of_day (zone=Time_Zone.system) = self.to_time_builtin time_of_day zone ## Add the specified amount of time to this instant to get another date. @@ -226,7 +260,7 @@ type Date example_add = Date.new 2020 + 6.months + : Duration -> Date - + self amount = if amount.is_time then Error.throw (Time.Time_Error "Date does not support time intervals") else + + self amount = if amount.is_time then Error.throw (Time_Error "Date does not support time intervals") else (Time_Utils.date_adjust self Time_Utils.AdjustOp.PLUS amount.internal_period) . internal_local_date ## Subtract the specified amount of time from this instant to get another @@ -238,12 +272,12 @@ type Date > Example Subtract 7 days from a local date. - import Standard.Base.Data.Time.Date + from Standard.Base import Date import Standard.Base.Data.Time.Duration example_subtract = Date.new 2020 - 7.days - : Duration -> Date - - self amount = if amount.is_time then Error.throw (Time.Time_Error "Date does not support time intervals") else + - self amount = if amount.is_time then Error.throw (Time_Error "Date does not support time intervals") else (Time_Utils.date_adjust self Time_Utils.AdjustOp.MINUS amount.internal_period) . internal_local_date @@ -268,7 +302,7 @@ type Date > Example Format "2020-06-02" as "2 June 2020" - import Standard.Base.Data.Time.Date + from Standard.Base import Date example_format = Date.new 2020 6 2 . format "d MMMM yyyy" diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso index 472661f896..b102345f2d 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso @@ -1,12 +1,12 @@ from Standard.Base import all -from Standard.Base.Data.Time import Time_Error import Standard.Base.Data.Time.Duration -import Standard.Base.Data.Time.Time_Of_Day -import Standard.Base.Data.Time.Zone +from Standard.Base.Error.Common import Time_Error polyglot java import java.time.format.DateTimeFormatter -polyglot java import java.time.ZonedDateTime +polyglot java import java.time.temporal.ChronoField +polyglot java import java.time.temporal.IsoFields + polyglot java import org.enso.base.Time_Utils ## ALIAS Current Time @@ -16,7 +16,7 @@ polyglot java import org.enso.base.Time_Utils > Example Get the current time - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_now = Date_Time.now now : Date_Time @@ -40,20 +40,18 @@ now = @Builtin_Method "Date_Time.now" > Example Create a new zoned date time at Unix epoch. - import Standard.Base.Data.Time.Date_Time - import Standard.Base.Data.Time.Zone + from Standard.Base import Date_Time, Time_Zone - example_new = Date_Time.new 1970 (zone = Zone.utc) + example_new = Date_Time.new 1970 (zone = Time_Zone.utc) > Example Get the 5 August 1986 at midnight. - import Standard.Base.Data.Time.Date_Time - import Standard.Base.Data.Time.Zone + from Standard.Base import Date_Time, Time_Zone example_new = Date_Time.new 1986 8 5 -new : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Zone -> Date_Time ! Time_Error -new year (month = 1) (day = 1) (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) (zone = Zone.system) = +new : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Time_Zone -> Date_Time ! Time_Error +new year (month = 1) (day = 1) (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) (zone = Time_Zone.system) = Panic.catch_java Any (Date_Time.new_builtin year month day hour minute second nanosecond zone) java_exception-> Error.throw (Time_Error java_exception.getMessage) @@ -89,49 +87,49 @@ new year (month = 1) (day = 1) (hour = 0) (minute = 0) (second = 0) (nanosecond > Example Parse UTC time. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "2020-10-01T04:11:12Z" > Example Parse UTC-04:00 time. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "2020-10-01T04:11:12-04:00" > Example Parse UTC-04:00 time specifying New York timezone. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "2020-10-01T04:11:12-04:00[America/New_York]" > Example Parse UTC-04:00 time with nanoseconds. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "2020-10-01T04:11:12.177528-04:00" > Example Recover from the parse error. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "2020-10-01" . catch Time_Error (_->Date_Time.now) > Example Parse "2020-05-06 04:30:20" as Date_Time - import Standard.Base.Data.Time + from Standard.Base import Date_Time - example_parse = Date.parse "2020-05-06 04:30:20" "yyyy-MM-dd HH:mm:ss" + example_parse = Date_Time.parse "2020-05-06 04:30:20" "yyyy-MM-dd HH:mm:ss" > Example Parse "06 of May 2020 at 04:30AM" as Date_Tme - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_parse = Date_Time.parse "06 of May 2020 at 04:30AM" "dd 'of' MMMM yyyy 'at' hh:mma" @@ -164,7 +162,7 @@ type Date_Time > Example Get the current year. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_year = Date_Time.now.year year : Integer @@ -175,7 +173,7 @@ type Date_Time > Example Get the current month. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_month = Date_Time.now.month month : Integer @@ -186,7 +184,7 @@ type Date_Time > Example Get the current day. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_day = Date_Time.now.day day : Integer @@ -197,7 +195,7 @@ type Date_Time > Example Get the current hour. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_hour = Date_Time.now.hour hour : Integer @@ -208,7 +206,7 @@ type Date_Time > Example Get the current minute. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_minute = Date_Time.now.minute minute : Integer @@ -219,7 +217,7 @@ type Date_Time > Example Get the current second. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_second = Date_Time.now.second second : Integer @@ -230,7 +228,7 @@ type Date_Time > Example Get the current nanosecond. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_nanosecond = Date_Time.now.nanosecond nanosecond : Integer @@ -241,10 +239,10 @@ type Date_Time > Example Get the current timezone. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_zone = Date_Time.now.zone - zone : Zone + zone : Time_Zone zone self = @Builtin_Method "Date_Time.zone" ## Return the number of seconds from the Unix epoch. @@ -252,7 +250,7 @@ type Date_Time > Example Get the current number of seconds from the Unix epoch. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_epoch = Date_Time.now.to_epoch_seconds to_epoch_seconds : Integer @@ -263,7 +261,7 @@ type Date_Time > Example Get the current number of milliseconds from the unix epoch. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_epoch = Date_Time.now.to_epoch_milliseconds to_epoch_milliseconds : Integer @@ -275,7 +273,7 @@ type Date_Time > Example Convert the current time to a time of day. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_time_of_day = Date_Time.now.time_of_day time_of_day : Time_Of_Day @@ -285,6 +283,7 @@ type Date_Time Arguments: - locale: the locale used to define the notion of weeks of year. + If no locale is provided, then the ISO 8601 week of year is used. ! Locale Dependency Note that this operation is locale-specific. It varies both by the @@ -294,8 +293,39 @@ type Date_Time other hand, the first day of the week is Monday, and week 1 is the week containing the first Thursday of the year. Therefore it is important to properly specify the `locale` argument. - week_of_year : Locale.Locale -> Integer - week_of_year self locale=Locale.default = Time_Utils.week_of_year_zoneddatetime self locale.java_locale + week_of_year : (Locale.Locale | Nothing) -> Integer + week_of_year self locale=Nothing = + if locale.is_nothing then Time_Utils.get_field_as_zoneddatetime self IsoFields.WEEK_OF_WEEK_BASED_YEAR else + Time_Utils.week_of_year_zoneddatetime self locale.java_locale + + ## Returns if the date is in a leap year. + is_leap_year : Boolean + is_leap_year self = self.date.is_leap_year + + ## Returns the number of days in the year represented by this date. + length_of_year : Integer + length_of_year self = self.date.length_of_year + + ## Returns the century of the date. + century : Integer + century self = self.date.century + + ## Returns the quarter of the year the date falls into. + quarter : Integer + quarter self = Time_Utils.get_field_as_zoneddatetime self IsoFields.QUARTER_OF_YEAR + + ## Returns the number of days in the month represented by this date. + length_of_month : Integer + length_of_month self = self.date.length_of_month + + ## Returns the day of the year. + day_of_year : Integer + day_of_year self = Time_Utils.get_field_as_zoneddatetime self ChronoField.DAY_OF_YEAR + + ## Returns the day of the week. + day_of_week : Day_Of_Week + day_of_week self = + Day_Of_Week.from (Time_Utils.get_field_as_zoneddatetime self ChronoField.DAY_OF_WEEK) Day_Of_Week.Monday ## ALIAS Time to Date @@ -305,7 +335,7 @@ type Date_Time > Example Convert the current time to a date. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_date = Date_Time.now.date date : Date @@ -321,11 +351,10 @@ type Date_Time > Example Convert time instance to -04:00 timezone. - import Standard.Base.Data.Time.Date_Time - import Standard.Base.Data.Time.Zone + from Standard.Base import Date_Time, Time_Zone - example_at_zone = Date_Time.new 2020 . at_zone (Zone.new -4) - at_zone : Zone -> Date_Time + example_at_zone = Date_Time.new 2020 . at_zone (Time_Zone.new -4) + at_zone : Time_Zone -> Date_Time at_zone self zone = @Builtin_Method "Date_Time.at_zone" ## Add the specified amount of time to this instant to produce a new instant. @@ -336,7 +365,7 @@ type Date_Time > Example Add 15 years and 3 hours to a zoned date time. - import Standard.Base.Data.Time.Date_Time + from Standard.Base import Date_Time import Standard.Base.Data.Time.Duration example_plus = Date_Time.new 2020 + 15.years + 3.hours @@ -353,7 +382,7 @@ type Date_Time > Example Subtract 1 year and 9 months from a zoned date time. - import Standard.Base.Data.Time.Date_Time + from Standard.Base import Date_Time import Standard.Base.Data.Time.Duration example_minus = Date_Time.new 2020 - 1.year - 9.months @@ -366,7 +395,7 @@ type Date_Time > Example Convert the current time to text. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_to_text = Date_Time.now.to_text to_text : Text @@ -377,7 +406,7 @@ type Date_Time > Example Convert the current time to JSON. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_to_json = Date_Time.now.to_json to_json : Json.Object @@ -438,7 +467,7 @@ type Date_Time Format "2020-10-08T16:41:13+03:00[Europe/Moscow]" as "2020-10-08T16:41:13+03:00[Europe/Moscow]". - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_format = Date_Time.parse "2020-10-08T16:41:13+03:00[Europe/Moscow]" . format "yyyy-MM-dd'T'HH:mm:ssZZZZ'['VV']'" @@ -446,7 +475,7 @@ type Date_Time > Example Format "2020-10-08T16:41:13+03:00[Europe/Moscow]" as "Thursday October 8 4:41 PM". - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_format = Date_Time.parse "2020-10-08T16:41:13+03:00[Europe/Moscow]" . format "EEEE MMMM d h:mm a" @@ -455,7 +484,7 @@ type Date_Time Format "2020-10-08T16:41:13+03:00[Europe/Moscow]" as "Thu Oct 8 (16:41)". - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_format = Date_Time.parse "2020-10-08T16:41:13+03:00[Europe/Moscow]" . format "EEE MMM d (HH:mm)" diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Day_Of_Week.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Day_Of_Week.enso new file mode 100644 index 0000000000..710e56e39c --- /dev/null +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Day_Of_Week.enso @@ -0,0 +1,57 @@ +from Standard.Base import all + +type Day_Of_Week + type Sunday + + type Monday + + type Tuesday + + type Wednesday + + type Thursday + + type Friday + + type Saturday + + ## Convert the Day_Of_Week to an Integer + + Arguments: + - `first_day`: The first day of the week. + - `start_at_zero`: If True, first day of the week is 0 otherwise is 1. + to_integer : Day_Of_Week -> Boolean -> Integer + to_integer self first_day=Sunday start_at_zero=False = + day_number = case self of + Sunday -> 0 + Monday -> 1 + Tuesday -> 2 + Wednesday -> 3 + Thursday -> 4 + Friday -> 5 + Saturday -> 6 + + shifted = if first_day == Day_Of_Week.Sunday then day_number else + (day_number + 7 - (first_day.to_integer start_at_zero=True)) % 7 + + shifted + if start_at_zero then 0 else 1 + +## Convert from an integer to a Day_Of_Week + + Arguments: + - `that`: The first day of the week. + - `first_day`: The first day of the week. + - `start_at_zero`: If True, first day of the week is 0 otherwise is 1. +Day_Of_Week.from (that : Integer) (first_day:Day_Of_Week=Sunday) (start_at_zero:Boolean=False) = + shifted = if start_at_zero then that else that - 1 + + case (shifted < 0) || (shifted > 6) of + True -> + valid_range = if start_at_zero then "0-6" else "1-7" + message = "Invalid day of week (must be " + valid_range + ")." + Error.throw (Illegal_Argument_Error message) + False -> + day_number = if first_day == Day_Of_Week.Sunday then shifted else + (shifted + (first_day.to_integer start_at_zero=True)) % 7 + + [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday].at day_number diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso index d6066d02f6..fe632bb894 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso @@ -1,6 +1,4 @@ from Standard.Base import all - -import Standard.Base.Data.Time import Standard.Base.System polyglot java import java.time.Duration as Java_Duration @@ -17,8 +15,8 @@ polyglot java import org.enso.base.Time_Utils > Example An hour interval between two points in time. + from Standard.Base import Date_Time import Standard.Base.Data.Time.Duration - import Standard.Base.Data.Time.Date_Time example_between = Duration.between Date_Time.now (Date_Time.new 2010 10 20) between : Date_Time -> Date_Time -> Duration diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso index a96e6a8cb8..96b9ef0918 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso @@ -1,8 +1,7 @@ from Standard.Base import all -import Standard.Base.Data.Time import Standard.Base.Data.Time.Duration -import Standard.Base.Data.Time.Zone +from Standard.Base.Error.Common import Time_Error polyglot java import java.time.format.DateTimeFormatter polyglot java import java.time.Instant @@ -14,7 +13,7 @@ polyglot java import org.enso.base.Time_Utils > Example Get the current time in the default time zone. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_now = Time_Of_Day.now now : Time_Of_Day @@ -34,20 +33,20 @@ now = @Builtin_Method "Time_Of_Day.now" > Example Create a new local time at Unix epoch. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_epoch = Time_Of_Day.new > Example Get the local time at 9:30. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_epoch = Time_Of_Day.new hour=9 minute=30 -new : Integer -> Integer -> Integer -> Integer -> Time_Of_Day ! Time.Time_Error +new : Integer -> Integer -> Integer -> Integer -> Time_Of_Day ! Time_Error new (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) = Panic.catch_java Any (Time_Of_Day.new_builtin hour minute second nanosecond) java_exception-> - Error.throw (Time.Time_Error java_exception.getMessage) + Error.throw (Time_Error java_exception.getMessage) ## Obtains an instance of `Time_Of_Day` from a text such as "10:15". @@ -84,35 +83,35 @@ new (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) = > Example Get the time 15:05:30. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_parse = Time_Of_Day.parse "15:05:30" > Example Recover from the parse error. - import Standard.Base.Data.Time - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day + from Standard.Base.Error.Common import Time_Error - example_parse = Time_Of_Day.parse "half twelve" . catch Time.Time_Error _-> + example_parse = Time_Of_Day.parse "half twelve" . catch Time_Error _-> Time_Of_Day.new > Example Parse "04:30:20" as Time_Of_Day. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_parse = Time_Of_Day.parse "04:30:20" "HH:mm:ss" > Example Parse "4:30AM" as Time_Of_Day - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_parse = Time_Of_Day.parse "4:30AM" "h:mma" -parse : Text -> Text | Nothing -> Locale -> Time_Of_Day ! Time.Time_Error +parse : Text -> Text | Nothing -> Locale -> Time_Of_Day ! Time_Error parse text pattern=Nothing locale=Locale.default = - Panic.catch_java Any handler=(java_exception -> Error.throw (Time.Time_Error java_exception.getMessage)) <| + Panic.catch_java Any handler=(java_exception -> Error.throw (Time_Error java_exception.getMessage)) <| case pattern of Nothing -> Time_Of_Day.parse_builtin text Text -> Time_Utils.parse_time text pattern locale.java_locale @@ -134,7 +133,7 @@ type Time_Of_Day > Example Get the current hour. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_hour = Time_Of_Day.now.hour hour : Integer @@ -145,7 +144,7 @@ type Time_Of_Day > Example Get the current minute. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_minute = Time_Of_Day.now.minute minute : Integer @@ -156,7 +155,7 @@ type Time_Of_Day > Example Get the current second. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_second = Time_Of_Day.now.second second : Integer @@ -167,7 +166,7 @@ type Time_Of_Day > Example Get the current nanosecond. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_nanosecond = Time_Of_Day.now.nanosecond nanosecond : Integer @@ -178,7 +177,7 @@ type Time_Of_Day > Example Convert the current time into elapsed seconds in the day. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_to_seconds = Time_Of_Day.now.to_seconds to_seconds : Integer @@ -193,11 +192,11 @@ type Time_Of_Day > Example Convert local time to 1st January 2020 12:30 at system timezone. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_to_time = Time_Of_Day.new 12 30 . to_time (Date.new 2020) - to_time : Date -> Zone -> Time - to_time self date (zone=Zone.system) = self.to_time_builtin date zone + to_time : Date -> Time_Zone -> Time + to_time self date (zone=Time_Zone.system) = self.to_time_builtin date zone ## Add the specified amount of time to this instant to get a new instant. @@ -206,12 +205,12 @@ type Time_Of_Day > Example + from Standard.Base import Time_Of_Day import Standard.Base.Data.Time.Duration - import Standard.Base.Data.Time.Time_Of_Day example_plus = Time_Of_Day.new + 3.seconds + : Duration -> Time_Of_Day - + self amount = if amount.is_date then Error.throw (Time.Time_Error "Time_Of_Day does not support date intervals") else + + self amount = if amount.is_date then Error.throw (Time_Error "Time_Of_Day does not support date intervals") else Time_Utils.time_adjust self Time_Utils.AdjustOp.PLUS amount.internal_duration ## Subtract the specified amount of time from this instant to get a new @@ -223,12 +222,12 @@ type Time_Of_Day > Example Subtract 12 hours from a local time. + from Standard.Base import Time_Of_Day import Standard.Base.Data.Time.Duration - import Standard.Base.Data.Time.Time_Of_Day example_minus = Time_Of_Day.now - 12.hours - : Duration -> Time_Of_Day - - self amount = if amount.is_date then Error.throw (Time.Time_Error "Time_Of_Day does not support date intervals") else + - self amount = if amount.is_date then Error.throw (Time_Error "Time_Of_Day does not support date intervals") else Time_Utils.time_adjust self Time_Utils.AdjustOp.MINUS amount.internal_duration ## Format this time of day as text using the default formatter. @@ -236,7 +235,7 @@ type Time_Of_Day > Example Convert the current time to text. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_to_text = Time_Of_Day.now.to_text to_text : Text @@ -247,7 +246,7 @@ type Time_Of_Day > Example Convert the current time to JSON. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_to_json = Time_Of_Day.now.to_text to_json : Json.Object @@ -268,35 +267,35 @@ type Time_Of_Day > Example Format "16:21:10" as "16:21:00.1234" - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_format = Time_Of_Day.new 16 21 10 . format "HH:mm:ss.SSSS" > Example Format "16:21:10" as "16:21:00.123456789" - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_format = Time_Of_Day.new 16 21 10 . format "HH:mm:ss.n" > Example Format "16:21:10" as "4:21pm" - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_format = Time_Of_Day.new 16 21 10 . format "h:mma" > Example Format "16:21:10" as "04:21:10pm" - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_format = Time_Of_Day.new 16 21 10 . format "hh:mm:ssa" > Example Format "16:21:10" as "hour:4" - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_format = Time_Of_Day.new 16 21 10 . format "'hour:'h" format : Text -> Text @@ -310,7 +309,7 @@ type Time_Of_Day > Example Compare two times for their ordering. - import Standard.Base.Data.Time.Time_Of_Day + from Standard.Base import Time_Of_Day example_compare_to = time_1 = Time_Of_Day.new hour=2 minute=30 diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Zone.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso similarity index 56% rename from distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Zone.enso rename to distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso index 44d070819b..ad0504e851 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Zone.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso @@ -1,6 +1,5 @@ from Standard.Base import all - -import Standard.Base.Data.Time +from Standard.Base.Error.Common import Time_Error polyglot java import java.time.ZoneId polyglot java import java.time.ZoneOffset @@ -11,11 +10,11 @@ polyglot java import org.enso.base.Time_Utils > Example Get the system default timezone. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_system = Zone.system -system : Zone -system = @Builtin_Method "Zone.system" + example_system = Time_Zone.system +system : Time_Zone +system = @Builtin_Method "Time_Zone.system" ## ALIAS Current Time Zone @@ -24,10 +23,10 @@ system = @Builtin_Method "Zone.system" > Example Get the system's local timezone. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_local = Zone.local -local : Zone + example_local = Time_Zone.local +local : Time_Zone local = system ## ALIAS UTC Time Zone @@ -37,13 +36,13 @@ local = system > Example Get the UTC timezone. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_utc = Zone.utc -utc : Zone + example_utc = Time_Zone.utc +utc : Time_Zone utc = parse "UTC" -## Obtains an instance of `Zone` using an offset in hours, minutes and seconds +## Obtains an instance of `Time_Zone` using an offset in hours, minutes and seconds from the UTC zone. Arguments: @@ -56,16 +55,16 @@ utc = parse "UTC" > Example Get time zone 1 hour 1 minute and 50 seconds from UTC. - import Standard.Base.Data.Time.Zone + from Standard.Base import Zone example_new = Zone.new 1 1 50 -new : Integer -> Integer -> Integer -> Zone +new : Integer -> Integer -> Integer -> Time_Zone new (hours = 0) (minutes = 0) (seconds = 0) = - Zone.new_builtin hours minutes seconds + Time_Zone.new_builtin hours minutes seconds ## ALIAS Time Zone from Text - This method parses the ID producing a `Zone`. + This method parses the ID producing a `Time_Zone`. Arguments: - text: The text representing a zone identifier. @@ -73,36 +72,36 @@ new (hours = 0) (minutes = 0) (seconds = 0) = > Example Get Central European Time. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_parse = Zone.parse "CET" + example_parse = Time_Zone.parse "CET" > Example Get Moscow time. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_parse = Zone.parse "Europe/Moscow" + example_parse = Time_Zone.parse "Europe/Moscow" > Example Get time zone -06:00. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_parse = Zone.parse "-06:00" + example_parse = Time_Zone.parse "-06:00" > Example Get custom offset +03:02:01 of 3 hours 2 minutes an 1 second. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_parse = Zone.parse "+03:02:01" -parse : Text -> Zone + example_parse = Time_Zone.parse "+03:02:01" +parse : Text -> Time_Zone parse text = - Panic.catch_java Any handler=(java_exception -> Error.throw (Time.Time_Error java_exception.getMessage)) <| - Zone.parse_builtin text + Panic.catch_java Any handler=(java_exception -> Error.throw (Time_Error java_exception.getMessage)) <| + Time_Zone.parse_builtin text -type Zone +type Time_Zone ## PRIVATE @@ -115,30 +114,30 @@ type Zone A time zone can be eiter offset-based like "-06:00" or id-based like "Europe/Paris". @Builtin_Type - type Zone + type Time_Zone ## Get the unique timezone ID. > Example Get the unique identifier for your system's current timezone. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_zone_id = Zone.system.zone_id + example_zone_id = Time_Zone.system.zone_id zone_id : Text - zone_id self = @Builtin_Method "Zone.zone_id" + zone_id self = @Builtin_Method "Time_Zone.zone_id" ## Convert the time zone to JSON. > Example Convert your system's current timezone to JSON. - import Standard.Base.Data.Time.Zone + from Standard.Base import Time_Zone - example_to_json = Zone.system.to_json + example_to_json = Time_Zone.system.to_json to_json : Json.Object - to_json self = Json.from_pairs [["type", "Zone"], ["id", self.zone_id]] + to_json self = Json.from_pairs [["type", "Time_Zone"], ["id", self.zone_id]] ## Compares two Zones for equality. - == : Zone -> Boolean + == : Time_Zone -> Boolean == self that = Time_Utils.equals_zone self that diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso index 5eaf0be178..e1621a0d71 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso @@ -645,3 +645,13 @@ Unimplemented_Error.to_display_text self = "An implementation is missing: " + se example_unimplemented = Errors.unimplemented unimplemented : Text -> Void unimplemented message="" = Panic.throw (Unimplemented_Error message) + +type Time_Error + + ## UNSTABLE + + An error produced while working with time- and date-related methods. + + Arguments: + - error_message: The message for the error. + type Time_Error error_message diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso index 705ade9314..b9cc784768 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso @@ -25,6 +25,10 @@ import project.Data.Text.Matching import project.Data.Text.Text_Ordering import project.Data.Text.Span import project.Data.Time.Date +import project.Data.Time.Date_Time +import project.Data.Time.Time_Of_Day +import project.Data.Time.Time_Zone +import project.Data.Time.Day_Of_Week import project.Data.Vector import project.Error.Common import project.Error.Problem_Behavior @@ -60,6 +64,10 @@ export project.Data.Statistics.Rank_Method export project.Data.Text.Regex export project.Data.Text.Regex.Mode as Regex_Mode export project.Data.Time.Date +export project.Data.Time.Date_Time +export project.Data.Time.Time_Of_Day +export project.Data.Time.Time_Zone +export project.Data.Time.Day_Of_Week export project.Data.Vector export project.Error.Problem_Behavior export project.IO diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/Http.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/Http.enso index 55c2c6df90..6c04c909d3 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/Http.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/Http.enso @@ -1,7 +1,8 @@ from Standard.Base import all import Standard.Base.Data.Time.Duration -import Standard.Base.Data.Time +from Standard.Base.Error.Common import Time_Error + import Standard.Base.Network.Http.Form import Standard.Base.Network.Http.Header import Standard.Base.Network.Http.Method @@ -658,7 +659,7 @@ type Http internal_http_client self = builder = HttpClient.newBuilder # timeout - if self.timeout.is_date then Panic.throw (Time.Time_Error "Connection timeout does not support date intervals") else + if self.timeout.is_date then Panic.throw (Time_Error "Connection timeout does not support date intervals") else builder.connectTimeout self.timeout.internal_duration # redirect redirect = HttpClient.Redirect diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso index eafcf0d0f0..e170df5750 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso @@ -6,7 +6,6 @@ import Standard.Base.Data.Text.Text_Sub_Range from Standard.Base.Error.Problem_Behavior import Report_Warning import Standard.Base.Runtime.Resource from Standard.Base.Runtime.Resource import Managed_Resource -from Standard.Base.Data.Time import Time polyglot java import org.enso.base.Array_Utils polyglot java import org.enso.base.Encoding_Utils diff --git a/distribution/lib/Standard/Examples/0.0.0-dev/src/Main.enso b/distribution/lib/Standard/Examples/0.0.0-dev/src/Main.enso index aacedf3250..55f28f68ea 100644 --- a/distribution/lib/Standard/Examples/0.0.0-dev/src/Main.enso +++ b/distribution/lib/Standard/Examples/0.0.0-dev/src/Main.enso @@ -1,9 +1,8 @@ from Standard.Base import all -import Standard.Base.Data.Time.Date_Time +import Standard.Base.Data.Time.Duration import Standard.Base.Network.Http import Standard.Base.System.Platform -import Standard.Base.Data.Time.Duration import Standard.Base.Network.URI import Standard.Base.Data.Text.Regex.Engine.Default as Default_Engine diff --git a/distribution/lib/Standard/Searcher/0.0.0-dev/src/Data_Science/Date_And_Time.enso b/distribution/lib/Standard/Searcher/0.0.0-dev/src/Data_Science/Date_And_Time.enso index a18543ff55..b8df79459f 100644 --- a/distribution/lib/Standard/Searcher/0.0.0-dev/src/Data_Science/Date_And_Time.enso +++ b/distribution/lib/Standard/Searcher/0.0.0-dev/src/Data_Science/Date_And_Time.enso @@ -7,28 +7,27 @@ > Example Get the current time - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_now = Date_Time.now > Example Parse UTC time. - import Standard.Base.Data.Time + from Standard.Base import Date_Time - example_parse = Time.parse "2020-10-01T04:11:12Z" + example_parse = Date_Time.parse "2020-10-01T04:11:12Z" > Example Convert time instance to -04:00 timezone. - import Standard.Base.Data.Time.Date_Time - import Standard.Base.Data.Time.Zone + from Standard.Base import Date_Time, Time_Zone - exaomple_at_zone = Date_Time.new 2020 . at_zone (Zone.new -4) + exaomple_at_zone = Date_Time.new 2020 . at_zone (Time_Zone.new -4) > Example Convert the current time to a date. - import Standard.Base.Data.Time + from Standard.Base import Date_Time example_date = Date_Time.now.date diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column_Type_Selection.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column_Type_Selection.enso index 33b261a09f..5de4cc0f9f 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column_Type_Selection.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column_Type_Selection.enso @@ -1,5 +1,4 @@ from Standard.Base import all -import Standard.Base.Data.Time ## The type representing inferring the column type automatically based on values present in the column. @@ -9,7 +8,7 @@ import Standard.Base.Data.Time - if all values are decimals or integers, `Decimal` is chosen, - if all values are booleans, `Boolean` is chosen, - if the values are all the same time type (a date, a time or a date-time), - the corresponding type is chosen, `Date`, `Time_Of_Day` or `Time`, + the corresponding type is chosen, `Date`, `Time_Of_Day` or `Date_Time`, respectively, - otherwise, `Text` is chosen as a fallback and the column is kept as-is without parsing. @@ -22,4 +21,4 @@ type Auto index. - datatype: The desired datatype for the column or `Auto` to infer the type from the data. -type Column_Type_Selection (column:Text|Integer) datatype:(Auto|Integer|Decimal|Date|Time|Time_Of_Day|Boolean)=Auto +type Column_Type_Selection (column:Text|Integer) datatype:(Auto|Integer|Decimal|Date|Date_Time|Time_Of_Day|Boolean)=Auto diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Data_Formatter.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Data_Formatter.enso index d0366edabf..f0a665ad6b 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Data_Formatter.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Data_Formatter.enso @@ -1,7 +1,4 @@ from Standard.Base import all - -from Standard.Base.Data.Time import Date_Time -from Standard.Base.Data.Time.Time_Of_Day import Time_Of_Day import Standard.Base.Error.Common as Errors from Standard.Table.Data.Column_Type_Selection import Auto diff --git a/distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso b/distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso index b338868669..3860d1a555 100644 --- a/distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso +++ b/distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso @@ -1,5 +1,4 @@ from Standard.Base import all -import Standard.Base.Data.Time.Date_Time import Standard.Base.Runtime.State import Standard.Base.System diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java index 292d6b45f4..1605cf8df2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java @@ -322,7 +322,7 @@ public abstract class InvokeMethodNode extends BaseNode { guards = { "!methods.hasFunctionalDispatch(self)", "!methods.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_ZONE" + "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TIME_ZONE" }) Stateful doConvertZone( VirtualFrame frame, @@ -336,7 +336,7 @@ public abstract class InvokeMethodNode extends BaseNode { var ctx = Context.get(this); try { var hostZone = interop.asTimeZone(self); - var dateTime = new EnsoZone(hostZone); + var dateTime = new EnsoTimeZone(hostZone); Function function = dateDispatch.getFunctionalDispatch(dateTime, symbol); arguments[0] = dateTime; return invokeFunctionNode.execute(function, frame, state, arguments); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java index 01d79cc993..c95d4b04c1 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java @@ -50,12 +50,12 @@ public abstract class HostMethodCallNode extends Node { CONVERT_TO_DATE, /** * The method call should be handled by converting {@code self} to a {@code - * Standard.Base.Data.DateTime} and dispatching natively. + * Standard.Base.Data.Time.Date_Time} and dispatching natively. */ CONVERT_TO_ZONED_DATE_TIME, /** * The method call should be handled by converting {@code self} to a {@code - * Standard.Base.Data.DateTime} with a system Zone and dispatching natively. + * Standard.Base.Data.Time.Date_Time} with a system Time_Zone and dispatching natively. */ CONVERT_TO_DATE_TIME, /** @@ -65,9 +65,9 @@ public abstract class HostMethodCallNode extends Node { CONVERT_TO_TIME_OF_DAY, /** * The method call should be handled by converting {@code self} to a {@code - * Standard.Base.Data.Time.Zone} and dispatching natively. + * Standard.Base.Data.Time.Time_Zone} and dispatching natively. */ - CONVERT_TO_ZONE, + CONVERT_TO_TIME_ZONE, /** The method call should be handled by dispatching through the {@code Any} type. */ NOT_SUPPORTED; @@ -85,7 +85,7 @@ public abstract class HostMethodCallNode extends Node { && this != CONVERT_TO_DATE_TIME && this != CONVERT_TO_ZONED_DATE_TIME && this != CONVERT_TO_TIME_OF_DAY - && this != CONVERT_TO_ZONE; + && this != CONVERT_TO_TIME_ZONE; } } @@ -119,7 +119,7 @@ public abstract class HostMethodCallNode extends Node { } else if (library.isTime(self)) { return PolyglotCallType.CONVERT_TO_TIME_OF_DAY; } else if (library.isTimeZone(self)) { - return PolyglotCallType.CONVERT_TO_ZONE; + return PolyglotCallType.CONVERT_TO_TIME_ZONE; } else if (library.isString(self)) { return PolyglotCallType.CONVERT_TO_TEXT; } else if (library.isMemberInvocable(self, methodName)) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java index 625ec9235a..83951d6a05 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java @@ -78,7 +78,7 @@ public class Builtins { private final BuiltinAtomConstructor date; private final BuiltinAtomConstructor dateTime; private final BuiltinAtomConstructor timeOfDay; - private final BuiltinAtomConstructor zone; + private final BuiltinAtomConstructor timeZone; private final BuiltinAtomConstructor warning; /** @@ -126,9 +126,9 @@ public class Builtins { timeOfDay = new BuiltinAtomConstructor( this, org.enso.interpreter.node.expression.builtin.date.TimeOfDay.class); - zone = + timeZone = new BuiltinAtomConstructor( - this, org.enso.interpreter.node.expression.builtin.date.Zone.class); + this, org.enso.interpreter.node.expression.builtin.date.TimeZone.class); special = new Special(language); warning = new BuiltinAtomConstructor(this, Warning.class); } @@ -452,21 +452,21 @@ public class Builtins { } /** - * Returns the {@code Zone} atom constructor. + * Returns the {@code TimeOfDay} atom constructor. * - * @return the {@code Zone} atom constructor + * @return the {@code TimeOfDay} atom constructor */ public AtomConstructor timeOfDay() { return timeOfDay.constructor(); } /** - * Returns the {@code Zone} atom constructor. + * Returns the {@code TimeZone} atom constructor. * - * @return the {@code Zone} atom constructor + * @return the {@code TimeZone} atom constructor */ - public AtomConstructor zone() { - return zone.constructor(); + public AtomConstructor timeZone() { + return timeZone.constructor(); } /** diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java index 25aebf67c4..c21cc03c1b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java @@ -74,7 +74,7 @@ public final class EnsoDate implements TruffleObject { } @Builtin.Method(name = "to_time_builtin", description = "Combine this day with time to create a point in time.") - public EnsoDateTime toTime(EnsoTimeOfDay timeOfDay, EnsoZone zone) { + public EnsoDateTime toTime(EnsoTimeOfDay timeOfDay, EnsoTimeZone zone) { return new EnsoDateTime(date.atTime(timeOfDay.asTime()).atZone(zone.asTimeZone())); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java index 0cfc2601de..f14e53027b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java @@ -43,7 +43,7 @@ public final class EnsoDateTime implements TruffleObject { *

Accepts: * *