You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Jiffy support short messages?
Instead of "5 minutes ago", can it display "5m"?
As of version 6.4.0, Jiffy allows you to fully customize relative date-time formatting. Whether you want short-form messages or a completely new format, Jiffy provides flexible options.
How to Customize Relative Date-Time Formatting
There are two main ways to achieve this:
1️⃣ Extending e.g. EnRelativeDateTime (or Other Pre-Set Classes)
If you only need to override specific pre-set RelativeDateTime formats while keeping the rest, you can extend them. For this example, we will use EnRelativeDateTime
// Extend EnRelativeDateTime to modify specific formatsclassCustomRelativeDateTimeextendsEnRelativeDateTime {
@overrideStringminutes(int minutes) =>'$minutes''m'; // Custom short format
}
awaitJiffy.setLocale('en_US', relativeDateTime:CustomRelativeDateTime());
final j =Jiffy.now().subtract(minutes:5);
print(j.fromNow(withPrefixAndSuffix:false)); // Output: 5m
2️⃣ Creating a Fully Custom Relative Date-Time Class
If you need total control, you can create a custom class from scratch by implementing RelativeDateTime.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
A recent issue was raised asking:
Issue #179
As of version 6.4.0, Jiffy allows you to fully customize relative date-time formatting. Whether you want short-form messages or a completely new format, Jiffy provides flexible options.
How to Customize Relative Date-Time Formatting
There are two main ways to achieve this:
1️⃣ Extending e.g.
EnRelativeDateTime
(or Other Pre-Set Classes)If you only need to override specific pre-set
RelativeDateTime
formats while keeping the rest, you can extend them. For this example, we will useEnRelativeDateTime
2️⃣ Creating a Fully Custom Relative Date-Time Class
If you need total control, you can create a custom class from scratch by implementing
RelativeDateTime
.More Customization Options
Beyond relative date-time formats, Jiffy allows advanced locale settings such as:
1st
,2nd
,3rd
, etc.)fromNow()
and other time expressions appearFor full details, check out the Locale Support Documentation.
Hope this helps! Let me know if you have any questions. 🚀
Beta Was this translation helpful? Give feedback.
All reactions