Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.5.0
* Implement the `ILibDurationFmt` class to enable DurationFormatting.

## 1.4.0
* Include the `DurationFmt.js` file from iLib in the `ilib-init.js` file within the assets.
The developer can use `evaluate()` to obtain the result of Duration formatting until the DurationFmt class is properly implemented.
Expand All @@ -21,7 +24,7 @@
* Updated the test cases where expectations have aligned between webOS versions and upstream since the CLDR update to 46

## 1.0.0
* Updated the structure to load separate locale data files.
* Updated the structure to load separate locale data files.
Previously, the dependent ilib was a fully assembled JS file. Now, the ilib files are divided into the js and locale files.
The JS code is assembled as `ilib-init.js`, and the locale files are generated with names like [language].js, e.g. `en.js`, `ko.js`. The iLib files are generated using the [ilib-assemble](https://github.com/iLib-js/ilib-assemble) tool. This change brings memory savings over previous versions of flutter_ilib.
Initially, when the app is launched, the package automatically loads the locale data by detecting the system's locale. To load the updated locale data file when the locale changes, I suggest adding the following method at the appropriate time when the locale chanages.
Expand Down
49 changes: 46 additions & 3 deletions Docs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Date
## ILibDateOptions

### Properties
Expand All @@ -7,6 +8,7 @@
|_\<String?>_ locale | Locales are specified either with a specifier string that follows the BCP-47 convention, <br>(roughly: "language-script-region").|
|_\<int?>_ year | The year|
|_\<int?>_ month | The month|
|_\<int?>_ week | The week|
|_\<int?>_ day | The day of the month|
|_\<int?>_ hour | The hour of the day|
|_\<int?>_ minute | The minute [0..59]|
Expand All @@ -20,7 +22,7 @@

### Constructors
```dart
ILibDateOptions (String? locale, int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? unixtime, String? type, String? calendar, DateTime? dateTime)
ILibDateOptions (String? locale, int? year, int? month, int? week, int? day, int? hour, int? minute, int? second, int? millisecond, int? unixtime, String? type, String? calendar, DateTime? dateTime)
```

### Methods
Expand All @@ -29,6 +31,7 @@ ILibDateOptions (String? locale, int? year, int? month, int? day, int? hour, int
|_String_ toJsonString() | A string representation of parameters to call functions of iLib library properly|


# Date Formatting
## ILibDateFmtOptions

### Properties
Expand Down Expand Up @@ -70,8 +73,45 @@ ILibDateFmt(ILibDateFmtOptions options)
|_String_ getTemplate()| Return the template string that is used to format date/times for this formatter instance|
|_List\<MeridiemsInfo>_ getMeridiemsRange()| Return the range of possible meridiems (times of day like "AM" or "PM") in this date formatter.|

## ILibLocaleInfo


# Duration Formatting
## ILibDurationFmtOptions
### Properties
|name|description|
|------|---|
|_\<String?>_ locale| locale to use when formatting the duration. If the locale is not specified, then the default locale of the app will be used |
|_\<String?>_ length| Specify the length of the format to use. The length is the approximate size of the formatted string. <br> <li><i>short</i> - use a short representation of the duration. This is the most compact format possible for the locale. eg. 1y 1m 1w 1d 1:01:01 <br> <li><i>medium</i> - use a medium length representation of the duration. This is a slightly longer format. eg. 1 yr 1 mo 1 wk 1 dy 1 hr 1 mi 1 se <br> <li><i>long</i> - use a long representation of the duration. This is a fully specified format, but some of the textual <br> <li><i>full</i> - use a full representation of the duration. This is a fully specified format where all the textual parts are spelled out completely. eg. 1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute and 1 second parts may still be abbreviated. eg. 1 yr 1 mo 1 wk 1 day 1 hr 1 min 1 sec|
|_\<String?>_ style| whether hours, minutes, and seconds should be formatted as a text string or as a regular time as on a clock. eg. text is "1 hour, 15 minutes", whereas clock is "1:15:00". Valid values for this property are "text" or "clock". Default if this property is not specified is "text". |
|_\<Bool?>_ useNative| the flag used to determaine whether to use the native script settings for formatting the numbers |

### Constructors
```dart
ILibDurationFmtOptions (String? locale, String? length, String? style, bool? useNative)
```

## ILibDurationFmt
### Properties
|name|description|
|------|---|
| _\<ILibDurationFmtOptions>_ options | Options for the DurationFormating|

### Constructors
```dart
ILibDurationFmt(ILibDurationFmtOptions options)
```
### Methods
|name|description|
|------|---|
|_String_ toJsonString() | A string representation of parameters to call functions of iLib library properly|
|_String_ format()| Formats a particular date instance according to the settings of this formatter object|
|_String_ getLocale()| Return the locale that was used to construct this duration formatter object.|
|_String_ getLength()| Return the length that was used to construct this duration formatter object.|
|_String_ getStyle()| Return the style that was used to construct this duration formatter object.|


# LocaleInfo
## ILibLocaleInfo
### Properties
|name|description|
|------|---|
Expand All @@ -87,4 +127,7 @@ ILibLocaleInfo(String locale)
|------|---|
|_int_ getFirstDayOfWeek() | Returns the day of week that starts weeks in the current locale. <br>Days are still numbered the standard way with 0 for Sunday through 6 for Saturday, <br> but calendars should be displayed and weeks calculated with the day of week returned from this function as the first day of the week.|
|_int_ getWeekEndStart() | Returns the day of week that starts weekend in the current locale.<br> Days are still numbered the standard way with 0 for Sunday through 6 for Saturday.|
|_int_ getWeekEndEnd() | Returns the day of week that ends weekend in the current locale. <br>Days are still numbered the standard way with 0 for Sunday through 6 for Saturday.|
|_int_ getWeekEndEnd() | Returns the day of week that ends weekend in the current locale. <br>Days are still numbered the standard way with 0 for Sunday through 6 for Saturday.|



42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ Widget build(BuildContext context) {
....
```

### Formatting
### Examples
Get the result of formatting by using the class provided by flutter_ilib.

### Date Formatting

```dart
final ILibDateFmtOptions fmtOptions = ILibDateFmtOptions(
locale: 'ko-KR',
Expand Down Expand Up @@ -84,6 +86,31 @@ fmt.format(dateOptions);
// '2024년 6월 27일 오전 10:42'
```

### Duration Formatting

```dart
final ILibDurationFmtOptions fmtOptions =
ILibDurationFmtOptions(locale: 'en-GB', length: 'full');
final ILibDurationFmt fmt = ILibDurationFmt(fmtOptions);
final ILibDateOptions dateOptions = ILibDateOptions(
year: 1, month: 1, week: 1, day: 1, hour: 1, minute: 1);
fmt.format(dateOptions);
// '1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute'

final ILibDurationFmtOptions fmtOptions = ILibDurationFmtOptions(
locale: 'en-GB',
length: 'full',
style: 'clock',
);
final ILibDurationFmt fmt = ILibDurationFmt(fmtOptions);
final ILibDateOptions dateOptions = ILibDateOptions(
year: 2, month: 2, week: 2, day: 2, hour: 2, minute: 2);
fmt.format(dateOptions);
// '2 years, 2 months, 2 weeks, 2 days, 02:02'
```

### LocaleInfo

```dart
// 0:sun, 1:mon, 2:tue, 3:wed, 4:thu, 5:fri, 6:sat
final ILibLocaleInfo locInfo = ILibLocaleInfo('ko-KR');
Expand All @@ -108,18 +135,25 @@ _flutterIlibPlugin.evaluateILib(jscode1);
// 'ethiopic'
```
To give a more efficient way, we provide some classes that can be easily used in a Flutter app.
Currently, We have a `ILibDateFmt` and `ILibLocaleInfo` classes.
Currently, We have a `ILibDateFmt` , `ILibLocaleInfo` and `ILibDurationFmt` classes.
We have a plan to provide more classes and methods.

### ILibDateFmt
### ILibDate
- Class: [ILibDateOptions](./Docs.md/#ilibdateoptions)

### ILibDateFmt
- Class: [ILibDateFmtOptions](./Docs.md/#ilibdatefmtoptions)
- Class: [ILibDateFmt](./Docs.md#ilibdatefmt)
- Methods: `format()`, `getClock()`, `getTemplate()`, `getMeridiemsRange()`

### ILibLocaleInfo
- Class: [ILibLocaleInfo](./Docs.md/#iliblocaleinfo)
- Methods: `getFirstDayOfWeek()`, `getWeekEndStart()`, `getWeekEndStart()`
- Methods: `getFirstDayOfWeek()`, `getWeekEndStart()`, `getWeekEndStart()`

### ILibDurationFmt
- Class: [ILibDurationFmtOptions](./Docs.md/#ilibdurationfmtoptions)
- Class: [ILibDurationFmt](./Docs.md/#ilibdurationfmt)
- Methods: `format()`, `getLocale()`, `getStyle()`, `getLength()`

## Supported Locales
The results of the following locales are checked by unit tests.
Expand Down
2 changes: 1 addition & 1 deletion assets/js/ilib-init.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/flutter_ilib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'ilib_init.dart';
import 'internal/logger/log_adapter.dart';
import 'internal/logger/logger_selector.dart';

export 'ilib_date.dart';
export 'ilib_datefmt.dart';
export 'ilib_durationfmt.dart';
export 'ilib_init.dart';
export 'ilib_localeinfo.dart';

Expand Down
104 changes: 104 additions & 0 deletions lib/ilib_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
class ILibDateOptions {
/// [locale] Locales are specified either with a specifier string that follows the BCP-47 convention,
/// [year] The year
/// [month] The month
/// [week] The week
/// [day] The day of the month
/// [hour] The hour of the day
/// [minute] The minute [0..59]
/// [second] The second [0..59]
/// [millisecond] The millisecond [0..999]
/// [unixtime] Sets the time of this instance according to the given unix time.
/// [timezone] Time zone name as a string
/// [calendar] Same as "type" property
/// [dateTime] DateTime class of flutter
/// [type] Specifies the type/calendar of the date desired.
ILibDateOptions(
{this.locale,
this.year,
this.month,
this.week,
this.day,
this.hour,
this.minute,
this.second,
this.millisecond,
this.unixtime,
this.timezone,
this.calendar,
this.dateTime,
this.type});
String? locale;
int? year;
int? month;
int? week;
int? day;
int? hour;
int? minute;
int? second;
int? millisecond;
int? unixtime;
String? timezone;
String? type;
String? calendar;
DateTime? dateTime;

/// A string representation of parameters to call functions of iLib library properly
String toJsonString() {
int? y = year;
int? m = month;
int? w = week;
int? d = day;
int? h = hour;
int? min = minute;
int? sec = second;
int? milsec = millisecond;
String result = '';
String completeOption = '';

if (dateTime != null) {
y = dateTime!.year;
m = dateTime!.month;
d = dateTime!.day;
h = dateTime!.hour;
min = dateTime!.minute;
sec = dateTime!.second;
milsec = dateTime!.millisecond;
}

final Map<String, String> paramInfo = <String, String>{
'locale': '$locale',
// If dateTime is not null and is in UTC, set timezone to 'Etc/UTC'.
// Otherwise, use the provided timezone value.
'timezone': (dateTime?.isUtc ?? false) ? 'Etc/UTC' : '$timezone',
'type': '$type',
'calendar': '$calendar'
};

paramInfo.forEach((String key, String value) {
if (value != 'null') {
result += '$key:"$value",';
}
});

final Map<String, int?> datetimeInfo = <String, int?>{
'year': y,
'month': m,
'week': w,
'day': d,
'hour': h,
'minute': min,
'second': sec,
'millisecond': milsec,
};
datetimeInfo.forEach((String key, int? value) {
if (value != null) {
result += '$key:$value,';
}
});
result =
result.isNotEmpty ? result.substring(0, result.length - 1) : result;
completeOption = result.isNotEmpty ? '{$result}' : '';
return completeOption;
}
}
Loading