date_formatter_codespark 1.2.0
date_formatter_codespark: ^1.2.0 copied to clipboard
A zero-dependency, ultra-lightweight Flutter package providing intuitive DateTime extensions.
date_formatter_codespark #
A zero-dependency, ultra-lightweight suite of intuitive DateTime extensions for Flutter. Bypasses the heavy initialization footprint of intl and the rigid functional wrapping of timeago.
The Token-Saving Advantage (Before vs. After) #
1. Relative Human Time #
Without this package (30 lines of error-prone math):
String timeAgo(DateTime date) {
final diff = DateTime.now().difference(date);
if (diff.inMinutes < 60) return '${diff.inMinutes}m ago';
if (diff.inHours < 24) return '${diff.inHours}h ago';
return '${diff.inDays}d ago';
}
With this package (1 line):
dateTime.toTimeAgo(); // "5m ago"
2. Live Countdown Tracking #
Without this package: Manual epoch calculations checking for midnight boundaries.
With this package:
dueDate.daysRemaining(); // "3 days left"
Key Features & Usage #
Semantic Evaluation Flags #
dateTime.isToday; // true/false
dateTime.isYesterday; // true/false
dateTime.isTomorrow; // true/false
dateTime.isThisWeek; // true/false
dateTime.isWeekend; // true/false
dateTime.isBusinessDay; // true/false
dateTime.isLastBusinessDayOfMonth; // true/false
dateTime.isLeapYear; // true/false
dateTime.isFuture; // true/false
dateTime.isPast; // true/false
Layout & Formatting Presets #
dateTime.toDayAndMonth(); // "29 May"
dateTime.toTime12Hour(); // "11:30 PM"
dateTime.toFullHumanDate(); // "Friday, 29 May, 2026"
dateTime.toIsoDateString(); // "2026-05-29"
dateTime.toIsoTimeString(); // "09:05:07"
dateTime.toShortTimeString(); // "9:05 AM"
dateTime.toShortDateString(); // "05/30/2026"
dateTime.toRfc2822String(); // "Sat, 30 May 2026 09:05:00 +0000"
Relative Time (Past & Future) #
dateTime.toTimeAgo(); // "12m ago" (short, default)
dateTime.toTimeAgo(short: false); // "12 minutes ago" (verbose)
// Future dates work natively:
dateTime.toTimeAgo(); // "in 3h"
dateTime.toTimeAgo(short: false); // "in 3 hours"
Precise Time Countdowns #
dateTime.daysRemaining(); // "3 days left" | "1 day left" | "Today" | "Expired"
dateTime.hoursRemaining(); // "5 hours left" | "1 hour left" | "Expired"
Business Day & Calendar Math #
dateTime.addBusinessDays(3); // Skips weekends
dateTime.subtractBusinessDays(2); // Skips weekends
dateTime.nextDay; // Next calendar day
dateTime.previousDay; // Previous calendar day
dateTime.copyWith(year: 2027); // Clone with changes
Week, Month, Quarter, Year Utilities #
dateTime.weekOfYear; // ISO week number
dateTime.quarter; // 1-4
dateTime.isQuarterStart; // true/false
dateTime.isQuarterEnd; // true/false
dateTime.startOfWeek; // Monday
dateTime.endOfWeek; // Sunday
dateTime.startOfMonth; // First day
dateTime.endOfMonth; // Last day
dateTime.startOfYear; // Jan 1
dateTime.endOfYear; // Dec 31
dateTime.isFirstDayOfMonth; // true/false
dateTime.isLastDayOfMonth; // true/false
dateTime.daysInMonth; // 28-31
dateTime.isSameDay(other);
dateTime.isSameWeek(other);
dateTime.isSameMonth(other);
dateTime.isSameYear(other);
Julian Day Support #
dateTime.toJulianDay; // int
DateFormatterExtension.fromJulianDay(2451545); // DateTime
Date Math & Utilities #
dateTime.daysUntil(other); // int
dateTime.monthsBetween(other); // int
dateTime.yearsBetween(other); // int
dateTime.isWithin(start, end); // true/false
dateTime.atTime(9, 30); // Set time
dateTime.endOfDay; // 23:59:59.999
dateTime.withTimeZoneOffset(Duration(hours: 2));
dateTime.toLocalOrUtc();
Installation #
Add to your pubspec.yaml:
dependencies:
date_formatter_codespark: ^1.1.0
Then import:
import 'package:date_formatter_codespark/date_formatter_codespark.dart';
Zero Dependencies #
This package has no external dependencies. It does not use intl, timeago, or any other third-party package. All date formatting, locale-aware month names, and weekday strings are handled via lean, hand-crafted lookup tables internally.
Full API Reference #
All extension methods are documented with concise doc comments and examples in the code. See lib/src/date_extensions.dart for the complete API surface.
License #
MIT License — see LICENSE for details.