Skip to content

Update Documentation for LookupMessages #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ThomasAunvik
Copy link

@ThomasAunvik ThomasAunvik commented Apr 4, 2025

aboutAYear returns months, not years.

From day 365 and to 729.

If it was years, it would look like 12y to 24y

result = messages.aboutAYear(months.round());

Example:

import 'package:timeago/timeago.dart' as timeago;

// my_custom_messages.dart
class MyCustomMessages implements timeago.LookupMessages {
  @override
  String prefixAgo() => '';
  @override
  String prefixFromNow() => '';
  @override
  String suffixAgo() => '';
  @override
  String suffixFromNow() => '';
  @override
  String lessThanOneMinute(int seconds) => 'now';
  @override
  String aboutAMinute(int minutes) => '${minutes}m';
  @override
  String minutes(int minutes) => '${minutes}m';
  @override
  String aboutAnHour(int minutes) => '${minutes}m';
  @override
  String hours(int hours) => '${hours}h';
  @override
  String aDay(int hours) => '${hours}h';
  @override
  String days(int days) => '${days}d';
  @override
  String aboutAMonth(int days) => '${days}d';
  @override
  String months(int months) => '${months}mo';
  @override
  String aboutAYear(int year) => '${year}y';
  @override
  String years(int years) => '${years}y';
  @override
  String wordSeparator() => ' ';
}

main() {
  // Override "en" locale messages with custom messages that are more precise and short
  timeago.setLocaleMessages('en', MyCustomMessages());

  final months = DateTime.now().subtract(Duration(days: 365));
  final month2 = DateTime.now().subtract(Duration(days: 729));

  print(timeago.format(months)); // 12y
  print(timeago.format(months2)); // 24y
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant