date_snap 1.0.0
date_snap: ^1.0.0 copied to clipboard
A lightweight Flutter package for localized date formatting and relative time calculation. Supports English, Bengali, and Arabic.
Date Snap #
Date Snap is a lightweight, zero-dependency Flutter package designed to make date formatting and relative time calculations incredibly simple. It supports localization out of the box, allowing you to display dates and times in English, Bengali, and Arabic seamlessly.
🚀 Features #
- Zero Dependency: Lightweight and easy to integrate without bloat.
- Localized Formatting: Native support for English, Bengali, and Arabic digit representations.
- Time Ago Calculation: Provides readable relative time strings like "2 hours ago" or "২ ঘণ্টা আগে".
- Easy to Use: Intuitive extension methods on the
DateTimeclass.
📦 Installation #
Add date_snap to your pubspec.yaml file:
dependencies:
date_snap: ^1.0.0
📖 Usage #
Import the package into your Dart file:
import 'package:date_snap/date_snap.dart';
1. Date Formatting #
Format dates into strings with local digit support:
DateTime now = DateTime.now();
print(now.toFormattedDate(lang: 'en')); // Output: 10/3/2026
print(now.toFormattedDate(lang: 'bn')); // Output: ১০/৩/২০২৬
print(now.toFormattedDate(lang: 'ar')); // Output: ١٠/٣/٢٠٢٦
2. Time Ago #
Calculate relative time effortlessly:
DateTime pastDate = DateTime.now().subtract(const Duration(hours: 2));
print(pastDate.toTimeAgo(lang: 'en')); // Output: 2h ago
print(pastDate.toTimeAgo(lang: 'bn')); // Output: ২ ঘণ্টা আগে
print(pastDate.toTimeAgo(lang: 'ar')); // Output: ٢ ساعة مضت