shortDiffForHumans method

String shortDiffForHumans([
  1. Carbon? other
])

Get a compact, localized human-readable difference (e.g. "14m ago", "2h ago", "5m from now").

Measures against other when given, or Carbon's own clock (honouring setTestNow) otherwise. Unlike diffForHumans, the wording comes from the time translation group (time.units_short.*, time.ago, time.from_now, time.just_now): a catalogue entry wins when present, and the English literal shipped in lang_en.stub is the fallback when it is not (Translator.has, localization/translator.dart:298).

The magnitude ladder truncates, never rounds: a 45-day gap reads "1mo ago" because 45 days is one whole 30-day month, not two.

createdAt.shortDiffForHumans();  // "14m ago"
dueAt.shortDiffForHumans();      // "5m from now"

Implementation

String shortDiffForHumans([Carbon? other]) {
  final DateTime reference = other?.toDateTime ?? _clock().dateTime;
  final Duration elapsed = reference.difference(toDateTime);
  final int totalSeconds = elapsed.inSeconds.abs();

  if (totalSeconds < 1) {
    return _shortLocalized('time.just_now', 'Just now', const {});
  }

  final String unitText = _shortUnitText(totalSeconds);
  final bool isFuture = elapsed.isNegative;
  final String wrapperKey = isFuture ? 'time.from_now' : 'time.ago';
  final String wrapperFallback = isFuture ? ':time from now' : ':time ago';

  return _shortLocalized(wrapperKey, wrapperFallback, {'time': unitText});
}