Skip to main content

Module format

Module format 

Expand description

Shared value formatters for system apps — byte sizes, transfer rates, media timecodes, “time ago” labels, grouped and compact counts, and month/weekday names.

bytes uses IEC binary units while bytes_si uses SI decimal units, so callers choose an unambiguous convention. The platform’s rule, shared with Files, Disks and the Storage pane: anything stored or transferred (files, downloads, caches, packages, drives and partitions) uses bytes_si, the way drives are sold and file managers count; memory uses bytes. A flow whose requirements are themselves stated in binary units (the installer’s GiB partition minimums) stays binary throughout so its numbers compare.

Month/weekday lookups are index-based (not string-keyed) so a caller wiring fluent in can map the index to a translated string without this module hard-coding a locale.

Functions§

bytes
Format a byte count with base-1024 IEC binary units (B, KiB, MiB, GiB, TiB, …). Whole bytes print with no decimal; larger units print one decimal place.
bytes_si
Format a byte count with base-1000 SI decimal units (B, kB, MB, GB, TB, …), for anything stored or transferred (see the module docs). Memory uses bytes.
capitalize_first
Upper-case the first character (by Unicode case mapping, so ß becomes SS) and keep the rest unchanged.
compact_count
Abbreviate a large count to at most one fractional digit: 1.2K, 3.4M, 1.1B. Exact tenths omit the redundant .0 (12K, not 12.0K) and a value that rounds into the next unit is promoted (999_999 becomes 1M, never 1000.0K). Values below 1000 print in full.
count
A whole count with the current locale’s digit grouping: 12,345 in English, 12.345 in German, 12\u{202f}345 in French. Use it for every count a person reads in full (rows, files, results); compact_count for the abbreviated form.
count_in
count for the locale locale (a BCP 47 tag such as de-DE).
month_abbrev
Three-letter English month abbreviation for a 0-based month index (0 = Jan … 11 = Dec). The index wraps mod 12, so callers holding a 1-based month can pass month - 1 without a bounds check.
month_name
Full English month name for a 0-based month index (0 = January). Wraps mod 12.
near_day
Name a calendar day next to today in the host’s language — Yesterday, Today, Tomorrow — or None further out, where the caller shows its own date. days_from_today is negative for the past.
rate
Format a transfer rate from bytes-per-second with base-1024 IEC units and a /s suffix (512 B/s, 6.4 MiB/s). Negative inputs clamp to zero.
relative
Format a past interval (in seconds) as a coarse relative label in the host’s language: just now, 3 min ago, 2 hr ago, yesterday, 4 days ago, 2 weeks ago, 3 months ago, 1 year ago. Zero and negative deltas (clock skew) read just now. Counts go through Fluent plurals, so each language words its own singular and plural forms.
relative_compact
Format a past interval (in seconds) as a narrow column label: now, 3m, 2h, 4d, 2w, 3mo, 1y. For list columns too tight for relative’s wording. Zero and negative deltas (clock skew) read now.
timecode
Format a whole-second duration as a media timecode: m:ss under an hour, h:mm:ss at or above one hour.
weekday_abbrev
Three-letter English weekday abbreviation for a 0-based index where 0 = Sunday … 6 = Saturday. Wraps mod 7.
weekday_name
Full English weekday name for a 0-based index where 0 = Sunday. Wraps mod 7.