Skip to content

Commit

Permalink
Update ICONs as per Cass's work (#9023)
Browse files Browse the repository at this point in the history
Apply the Date and Time based ICON updates.
  • Loading branch information
jdunkerley authored Feb 12, 2024
1 parent 6739426 commit 0c3e8f1
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ polyglot java import java.util.Base64

## A helper utility for handling base64 encoding.
type Base_64
## Converts a string to bytes using the specified encoding, and encodes that
## ICON convert
Converts a string to bytes using the specified encoding, and encodes that
to base64.
encode_text (text : Text) (encoding : Encoding = Encoding.utf_8) -> Text =
Base64.getEncoder.encodeToString (text.bytes encoding)

## Decodes a base64 encoded string, using the provided encoding.
## ICON convert
Decodes a base64 encoded string, using the provided encoding.
decode_text (encoded_text : Text) (encoding : Encoding = Encoding.utf_8) -> Text ! Encoding_Error =
Text.from_bytes (Base64.getDecoder.decode encoded_text) encoding
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ type Enso_File
list_assets self . filter f-> f.asset_type != Enso_Asset_Type.Secret

## UNSTABLE
GROUP Output
Creates a subdirectory in a specified directory.
create_directory : Text -> Enso_File
create_directory self (name : Text) = if self.is_directory.not then Error.throw (Illegal_Argument.Error "Only directories can contain subdirectories.") else
Expand All @@ -244,6 +245,7 @@ type Enso_File
response.if_not_error <| response.decode_as_json.into Enso_File

## UNSTABLE
GROUP Output
Deletes the file or directory.
delete : Nothing
delete self = if self.id == "" then Error.throw (Illegal_Argument.Error "The root directory cannot be deleted.") else
Expand All @@ -254,6 +256,7 @@ type Enso_File
response.if_not_error <| Nothing

## UNSTABLE
GROUP Operators
Resolves a file or directory within this directory.
/ : Text -> Enso_File ! Not_Found
/ self (name : Text) -> Enso_File ! Not_Found =
Expand Down
14 changes: 12 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Java_Json.enso
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ polyglot java import com.fasterxml.jackson.databind.ObjectMapper
type Java_Json
## ALIAS from text
GROUP Conversions
ICON convert

Parse a Text value into a `Jackson_Object` or an Enso primitive value
(like `Text`, `Number`, `Boolean`, `Nothing`), or a `Vector` of values.
Expand Down Expand Up @@ -83,11 +84,13 @@ type Jackson_Object
Value object_node ~field_array

## GROUP Logical
ICON preparation
Returns True iff the objects contains the given `key`.
contains_key : Text -> Boolean
contains_key self key:Text = self.object_node.has key

## Get a value for a key of the object, or a default value if that key is not present.
## ICON select_row
Get a value for a key of the object, or a default value if that key is not present.

Arguments:
- key: The key to get.
Expand All @@ -100,6 +103,7 @@ type Jackson_Object
read_json_node child

## GROUP Selections
ICON select_row
Get a value for a key of the object.
If the key is not found, throws a `No_Such_Key` error.

Expand All @@ -110,6 +114,7 @@ type Jackson_Object
at self key:Text = self.get key (Error.throw (No_Such_Key.Error self key))

## GROUP Metadata
ICON metadata
Get the keys of the object.
field_names : Vector
field_names self = self.field_array
Expand All @@ -136,6 +141,7 @@ type Jackson_Object
function key value

## GROUP Conversions
ICON convert
Convert the object to a Vector of Pairs.
to_vector : Vector
to_vector self =
Expand All @@ -144,16 +150,19 @@ type Jackson_Object
Vector.from_polyglot_array proxy

## GROUP Metadata
ICON metadata
Gets the number of keys in the object.
length : Number
length self = self.object_node.size

## GROUP Logical
ICON metadata
Returns True iff the Map is empty, i.e., does not have any entries.
is_empty : Boolean
is_empty self = self.length == 0

