From 6b8d3861845f3dfcb4468249564510560590268f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Mon, 20 Jun 2022 15:26:29 +0200 Subject: [PATCH] register formatters, weird linter issue --- .../0.0.0-dev/src/Data/Data_Formatter.enso | 19 ++++++++++++++++--- .../enso/table/formatting/DateFormatter.java | 2 +- .../table/formatting/DateTimeFormatter.java | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) 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 9fa80e8d66e09..eb95ebd8ea3ff 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 @@ -23,6 +23,9 @@ polyglot java import org.enso.table.formatting.AnyObjectFormatter polyglot java import org.enso.table.formatting.BooleanFormatter polyglot java import org.enso.table.formatting.DecimalFormatter polyglot java import org.enso.table.formatting.IntegerFormatter +polyglot java import org.enso.table.formatting.DateFormatter +polyglot java import org.enso.table.formatting.DateTimeFormatter +polyglot java import org.enso.table.formatting.TimeFormatter polyglot java import org.enso.table.formatting.TextFormatter ## Specifies options for reading text data in a table to more specific types and @@ -118,7 +121,18 @@ Data_Formatter.make_decimal_formatter = ## PRIVATE Data_Formatter.make_date_formatter = - DateFormatter.new this.??? this.decimal_point + if this.date_formats.is_empty then Error.throw (Illegal_Argument_Error "Formatting dates requires at least one entry in the `date_formats` parameter") else + DateFormatter.new this.date_formats.first this.locale.java_locale + +## PRIVATE +Data_Formatter.make_time_formatter = + if this.time_formats.is_empty then Error.throw (Illegal_Argument_Error "Formatting times requires at least one entry in the `time_formats` parameter") else + TimeFormatter.new this.time_formats.first this.locale.java_locale + +## PRIVATE +Data_Formatter.make_datetime_formatter = + if this.datetime_formats.is_empty then Error.throw (Illegal_Argument_Error "Formatting date-times requires at least one entry in the `datetime_formats` parameter") else + DateTimeFormatter.new this.datetime_formats.first this.locale.java_locale ## PRIVATE Data_Formatter.make_boolean_formatter = @@ -132,8 +146,7 @@ Data_Formatter.make_text_formatter = ## PRIVATE Data_Formatter.get_specific_type_formatters = - # TODO add date-time formatters - [this.make_integer_formatter, this.make_decimal_formatter, this.make_boolean_formatter, this.make_text_formatter] + [this.make_integer_formatter, this.make_decimal_formatter, this.make_boolean_formatter, this.make_datetime_formatter, this.make_date_formatter, this.make_time_formatter, this.make_text_formatter] ## PRIVATE Data_Formatter.make_auto_formatter = diff --git a/std-bits/table/src/main/java/org/enso/table/formatting/DateFormatter.java b/std-bits/table/src/main/java/org/enso/table/formatting/DateFormatter.java index c017dbf75098d..a4a0f1ef53e11 100644 --- a/std-bits/table/src/main/java/org/enso/table/formatting/DateFormatter.java +++ b/std-bits/table/src/main/java/org/enso/table/formatting/DateFormatter.java @@ -12,7 +12,7 @@ public DateFormatter(String formatString, Locale locale) { } @Override - public String format(Object value) { + public String format(Object value) { if (value == null) { return NULL_REPRESENTATION; } diff --git a/std-bits/table/src/main/java/org/enso/table/formatting/DateTimeFormatter.java b/std-bits/table/src/main/java/org/enso/table/formatting/DateTimeFormatter.java index 88a863536d9ef..9b3fe6f639338 100644 --- a/std-bits/table/src/main/java/org/enso/table/formatting/DateTimeFormatter.java +++ b/std-bits/table/src/main/java/org/enso/table/formatting/DateTimeFormatter.java @@ -6,7 +6,7 @@ public class DateTimeFormatter implements DataFormatter { private final java.time.format.DateTimeFormatter formatter; - public DateTimeFormatter(String formatString, Locale locale) { +public DateTimeFormatter(String formatString, Locale locale) { formatter = java.time.format.DateTimeFormatter.ofPattern(formatString, locale); }