TOML (Tom’s Obvious, Minimal Language) is a simple and easy-to-read configuration file format commonly used in software applications. One of its standout features is how it handles date and time values — making them both human-friendly and efficient. In this guide, we’ll take a closer look at how dates and times work in TOML, how to define and use them in a TOML file.
What is TOML Date & Time?
TOML provides native support for dates, times, and timestamps, adhering to the RFC 3339 standard, which is a stricter subset of ISO 8601. This format is widely used in programming languages, APIs, and logging systems.
Why Use RFC 3339 in TOML?
- Avoids timezone confusion when handling timestamps across regions.
- Supports fractional seconds for precise logging, debugging, and analytics.
- Provides a standard format for APIs, databases, and automation tools.
Types of Date-Time Representations in TOML
TOML supports four types of date-time representations:
- Offset Date-Time (Includes date, time, and timezone offset)
- Local Date-Time (Includes date and time without a timezone)
- Local Date (Only the date without time)
- Local Time (Only the time without date)
Let’s explore each of these in detail with examples.
Offset Date-Time
Offset Date-Time includes the date, time, and timezone offset from UTC. This is useful when you need to store timestamps with explicit timezone information.
A small but important question — what does ‘offset’ mean when defining date and time?
In date-time representation, an offset indicates the difference between a specific local time and Coordinated Universal Time (UTC). It’s usually written in the format ±hh:mm, where:
‘+’ means the time is ahead of UTC
‘-’ means the time is behind UTC
So, why is the offset important?
Offsets are essential for adjusting time across different regions. They help ensure accurate time conversions and prevent errors when working with time zones, logs, and scheduling across multiple locations.
# Offset Date-Time example
utc_datetime = 2025-02-03T14:30:00Z # Coordinated Universal Time (UTC)
india_datetime = 2025-02-03T14:30:00+05:30 # India (UTC+5:30)
ny_datetime = 2025-02-03T14:30:00-05:00 # New York (UTC-5)
Here,
2025-02-03
→ Represents the date (Year-Month-Day)T
→ Separates the date and time (can be replaced with a space)14:30:00
→ Represents the time in HH:MM:SS format- The
Z (Zulu time)
at the end ofutc_datetime
means it’s in Coordinated Universal Time (UTC with no offset). india_datetime
uses+05:30
, meaning it is 5 hours and 30 minutes ahead of UTC.ny_datetime
uses-05:00
indicating it is 5 hours behind UTC.
Additional Examples for Clarity
Let’s go through a few more examples to deepen our understanding and see how different scenarios are handled.
odt1 = 1979-05-27T07:32:00Z # UTC time (Zulu time)
odt2 = 1979-05-27T00:32:00-07:00 # Same instant, but in UTC-07:00
odt3 = 1979-05-27T00:32:00.999999-07:00 # Includes microseconds
# Alternate format using a space instead of 'T'
odt4 = 1979-05-27 07:32:00Z # Equivalent to odt1
odt1 = 1979-05-27T07:32:00Z
This means May 27, 1979, at 07:32:00 AM in UTC (Zulu time).
odt2 = 1979-05-27T00:32:00-07:00
This means May 27, 1979, at 00:32:00 AM in UTC-7 (Pacific Time Zone).
- If converted to UTC, it is 07:32:00 AM UTC (same as
odt1
).
odt3 = 1979-05-27T00:32:00.999999-07:00
Similar to odt2
, but includes microseconds (0.999999 seconds) for higher precision.
odt4 = 1979-05-27 07:32:00Z
Same as odt1
, but replaces T
with a space for readability.
Please note that:
You can replace the
T
between the date and time with a space for readability (e.g.,1979-05-27 07:32:00Z
).Fractional seconds (e.g.,
.999999
) are supported but not required. If extra precision is provided beyond the system’s capability, it should be truncated (cut off), not rounded.
Real-World Example: Server Logs
Imagine a log file that records important system events:
[server_restart]
event = "System Reboot"
timestamp = 2025-02-04T14:15:30.456789Z
[user_login]
user = "tony"
login_time = 2025-02-04T08:15:30-06:00 # tony logs in from a UTC-6 region
[database_backup]
backup_time = 2025-02-04T23:59:59.999999+05:30 # India Standard Time (UTC+5:30)
This ensures that every event has an unambiguous timestamp, regardless of the time zone. When timestamps include a time zone offset or are stored in UTC, they can be consistently converted and compared across different regions.
Local Date-Time (Without Time Zone)
A Local Date-Time includes the date and time but does not have any timezone information.
# Local Date-Time example
scheduled_at = 2025-02-15T09:00:00
2025-02-15T09:00:00
→ Represents date and time without timezone.- The given date-time values are local (not tied to UTC or any time zone).
- Without an offset (
Z
or±hh:mm
), these timestamps cannot be converted to a global instant without additional context (e.g., knowing the intended timezone). - Used for cases where timezone conversion is not needed, such as for timestamps in local logs.
Use Case: Event Scheduling in a Local System
Imagine you’re building a conference scheduling system where sessions are stored in a TOML file. Since the schedule is based on the local time at the venue (not tied to UTC), we omit the timezone offset.
# Conference schedule stored in local time
conference = "softAai Tech Summit 2025"
# Sessions without timezone (assumed to be in the local conference timezone)
session1_start = 2025-06-15T09:00:00 # 9:00 AM
session1_end = 2025-06-15T10:30:00.500 # 10:30 AM with 500 milliseconds
session2_start = 2025-06-15T11:00:00 # 11:00 AM
session2_end = 2025-06-15T12:30:00.123 # 12:30 PM with 123 milliseconds
# Break time
lunch_start = 2025-06-15T12:30:00
lunch_end = 2025-06-15T13:30:00
Here,
- The times do not include a timezone, meaning they are defined in local time (e.g., IST). This is fine as long as everyone knows the conference is in India and follows the same local time.
- If different users in different time zones view this, they will not get an accurate conversion unless they know the correct timezone.
- Microseconds (e.g.,
.500
and.123
) provide precision but may be truncated in some implementations.
Milliseconds (
.SSS
) are required, but beyond that (microseconds/nanoseconds) is implementation-specific. If an application doesn’t support high precision, extra precision is truncated (cut off) instead of rounded.
Impact of Including a Timezone
What happens when a user from London checks the schedule? If the timezone offset isn’t included, they might be unsure whether the times are in UTC, IST, or another local time. To avoid confusion, it’s best to include an offset to make the times clear.
If you want to ensure everyone interprets the time correctly, always include a timezone offset:
# Session timings with time zone offsets
session1_start = 2025-06-15T09:00:00+05:30 # 9:00 AM IST (UTC+5:30)
session1_end = 2025-06-15T10:30:00.500+05:30 # 10:30 AM IST (with milliseconds)
session2_start = 2025-06-15T11:00:00+05:30 # 11:00 AM IST
session2_end = 2025-06-15T12:30:00.123+05:30 # 12:30 PM IST (with milliseconds)
Now, even if someone from New York or London checks the schedule, they will understand exactly what time it corresponds to in their local timezone by calculating the difference from the provided offset.
So,
Use local date-time (without offset) when:
- The time is fixed to a specific place (e.g., event in one location).
- You don’t need to convert it globally.
And use date-time with an offset when:
- You need to convert times across time zones.
- The event can be attended globally.
Local Date (Date Without Time)
Sometimes, you only need a date without specifying a time.
# Local Date example
release_date = 2025-07-20
2025-07-20
→ Represents an entire day (July 20, 2025) without any connection to time zones or time offsets.
This format is useful when you want to record an event or action that occurred on a specific day but don’t need to worry about the exact time or time zone. For example, birthdays, holidays, or historical events can be recorded simply by their date, without the need to specify the exact time. The day itself remains the same, regardless of where you are in the world.
In short, a Local Date is:
- A representation of just the date, without time or time zone.
- Used for events or information tied to a specific day, not a particular moment in time.
Local Time (Time Without Date)
Local Time, on the other hand, focuses purely on the time of day, without any reference to a specific date or time zone. This format captures only the hour, minute, second, and possibly fractions of a second, but it is not concerned with the day or any time zone offset.
# Local Time example
backup_time = 23:45:00
23:45:00
→ Represents time in HH:MM:SS format- Useful for defining daily recurring events like alarms or job schedules.
The idea behind Local Time is that you may want to capture a precise time of day without associating it with any specific date or time zone. For instance, when setting alarms or schedules, you might be concerned only with a specific time during the day, not a particular day or location.
However, an important note when dealing with Local Time is precision. In this case (23:45:00.999999
), the time is expressed in microsecond precision (down to six decimal places), but systems might not support this level of precision. If the system can’t handle such precision, it’s important to truncate (remove the extra digits) rather than round the value. Truncating means simply cutting off the extra digits, ensuring that the time stays within the system’s capabilities.
In short, Local Time is:
- A representation of just a time, without linking it to any specific date or time zone.
- Used when you need to capture a specific time of day without worrying about the date or location.
- Potentially expressed in very fine precision, but systems must truncate if they can’t support such precision.
Why Use TOML for Date & Time?
TOML simplifies date and time handling by:
- Providing a structured and standardized format (RFC 3339 / ISO 8601)
- Making it human-readable and easy to edit
- Reducing ambiguity compared to formats like JSON (which often stores timestamps as strings)
- Being widely supported in modern programming languages
Conclusion
TOML provides an easy and efficient way to handle dates and times in a structured format. Whether you need timezone-aware timestamps, local dates, or recurring time events, TOML makes it simple and readable. Understanding these formats will help you better manage configurations in software projects while maintaining clarity and consistency.
Now that you have a strong grasp of TOML Date & Time, try using it in your projects and see how it simplifies time handling..!