3 ms·
ISO 8601: Ending the Date Wars
- ezekg 6y agoOne neat thing about ISO 8601 that I learned recently is durations. For example, "P1M" is a 1 month duration. These can be used in frameworks like Rails to store durations in the database for things like subscriptions and then parsed: dt = Time.parse('2021-02-01 00:00:00 UTC') dt + ActiveSupport::Duration.parse('P1M') => 2021-03-01 00:00:00 UTC This takes care of calculating what a "month" actually is, instead of erroneously adding 30 days in seconds to the datetime, which can result in an inconsistent billing cycle: dt + 30.days.to_i => 2021-03-03 00:00:00 UTC