easy_date_time 0.3.6
easy_date_time: ^0.3.6 copied to clipboard
A drop-in replacement for DateTime with full IANA timezone support, intuitive arithmetic, and flexible formatting.
EasyDateTime Examples #
Complete runnable examples with all dependencies.
Setup #
cd example
dart pub get
For freezed/retrofit examples, run code generation:
dart run build_runner build
Directory Structure #
lib/
├── core/ # Core usage (no code generation)
└── integrations/ # Third-party integrations (requires code generation)
Core Examples #
No code generation needed. Run directly:
| File | Description |
|---|---|
| basic_usage.dart | Initialization, creation |
| timezone_specify.dart | Three ways to specify timezone |
| parsing.dart | Parsing with value preservation |
| timezone_convert.dart | Timezone conversion |
| arithmetic.dart | Date arithmetic |
| date_utils.dart | isToday, startOfDay, etc. |
| json_serialization.dart | JSON serialization |
| formatting.dart | Output formats using format() and DateTimeFormats |
| formatter_example.dart | Pre-compiled formatter for performance |
| copywith.dart | Creating modified copies |
| error_handling.dart | Safe parsing, validation |
dart run lib/core/basic_usage.dart
Integration Examples #
Requires dart run build_runner build first:
| File | Description |
|---|---|
| freezed_example.dart | Freezed + json_serializable |
| dio_example.dart | Dio HTTP client |
| retrofit_example.dart | Retrofit type-safe API |
dart run lib/integrations/freezed_example.dart
Custom JsonConverter #
EasyDateTime works with json_serializable via custom converters. See freezed_example.dart for the converter template:
class EasyDateTimeConverter implements JsonConverter<EasyDateTime, String> {
const EasyDateTimeConverter();
@override
EasyDateTime fromJson(String json) => EasyDateTime.fromIso8601String(json);
@override
String toJson(EasyDateTime object) => object.toIso8601String();
}