Strict RFC3339

0.7 · maintenance · verified Sun Apr 12

strict-rfc3339 is a Python library providing strict, simple, and lightweight functions for converting Unix timestamps to and from RFC3339 formatted strings. It aims to avoid the complexities of timezones as much as possible, focusing on strict adherence to the RFC3339 standard. The current version is 0.7, with development appearing to be in maintenance mode, as the last release was in April 2016.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain the current time in RFC3339 format (UTC or local offset), validate an RFC3339 string, and convert between RFC3339 strings and Unix timestamps. It highlights the library's core functionalities for strict RFC3339 handling.

import strict_rfc3339
import time

# Get current UTC time as RFC3339 string
rfc3339_now_utc = strict_rfc3339.now_to_rfc3339_utc()
print(f"Current UTC RFC3339: {rfc3339_now_utc}")

# Get current local time as RFC3339 string with local offset
rfc3339_now_local = strict_rfc3339.now_to_rfc3339_localoffset()
print(f"Current Local RFC3339: {rfc3339_now_local}")

# Validate an RFC3339 string
is_valid = strict_rfc3339.validate_rfc3339("2023-10-27T10:00:00Z")
print(f"'2023-10-27T10:00:00Z' is valid: {is_valid}")

is_invalid = strict_rfc3339.validate_rfc3339("some rubbish")
print(f"'some rubbish' is valid: {is_invalid}")

# Convert RFC3339 to Unix timestamp
timestamp = strict_rfc3339.rfc3339_to_timestamp("2023-10-27T10:00:00+00:00")
print(f"Timestamp for '2023-10-27T10:00:00+00:00': {timestamp}")
print(f"Time tuple (UTC): {time.gmtime(timestamp)[:6]}")

# Convert Unix timestamp to RFC3339 (UTC)
new_rfc3339_utc = strict_rfc3339.timestamp_to_rfc3339_utc(timestamp)
print(f"Timestamp {timestamp} to RFC3339 UTC: {new_rfc3339_utc}")

view raw JSON →