Knowledgebase

Working With Dates and Times Print

  • python, woocommerce, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Handling time correctly.

WHY IT IS DIFFICULT

Time zones, formats, and the difference between a date and a moment.

WHAT PYTHON PROVIDES

Types for dates, times, combined values, and durations.

WHAT TO BE CLEAR ABOUT

Whether a value carries a time zone.

A value without one is ambiguous, and mixing the two causes errors.

WHAT TO PREFER FOR ANYTHING STORED

Values carrying a time zone, or an explicit convention applied everywhere.

WHAT TO STORE

A consistent standard internally, converting for display.

WHY

Converting at the edges and storing consistently prevents a large class of bugs.

PARSING TEXT INTO DATES

Explicit, with the format specified.

Never rely on guessing.

FORMATTING FOR DISPLAY

Also explicit.

WHAT TO BE CAREFUL WITH

Day and month order, which differs by region Daylight changes, where they apply Arithmetic across time zone boundaries

WHAT DURATIONS ARE FOR

Differences between times, and adding or subtracting periods.

WHAT TO VALIDATE

That parsed dates are plausible.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot