Skip to content

Commit

Permalink
Updated json_class
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeiffer committed Jul 16, 2023
1 parent 47d6ff4 commit a0e1208
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 78 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [3.1.0] - July 16th, 2023

* Updated to json_class 3.0.0


## [3.0.6+2] - July 4, 2023

* Automated dependency updates
Expand Down
44 changes: 22 additions & 22 deletions lib/src/expressions/functions/date_time_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,51 @@ class DateTimeFunctions {
second != null ||
millisecond != null)
? DateTime(
JsonClass.parseInt(value) ?? 0,
JsonClass.parseInt(month) ?? 1,
JsonClass.parseInt(date) ?? 1,
JsonClass.parseInt(hour) ?? 0,
JsonClass.parseInt(minute) ?? 0,
JsonClass.parseInt(second) ?? 0,
JsonClass.parseInt(millisecond) ?? 0,
JsonClass.maybeParseInt(value) ?? 0,
JsonClass.maybeParseInt(month) ?? 1,
JsonClass.maybeParseInt(date) ?? 1,
JsonClass.maybeParseInt(hour) ?? 0,
JsonClass.maybeParseInt(minute) ?? 0,
JsonClass.maybeParseInt(second) ?? 0,
JsonClass.maybeParseInt(millisecond) ?? 0,
)
: value is Map
? DateTime(
JsonClass.parseInt(value['year']) ?? 0,
JsonClass.parseInt(value['month']) ?? 1,
JsonClass.parseInt(value['date'] ?? value['day']) ?? 1,
JsonClass.parseInt(value['hour']) ?? 0,
JsonClass.parseInt(value['minute']) ?? 0,
JsonClass.parseInt(value['second']) ?? 0,
JsonClass.parseInt(value['milliseconds']) ?? 0,
JsonClass.maybeParseInt(value['year']) ?? 0,
JsonClass.maybeParseInt(value['month']) ?? 1,
JsonClass.maybeParseInt(value['date'] ?? value['day']) ?? 1,
JsonClass.maybeParseInt(value['hour']) ?? 0,
JsonClass.maybeParseInt(value['minute']) ?? 0,
JsonClass.maybeParseInt(value['second']) ?? 0,
JsonClass.maybeParseInt(value['milliseconds']) ?? 0,
)
: value is List
? DateTime(
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.isNotEmpty ? value[0] : null) ??
0,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 1 ? value[1] : null) ??
1,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 2 ? value[2] : null) ??
1,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 3 ? value[3] : null) ??
0,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 4 ? value[4] : null) ??
0,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 5 ? value[5] : null) ??
0,
JsonClass.parseInt(
JsonClass.maybeParseInt(
value.length > 6 ? value[6] : null) ??
0,
)
: (value is num || value is String)
? DateTime.fromMillisecondsSinceEpoch(
JsonClass.parseInt(value) ?? 0)
JsonClass.maybeParseInt(value) ?? 0)
: value == null
? DateTime.now()
: throw Exception(
Expand Down
89 changes: 45 additions & 44 deletions lib/src/expressions/functions/duration_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,55 @@ import 'package:json_class/json_class.dart';
class DurationFunctions {
/// The functions related to the Duration creation
static final functions = {
'Duration': (value, [hours, minutes, seconds, milliseconds]) => (hours !=
null ||
minutes != null ||
seconds != null ||
milliseconds != null)
? Duration(
days: JsonClass.parseInt(value) ?? 0,
hours: JsonClass.parseInt(hours) ?? 0,
minutes: JsonClass.parseInt(minutes) ?? 0,
seconds: JsonClass.parseInt(seconds) ?? 0,
milliseconds: JsonClass.parseInt(milliseconds) ?? 0,
)
: value is Map
'Duration': (value, [hours, minutes, seconds, milliseconds]) =>
(hours != null ||
minutes != null ||
seconds != null ||
milliseconds != null)
? Duration(
days: JsonClass.parseInt(value['days']) ?? 0,
hours: JsonClass.parseInt(value['hours']) ?? 0,
minutes: JsonClass.parseInt(value['minutes']) ?? 0,
seconds: JsonClass.parseInt(value['seconds']) ?? 0,
milliseconds: JsonClass.parseInt(value['milliseconds']) ?? 0,
days: JsonClass.maybeParseInt(value) ?? 0,
hours: JsonClass.maybeParseInt(hours) ?? 0,
minutes: JsonClass.maybeParseInt(minutes) ?? 0,
seconds: JsonClass.maybeParseInt(seconds) ?? 0,
milliseconds: JsonClass.maybeParseInt(milliseconds) ?? 0,
)
: value is List
: value is Map
? Duration(
days: JsonClass.parseInt(
value.isNotEmpty ? value[0] : null) ??
0,
hours: JsonClass.parseInt(
value.length > 1 ? value[1] : null) ??
0,
minutes: JsonClass.parseInt(
value.length > 2 ? value[2] : null) ??
0,
seconds: JsonClass.parseInt(
value.length > 3 ? value[3] : null) ??
0,
milliseconds: JsonClass.parseInt(
value.length > 4 ? value[4] : null) ??
0,
days: JsonClass.maybeParseInt(value['days']) ?? 0,
hours: JsonClass.maybeParseInt(value['hours']) ?? 0,
minutes: JsonClass.maybeParseInt(value['minutes']) ?? 0,
seconds: JsonClass.maybeParseInt(value['seconds']) ?? 0,
milliseconds:
JsonClass.maybeParseInt(value['milliseconds']) ?? 0,
)
: value is String || value is num
? JsonClass.parseDurationFromMillis(value)!
: throw Exception(
'[Duration]: expected [value] to be a Map, a List, a String, or a num but encountered: ${value?.runtimeType}',
),
'days': (value) => Duration(hours: JsonClass.parseInt(value)! * 24),
'hours': (value) => Duration(minutes: JsonClass.parseInt(value)!),
: value is List
? Duration(
days: JsonClass.maybeParseInt(
value.isNotEmpty ? value[0] : null) ??
0,
hours: JsonClass.maybeParseInt(
value.length > 1 ? value[1] : null) ??
0,
minutes: JsonClass.maybeParseInt(
value.length > 2 ? value[2] : null) ??
0,
seconds: JsonClass.maybeParseInt(
value.length > 3 ? value[3] : null) ??
0,
milliseconds: JsonClass.maybeParseInt(
value.length > 4 ? value[4] : null) ??
0,
)
: value is String || value is num
? JsonClass.maybeParseDurationFromMillis(value)!
: throw Exception(
'[Duration]: expected [value] to be a Map, a List, a String, or a num but encountered: ${value?.runtimeType}',
),
'days': (value) => Duration(hours: JsonClass.maybeParseInt(value)! * 24),
'hours': (value) => Duration(minutes: JsonClass.maybeParseInt(value)!),
'milliseconds': (value) =>
Duration(milliseconds: JsonClass.parseInt(value)!),
'minutes': (value) => Duration(minutes: JsonClass.parseInt(value)!),
'seconds': (value) => Duration(seconds: JsonClass.parseInt(value)!),
Duration(milliseconds: JsonClass.maybeParseInt(value)!),
'minutes': (value) => Duration(minutes: JsonClass.maybeParseInt(value)!),
'seconds': (value) => Duration(seconds: JsonClass.maybeParseInt(value)!),
};
}
12 changes: 6 additions & 6 deletions lib/src/expressions/standard_members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ dynamic _processDateTime(DateTime target, String name) {
target.millisecondsSinceEpoch +
((duration is Duration)
? duration.inMilliseconds
: JsonClass.parseInt(duration)!),
: JsonClass.maybeParseInt(duration)!),
isUtc: target.isUtc,
);
break;
Expand Down Expand Up @@ -170,7 +170,7 @@ dynamic _processDateTime(DateTime target, String name) {
result = (duration) => target.subtract(
duration is Duration
? duration
: Duration(milliseconds: JsonClass.parseInt(duration)!),
: Duration(milliseconds: JsonClass.maybeParseInt(duration)!),
);
break;

Expand Down Expand Up @@ -198,7 +198,7 @@ dynamic _processDuration(Duration target, String name) {
target.inMilliseconds +
(duration is Duration
? duration.inMilliseconds
: JsonClass.parseInt(duration)!);
: JsonClass.maybeParseInt(duration)!);
break;

case 'compareTo':
Expand Down Expand Up @@ -230,7 +230,7 @@ dynamic _processDuration(Duration target, String name) {
milliseconds: target.inMilliseconds -
(duration is Duration
? duration.inMilliseconds
: JsonClass.parseInt(duration)!),
: JsonClass.maybeParseInt(duration)!),
);
break;
}
Expand Down Expand Up @@ -390,7 +390,7 @@ dynamic _processList(List target, String name) {

case 'toJson':
result = ([padding]) {
final indent = JsonClass.parseInt(padding) ?? 0;
final indent = JsonClass.maybeParseInt(padding) ?? 0;

return indent == 0
? json.encode(target)
Expand Down Expand Up @@ -488,7 +488,7 @@ dynamic _processMap(Map target, String name) {

case 'toJson':
result = ([padding]) {
final indent = JsonClass.parseInt(padding) ?? 0;
final indent = JsonClass.maybeParseInt(padding) ?? 0;

return indent == 0
? json.encode(target)
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: 'template_expressions'
description: 'A Dart library to process string based templates using expressions.'
homepage: 'https://github.com/peiffer-innovations/template_expressions'
version: '3.0.6+2'
version: '3.1.0'

environment:
environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
dependencies:
convert: '^3.1.1'
crypto: '^3.0.1'
encrypt: '^5.0.1'
fake_async: '^1.3.0'
intl: '^0.18.1'
json_class: '^2.2.2+1'
json_class: '^3.0.0'
json_path: '^0.6.0'
logging: '^1.2.0'
meta: '^1.9.1'
Expand All @@ -22,11 +22,11 @@ dependencies:
rxdart: '^0.27.7'
yaon: '^1.1.2+1'

dev_dependencies:
dev_dependencies:
flutter_lints: '^2.0.2'
test: '^1.24.4'

ignore_updates:
ignore_updates:
- 'archive'
- 'async'
- 'boolean_selector'
Expand Down

0 comments on commit a0e1208

Please sign in to comment.