toRealtime method

String toRealtime({
  1. bool showRealtime = true,
  2. int whenShowNow = 10,
  3. String? format,
  4. String? local,
  5. TimeFormats timeFormat = TimeFormats.timeHMa,
  6. DateFormats dateFormat = DateFormats.dateDMCY,
  7. String separator = " at ",
  8. RealtimeTextFormat textFormat = const RealtimeTextFormat(),
  9. String onRealtime(
    1. Realtime value
    )?,
  10. String onRealtimeByHours(
    1. Realtime value
    )?,
  11. String onRealtimeByMinutes(
    1. Realtime value
    )?,
  12. String onRealtimeBySeconds(
    1. Realtime value
    )?,
  13. String onRealtimeByAfterHours(
    1. Realtime value
    )?,
  14. String onRealtimeByAfterMinutes(
    1. Realtime value
    )?,
  15. String onRealtimeByAfterSeconds(
    1. Realtime value
    )?,
  16. String onRealtimeByTomorrow(
    1. Realtime value,
    2. String time
    )?,
  17. String onRealtimeByToday(
    1. Realtime value,
    2. String time
    )?,
  18. String onRealtimeByYesterday(
    1. Realtime value,
    2. String time
    )?,
})

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 DateConverter.toRealtime(
    this?.millisecondsSinceEpoch,
    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,
  );
}