Skip to main content

Module pattern

Module pattern 

Source
Expand description

Strftime-subset pattern parser shared by DateEdit and TimeEdit.

Supported tokens:

TokenMeaning
%Y4-digit year (zero-padded; sign printed for negatives)
%m / %-m2-digit / 1-or-2-digit month
%d / %-d2-digit / 1-or-2-digit day
%H / %-H24-hour hour
%I / %-I12-hour hour
%M / %-Mminute
%S / %-Ssecond
%pAM/PM (12-hour mode)
%%literal %

Anything else between tokens is preserved verbatim as a literal separator. Locale-localized literal text (%B / %A) is deliberately NOT supported here — month and weekday names come from tr! keys, not from the pattern.

Structs§

ParsedPattern
A pattern parsed into segments + literals, ready for formatting and reverse parsing.

Enums§

ParseTarget
What kind of value is being parsed.
ParsedValue
Parsed value.
PatternError
Pattern parse errors.
PatternToken
One token in a parsed pattern.
SegmentKind
What a segment edits.

Functions§

format_value
Format a Date against a parsed pattern. Time segments emit “00”.
mask_for_pattern
Build an InputMask grammar string from a parsed pattern. Each digit segment becomes the corresponding number of 9 chars; the AM/PM period segment becomes >AA (two uppercase-locked letters); literals stay as fixed separators.
parse_value
Reverse-parse a string against a pattern.
render_segment
Format a value into its segment string.
segment_at_position
Find the segment under caret_pos (in formatted-text display coordinates). A caret resting on a segment boundary belongs to the segment to its right (typing-into semantics). A caret on a separator snaps to the preceding segment so Up/Down keep working when the caret is between two segments. Returns None only when the pattern has no editable segments at all.
segment_value_for_date
What a segment evaluates to. Year can be negative; the rest are non-negative integers. Period is 0 for AM, 1 for PM.
segment_value_for_time
Time-half evaluator.
segments_layout
One editable segment’s span in formatted-text display coordinates. (start_char_offset, end_char_offset_exclusive, kind). Computed by walking ParsedPattern::tokens and accumulating the rendered width of each segment (4 for Year, 2 for Period (AM/PM), 2 for every digit segment) and each literal. Drives caret-in- segment lookups for segment-stepping and per-segment selection.
step_date_field
Step a single field of a Date by delta. Year saturates at the jiff range and clamps the day if the new year+month no longer holds the current day (e.g. Feb 29 → Feb 28 in non-leap years). Month wraps within [1, 12] and clamps the day to the new month’s last day. Day wraps within the current month — does not advance to the next month, matching Qt QDateEdit and macOS Calendar behaviour. Returns the input date unchanged when kind is not a date field.
step_time_field
Step a single field of a Time by delta. Hour wraps in [0, 24) (whether 12h or 24h segment kind — internal storage is 24h). Minute and second wrap in [0, 60). AM/PM toggles on any non-zero delta (sign-agnostic). Returns the input time unchanged when kind is not a time field.