## GROUP Logical
ICON metadata
Returns True iff the Map is not empty, i.e., has at least one entry.
not_empty : Boolean
not_empty self = self.is_empty.not
Expand Down Expand Up @@ -187,7 +196,8 @@ make_field_name_selector : Jackson_Object -> Display -> Widget
make_field_name_selector js_object display=Display.Always =
Single_Choice display=display values=(js_object.field_names.map n->(Option n n.pretty))

## Extension for Text to allow use.
## ICON convert
Extension for Text to allow use.
Text.parse_fast_json : Nothing | Boolean | Number | Text | Vector | Jackson_Object
Text.parse_fast_json self = Java_Json.parse self

Expand Down
9 changes: 8 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ type JS_Object
contains_key : Text -> Boolean
contains_key self key:Text = has_property self.js_object key

## Get a value for a key of the object, or a default value if that key is not present.
## ICON select_row
Get a value for a key of the object, or a default value if that key is not present.

Arguments:
- key: The key to get.
Expand All @@ -154,6 +155,7 @@ type JS_Object
make_enso value

## GROUP Selections
ICON select_row
Get a value for a key of the object.
If the key is not found, throws a `No_Such_Key` error.

Expand All @@ -164,6 +166,7 @@ type JS_Object
at self key:Text = self.get key (Error.throw (No_Such_Key.Error self key))

## GROUP Metadata
ICON metadata
Get the keys of the object.
field_names : Vector
field_names self =
Expand Down Expand Up @@ -191,22 +194,26 @@ type JS_Object
function key value

## GROUP Metadata
ICON metadata
Gets the number of keys in the object.
length : Number
length self =
get_property_names self.js_object . length

## GROUP Logical
ICON metadata
Returns True iff the Map is empty, i.e., does not have any entries.
is_empty : Boolean
is_empty self = self.length == 0

## GROUP Logical
ICON metadata
Returns True iff the Map is not empty, i.e., has at least one entry.
not_empty : Boolean
not_empty self = self.is_empty.not

## GROUP Conversions
ICON convert
Convert the object to a Vector of Key and Values.
to_vector : Vector
to_vector self =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ type Number
log self base = self.ln / base.ln

## GROUP Conversions
ICON convert
Converts a numeric value to a string, using the Java DecimalFormat
formatter.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ type Date

## ALIAS date range
GROUP Input
ICON date_and_time
Creates an increasing range of dates from `self` to `end`.

Arguments:
Expand All @@ -550,6 +551,7 @@ type Date

## ALIAS date range
GROUP Input
ICON date_and_time
Creates a decreasing range of dates from `self` to `end`.

Arguments:
Expand Down Expand Up @@ -749,7 +751,7 @@ type Date
JS_Object.from_pairs [type_pair, cons_pair, ["day", self.day], ["month", self.month], ["year", self.year]]

## GROUP Conversions
ICON text
ICON convert
Format this date using the provided format specifier.

Arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ type Date_Time
parse text:Text format:Date_Time_Formatter=Date_Time_Formatter.default_enso_zoned_date_time =
format.parse_date_time text

## Creates a new `Date_Time` from a Unix epoch timestamp in seconds (and optional nanoseconds).
## ICON convert
Creates a new `Date_Time` from a Unix epoch timestamp in seconds (and optional nanoseconds).

Arguments:
- seconds: The number of seconds since the Unix epoch.
Expand All @@ -301,7 +302,8 @@ type Date_Time
from_unix_epoch_seconds seconds:Integer nanoseconds:Integer=0 =
unix_epoch_start + Duration.new seconds=seconds nanoseconds=nanoseconds

## Creates a new `Date_Time` from a Unix epoch timestamp in milliseconds.
## ICON convert
Creates a new `Date_Time` from a Unix epoch timestamp in milliseconds.

Arguments:
- milliseconds: The number of milliseconds since the Unix epoch.
Expand Down Expand Up @@ -835,7 +837,7 @@ type Date_Time
JS_Object.from_pairs [type_pair, cons_pair, ["year", self.year], ["month", self.month], ["day", self.day], ["hour", self.hour], ["minute", self.minute], ["second", self.second], ["nanosecond", self.nanosecond include_milliseconds=True], ["zone", self.zone]]

