Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AGenUI AGenUI TR35 Date Pattern Formatting

From Leeroopedia
Knowledge Sources
Domains Date_Time_Formatting, Parsing
Last Updated 2026-10-24 17:21 GMT

Overview

A date formatting technique that uses Unicode TR35 pattern tokens (letters like `y`, `M`, `d`, `H`) whose repetition count controls output width and form, enabling locale-independent date string construction.

Description

The Unicode Technical Standard #35 defines a pattern-based date formatting language used by ICU, CLDR, and many libraries. A pattern string contains field tokens (repeated letters) and literal text (everything else). Each token's repeat count determines the output form:

  • `y` (year): 2 = 2-digit, 3+ = full year
  • `M` (month): 1 = numeric, 2 = padded, 3 = abbreviated name, 4+ = full name
  • `d` (day): 1 = numeric, 2+ = padded
  • `E` (weekday): 1-3 = abbreviated, 4+ = full
  • `H` (24-hour): 1 = numeric, 2+ = padded
  • `h` (12-hour): 1 = numeric, 2+ = padded
  • `m` (minute): 1+ = padded
  • `s` (second): 1+ = padded
  • `a` (AM/PM): 1+ = marker

This decouples the formatting logic from any specific locale library, allowing a compact C++ implementation that parses ISO 8601 or Unix timestamps and produces localized-looking output from pattern repetition alone.

Usage

Use this principle when:

  • A UI framework needs to format dates in component attributes without pulling in a full ICU dependency
  • Date patterns must be user-configurable at runtime (e.g. `"yyyy-MM-dd"` vs `"MMM d, yyyy"`)
  • Both ISO 8601 strings and Unix timestamps need to be accepted as input

Theoretical Basis

# Abstract algorithm (NOT real implementation)
def format_with_tr35(timestamp, pattern):
    tm = to_local_time(timestamp)
    result = ""
    i = 0
    while i < len(pattern):
        if pattern[i] in TOKEN_CHARS:  # y, M, d, E, H, h, m, s, a
            token = pattern[i]
            count = count_consecutive(pattern, i, token)
            result += format_token(tm, token, count)
            i += count
        else:
            result += pattern[i]  # literal character
            i += 1
    return result

The repeat-count semantic:

Pattern: "yyyy-MM-dd HH:mm:ss"
Tokens:  yyyy(4)→"2024"  -  MM(2)→"03"  -  dd(2)→"15"
         (space) HH(2)→"14" : mm(2)→"30" : ss(2)→"00"
Output:  "2024-03-15 14:30:00"

Practical Guide

  • Use pattern tokens in the `format` argument of the `formatDate` function call.
  • Accept both ISO 8601 strings (`"2024-03-15T14:30:00Z"`) and Unix timestamps in milliseconds.
  • Non-token characters in the pattern are emitted literally — use them for separators (`-`, `/`, `:`, spaces).

Related Pages

Implemented By

Related Principles

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment