topmark.utils.timestamp¶
Timestamp helpers used across TopMark.
This module centralizes timestamp sources and string formatting so that:
- internal timestamps are consistently represented in UTC;
- machine-readable output can use ISO-8601 strings; and
- unified diff headers can use GNU diff / git-style timestamps.
Naming convention:
- get_* functions return datetime objects (UTC).
- format_* functions return strings in a specific, documented format.
get_utc_now ¶
get_path_mtime_utc ¶
Return the file's modification time as an aware UTC datetime.
Falls back to get_utc_now() when the mtime cannot be read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file. |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
The file's |
Source code in src/topmark/utils/timestamp.py
format_iso8601_timestamp ¶
Return an ISO-8601 timestamp string in UTC.
If dt is not set, uses the current time.
All timestamps are converted to UTC offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime | None
|
An optional |
None
|
Returns:
| Type | Description |
|---|---|
str
|
ISO-8601 timestamp string in UTC (e.g. |
Source code in src/topmark/utils/timestamp.py
format_gnu_diff_timestamp ¶
Return a GNU diff / git-style timestamp string in UTC.
This format is suitable for unified diff header date fields.
If dt is not set, uses the current time.
All timestamps are converted to UTC offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime | None
|
An optional |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string representing the GNU diff timestamp (e.g., '2026-02-21 19:16:49 +0000'). |