tempo_dart 0.1.0
tempo_dart: ^0.1.0 copied to clipboard
A lightweight, tree-shakable date and time utility library for Dart and Flutter, built around native DateTime.
// Minimal usage example for `tempo_dart`. Demonstrates one call from each
// of the seven implemented modules. Locale-aware tokens (`dddd`, `MMMM`)
// require `initializeDateFormatting` to be called once at startup.
import 'package:intl/date_symbol_data_local.dart';
import 'package:tempo_dart/tempo_dart.dart';
Future<void> main() async {
// Locale data must be initialised before any locale-aware token (MMMM,
// dddd, A/a) or `intl`-backed style shorthand. `tempo_dart` itself never
// calls this implicitly — see DESIGN.md §4.2.
await initializeDateFormatting('en');
final now = DateTime(2026, 5, 8, 14, 5);
// 1. Token-based formatting via the extension form.
print(now.format('dddd, MMMM D, YYYY')); // Friday, May 8, 2026
// 2. Date arithmetic with month-overflow guard.
final endOfNextMonth = now.addMonths(1).endOfMonth();
print(endOfNextMonth); // 2026-06-30 23:59:59.999999
// 3. Calendar-aware difference.
print(now.diffInDays(DateTime(2026, 5, 1))); // 7
// 4. Localised relative-time string with explicit reference.
print(
now.humanize(
relativeTo: DateTime(2026, 5, 8, 17, 5),
locale: 'en',
),
); // 3 hours ago
}