Skip to content

Commit

Permalink
v: 2.3.0+3
Browse files Browse the repository at this point in the history
  • Loading branch information
hhtokpinar committed Sep 29, 2022
1 parent ebba658 commit d68f6cc
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 236 deletions.
Binary file modified .DS_Store
Binary file not shown.
54 changes: 0 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,60 +244,6 @@ So you can create many Database Models and use them in your application.
);
```

Now you can define const and methods for customized DateTime Format to call it from the files that will be generated

```dart
/// region Date Format
///
/// Specify a defaultDateFormat (Optional) default (dd-MM-yyyy)
final defaultDateFormat = intl.DateFormat('dd-MM-yyyy');
/// Specify a defaultTimeFormat (Optional) default (hh:mm a)
final defaultTimeFormat = intl.DateFormat('hh:mm a');
/// Specify a defaultDateTimeFormat (Optional) default (dd-MM-yyyy - hh:mm a)
final defaultDateTimeFormat =
intl.DateFormat('$defaultDateFormat - $defaultTimeFormat');
DateTime toDateTime(TimeOfDay x) {
return DateTime(2020, 1, 1, x.hour, x.minute);
}
TimeOfDay? tryParseTime(String x) {
final DateTime? d = tryParseTimeToDate(x);
return d == null ? null : TimeOfDay.fromDateTime(d);
}
DateTime? tryParseTimeToDate(String x) {
try {
return int.tryParse(x) != null
? DateTime.fromMillisecondsSinceEpoch(int.tryParse(x)!)
: defaultTimeFormat.parse(x);
} catch (e) {
return tryParseDateTime(x);
}
}
DateTime? tryParseDate(String x) {
try {
return defaultDateFormat.parse(x);
} catch (e) {
return tryParseDateTime(x);
}
}
DateTime? tryParseDateTime(String x) {
try {
return defaultDateTimeFormat.parse(x);
} catch (e) {
return DateTime.tryParse(x);
}
}
/// endregion
```


That's all.. one more step left for create models.dart file.
Expand Down
49 changes: 0 additions & 49 deletions example/lib/model/chinook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,6 @@ import 'view.list.dart';
part 'chinook.g.dart';
part 'chinook.g.view.dart';

/// region Dates Formats
///
/// Specify a defaultDateFormat (Optional) default (dd-MM-yyyy)
final defaultDateFormat = intl.DateFormat('dd-MMMM-yyyy');

/// Specify a defaultTimeFormat (Optional) default (hh:mm a)
final defaultTimeFormat = intl.DateFormat('hh:mm a');

/// Specify a defaultDateTimeFormat (Optional) default (dd-MM-yyyy - hh:mm a)
final defaultDateTimeFormat =
intl.DateFormat('$defaultDateFormat - $defaultTimeFormat');

DateTime toDateTime(TimeOfDay x) {
return DateTime(2020, 1, 1, x.hour, x.minute);
}

TimeOfDay? tryParseTime(String x) {
final DateTime? d = tryParseTimeToDate(x);
return d == null ? null : TimeOfDay.fromDateTime(d);
}

DateTime? tryParseTimeToDate(String x) {
try {
return int.tryParse(x) != null
? DateTime.fromMillisecondsSinceEpoch(int.tryParse(x)!)
: defaultTimeFormat.parse(x);
} catch (e) {
return tryParseDateTime(x);
}
}

DateTime? tryParseDate(String x) {
try {
return defaultDateFormat.parse(x);
} catch (e) {
return tryParseDateTime(x);
}
}

DateTime? tryParseDateTime(String x) {
try {
return defaultDateTimeFormat.parse(x);
} catch (e) {
return DateTime.tryParse(x);
}
}

/// endregion
// BEGIN chinook.db MODEL

// BEGIN TABLES
Expand Down
91 changes: 62 additions & 29 deletions example/lib/model/chinook.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d68f6cc

Please sign in to comment.