toRealtime method
String
toRealtime({
- bool showRealtime = true,
- int whenShowNow = 10,
- String? format,
- String? local,
- TimeFormats timeFormat = TimeFormats.timeHMa,
- DateFormats dateFormat = DateFormats.dateDMCY,
- String separator = " at ",
- RealtimeTextFormat textFormat = const RealtimeTextFormat(),
- String onRealtime(
- Realtime value
- String onRealtimeByHours(
- Realtime value
- String onRealtimeByMinutes(
- Realtime value
- String onRealtimeBySeconds(
- Realtime value
- String onRealtimeByAfterHours(
- Realtime value
- String onRealtimeByAfterMinutes(
- Realtime value
- String onRealtimeByAfterSeconds(
- Realtime value
- String onRealtimeByTomorrow()?,
- String onRealtimeByToday()?,
- String onRealtimeByYesterday()?,
Converts milliseconds since epoch to a customizable relative time string.
Example:
int myTime = DateProvider.currentMS;
String customRelativeTime = DateProvider.toRealtime(
myTime,
onRealtimeByHours: (value) => "Custom hours: ${value.hours}",
onRealtimeByMinutes: (value) => "Custom minutes: ${value.minutes}",
);
print(customRelativeTime); // Output: Custom hours: 2
Implementation
String toRealtime({
bool showRealtime = true,
int whenShowNow = 10,
String? format,
String? local,
TimeFormats timeFormat = TimeFormats.timeHMa,
DateFormats dateFormat = DateFormats.dateDMCY,
String separator = " at ",
RealtimeTextFormat textFormat = const RealtimeTextFormat(),
String Function(Realtime value)? onRealtime,
String Function(Realtime value)? onRealtimeByHours,
String Function(Realtime value)? onRealtimeByMinutes,
String Function(Realtime value)? onRealtimeBySeconds,
String Function(Realtime value)? onRealtimeByAfterHours,
String Function(Realtime value)? onRealtimeByAfterMinutes,
String Function(Realtime value)? onRealtimeByAfterSeconds,
String Function(Realtime value, String time)? onRealtimeByTomorrow,
String Function(Realtime value, String time)? onRealtimeByToday,
String Function(Realtime value, String time)? onRealtimeByYesterday,
}) {
return DateHelper.toRealtime(
this,
showRealtime: showRealtime,
whenShowNow: whenShowNow,
format: format,
local: local,
timeFormat: timeFormat,
dateFormat: dateFormat,
separator: separator,
textFormat: textFormat,
onRealtime: onRealtime,
onRealtimeByHours: onRealtimeByHours,
onRealtimeByMinutes: onRealtimeByMinutes,
onRealtimeBySeconds: onRealtimeBySeconds,
onRealtimeByAfterHours: onRealtimeByAfterHours,
onRealtimeByAfterMinutes: onRealtimeByAfterMinutes,
onRealtimeByAfterSeconds: onRealtimeByAfterSeconds,
onRealtimeByTomorrow: onRealtimeByTomorrow,
onRealtimeByToday: onRealtimeByToday,
onRealtimeByYesterday: onRealtimeByYesterday,
);
}