## GROUP Conversions
ICON text
ICON convert
Format this time as text using the specified format specifier.

Arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Day_Of_Week
Saturday

## GROUP Conversions
ICON convert
Convert the Day_Of_Week to an Integer.

Arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ ensure_duration object ~action =
## Represents the amount of time between two points in time.
@Builtin_Type
type Duration
## Create an interval representing the duration between two points in time.
## ICON date_and_time
Create an interval representing the duration between two points in time.

Arguments:
- start_inclusive: The start datetime of the duration, included.
Expand All @@ -85,6 +86,7 @@ type Duration
between_builtin start_inclusive end_exclusive timezone_aware

## GROUP DateTime
ICON date_and_time
Create a duration from time units.

Arguments:
Expand All @@ -104,7 +106,8 @@ type Duration
new hours=0 minutes=0 seconds=0 milliseconds=0 nanoseconds=0 =
new_builtin hours minutes seconds milliseconds nanoseconds

## Create a zero (empty) duration.
## ICON date_and_time
Create a zero (empty) duration.
> Example
Folding a vector of durations.

Expand All @@ -116,6 +119,7 @@ type Duration
zero = Duration.new

## ADVANCED
ICON date_and_time

Time the evaluation of a function, return a Pair of Duration and Result

Expand Down Expand Up @@ -177,6 +181,7 @@ type Duration
Error.throw (Time_Error.Error err.payload.getMessage)

## GROUP Metadata
ICON metadata
Get the portion of the duration expressed in nanoseconds.

> Example
Expand All @@ -189,6 +194,7 @@ type Duration
nanoseconds self = @Builtin_Method "Duration.nanoseconds"

## GROUP Metadata
ICON metadata
Get the portion of the duration expressed in milliseconds.

> Example
Expand All @@ -201,6 +207,7 @@ type Duration
milliseconds self = @Builtin_Method "Duration.milliseconds"

## GROUP Metadata
ICON metadata
Get the portion of the duration expressed in seconds.

> Example
Expand All @@ -213,6 +220,7 @@ type Duration
seconds self = @Builtin_Method "Duration.seconds"

## GROUP Metadata
ICON metadata
Get the portion of the duration expressed in minutes.

> Example
Expand All @@ -225,6 +233,7 @@ type Duration
minutes self = @Builtin_Method "Duration.minutes"

## GROUP Metadata
ICON metadata
Get the portion of the duration expressed in hours.

> Example
Expand All @@ -237,23 +246,27 @@ type Duration
hours self = @Builtin_Method "Duration.hours"

## GROUP DateTime
ICON convert
Convert the duration to total milliseconds.
total_milliseconds : Integer ! Illegal_State
total_milliseconds self =
Panic.catch ArithmeticException (self.total_milliseconds_builtin) _->
Error.throw (Illegal_State.Error "The duration is too large to convert it to milliseconds")

## GROUP DateTime
ICON convert
Convert the duration to total seconds.
total_seconds : Float ! Illegal_State
total_seconds self = self.total_milliseconds / 1000.0

## GROUP DateTime
ICON convert
Convert the duration to total minutes.
total_minutes : Float ! Illegal_State
total_minutes self = self.total_seconds / 60.0

## GROUP DateTime
ICON convert
Convert the duration to total minutes.
total_hours : Float ! Illegal_State
total_hours self = self.total_minutes / 60.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ ensure_period object ~action error_msg="Cannot use Duration as a parameter" =
daylight saving time. This means that a Period of 1 day does not necessarily
have to be 24 hours of Duration.
type Period
## Create a Period representing the time interval between two dates.
## ICON date_and_time
Create a Period representing the time interval between two dates.

Arguments:
- start_date_inclusive: The start date of the period, included.
Expand Down
Loading

0 comments on commit 0c3e8f1

Please sign in to comment.