Skip to content

Commit

Permalink
Merge pull request #35 from nixrajput/v2.1.0
Browse files Browse the repository at this point in the history
Updated to v2.1.0
  • Loading branch information
nixrajput authored Nov 18, 2024
2 parents 10074b1 + 180f38a commit 435ef21
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 87 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.1.0

- **Change**: Added support for `Dutch` (nl) locale.
- **Change**: Dependencies updated.
- **Fix**: All known bugs and issues fixed.

## 2.0.0

- **Breaking Change**: A new message method `justNow` added for displaying the time less than 15 seconds.
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,9 @@ If you would like to contribute to this project, feel free to fork the repositor

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Sponsor Me
## Support My Work

By sponsoring my efforts, you're not merely contributing to the development of my projects; you're investing in its growth and sustainability.

Your support empowers me to dedicate more time and resources to improving the project's features, addressing issues, and ensuring its continued relevance in the rapidly evolving landscape of technology.

Your sponsorship directly fuels innovation, fosters a vibrant community, and helps maintain the project's high standards of quality. Together, we can shape the future of the projects and make a lasting impact in the open-source community.

Thank you for considering sponsoring my work!
Your support helps me dedicate more time to developing high-quality, impactful projects in the open-source community. Sponsor me, and together, let’s bring even more innovation to life!

[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/nixrajput)

Expand Down
225 changes: 149 additions & 76 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,44 @@ class GetTimeAgoExampleApp extends StatelessWidget {
}
}

class GetTimeAgoExampleScreen extends StatelessWidget {
class GetTimeAgoExampleScreen extends StatefulWidget {
@override
State<GetTimeAgoExampleScreen> createState() =>
_GetTimeAgoExampleScreenState();
}

const Map<String, String> languageNames = {
'ar': 'Arabic',
'en': 'English',
'es': 'Spanish',
'fa': 'Persian (Farsi)',
'fr': 'French',
'hi': 'Hindi',
'pt': 'Portuguese (Brazil)',
'br': 'Portuguese (Brazil alternate)',
'zh': 'Simplified Chinese',
'zh_tr': 'Traditional Chinese',
'ja': 'Japanese',
'oc': 'Occitan',
'ko': 'Korean',
'de': 'German',
'id': 'Indonesian',
'tr': 'Turkish',
'ur': 'Urdu',
'vi': 'Vietnamese',
'ro': 'Romanian',
'nl': 'Dutch',
};

class _GetTimeAgoExampleScreenState extends State<GetTimeAgoExampleScreen> {
// Helper function to get the DateTime relative to now
DateTime _getRelativeDateTime(Duration duration) {
return DateTime.now().subtract(duration);
}

// Variable to hold the selected language code
String? _selectedLanguage = Data.defaultLocale;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -47,83 +79,118 @@ class GetTimeAgoExampleScreen extends StatelessWidget {
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
border: Border.all(color: Colors.blue.shade50),
border: Border.all(color: Colors.grey.shade300),
),
child: ListView(
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
child: Column(
children: [
_buildExampleTile(
context,
'Just Now (Less than 15 seconds ago)',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 10)),
),
),
_buildExampleTile(
context,
'30 seconds ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 30)),
),
),
_buildExampleTile(
context,
'1 minute ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
),
),
_buildExampleTile(
context,
'2 minutes ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 2)),
),
DropdownButton<String>(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
isExpanded: true,
hint: const Text("Select Locale"),
value: _selectedLanguage,
onChanged: (String? newValue) {
setState(() {
_selectedLanguage = newValue;
});
},
items: languageNames.entries.map((entry) {
var code = entry.key;
var name = entry.value;
return DropdownMenuItem<String>(
value: code,
child: Text('$name ($code)'),
);
}).toList(),
),
_buildExampleTile(
context,
'1 hour ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
),
),
_buildExampleTile(
context,
'2 hours ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 2)),
),
),
_buildExampleTile(
context,
'1 day ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 1)),
),
),
_buildExampleTile(
context,
'3 days ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 3)),
),
),
_buildExampleTile(
context,
'10 days ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 10)),
),
),
_buildExampleTile(
context,
'Custom format beyond 7 days',
GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(days: 10),
),
pattern: 'yyyy-MM-dd',
Expanded(
child: ListView(
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
children: [
_buildExampleTile(
context,
'Just Now (Less than 15 seconds)',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 10)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'30 seconds ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 30)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'1 minute ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'2 minutes ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 2)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'1 hour ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'2 hours ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 2)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'1 day ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 1)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'3 days ago',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 3)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'10 days ago (beyond 7 days)',
GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 10)),
locale: _selectedLanguage,
),
),
_buildExampleTile(
context,
'Custom format beyond 7 days',
GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(days: 10),
),
pattern: 'yyyy-MM-dd',
locale: _selectedLanguage,
),
),
],
),
),
],
Expand All @@ -137,7 +204,13 @@ class GetTimeAgoExampleScreen extends StatelessWidget {
Widget _buildExampleTile(BuildContext context, String title, String timeAgo) {
return ListTile(
title: Text(title),
subtitle: Text(timeAgo),
subtitle: Text(
timeAgo,
style: const TextStyle(
color: Colors.blue,
fontSize: 16,
),
),
isThreeLine: true,
);
}
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: get_time_ago
description: A Dart package to convert and format `DateTime` objects into human-readable 'time ago' strings like '20 seconds ago', 'a minute ago', or '7 hours ago'.

version: 2.0.0
version: 2.1.0

homepage: https://pub.dev/packages/get_time_ago
repository: https://github.com/nixrajput/get-time-ago
Expand All @@ -14,7 +14,7 @@ dependencies:
intl: ">=0.18.0 <0.20.0"

dev_dependencies:
lints: ^4.0.0
lints: ^5.0.0
test: ^1.25.8

topics:
Expand All @@ -25,5 +25,5 @@ topics:

funding:
- https://ko-fi.com/nixrajput
- https://www.buymeacoffee.com/nixrajput
- https://buymeacoffee.com/nixrajput
- https://github.com/sponsors/nixrajput

0 comments on commit 435ef21

Please sign in to comment.