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 usesbytes. - capitalize_
first - Upper-case the first character (by Unicode case mapping, so
ßbecomesSS) 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, not12.0K) and a value that rounds into the next unit is promoted (999_999becomes1M, never1000.0K). Values below 1000 print in full. - count
- A whole count with the current locale’s digit grouping:
12,345in English,12.345in German,12\u{202f}345in French. Use it for every count a person reads in full (rows, files, results);compact_countfor the abbreviated form. - count_
in countfor the localelocale(a BCP 47 tag such asde-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 passmonth - 1without 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— orNonefurther out, where the caller shows its own date.days_from_todayis negative for the past. - rate
- Format a transfer rate from bytes-per-second with base-1024 IEC units
and a
/ssuffix (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) readjust 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 forrelative’s wording. Zero and negative deltas (clock skew) readnow. - timecode
- Format a whole-second duration as a media timecode:
m:ssunder an hour,h:mm:ssat 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.