+ 29

Date manipulation prior to Epoch

I was wondering if anyone knows a method using the STL or custom methods (not boost) of manipulating dates that are prior to epoch. I have tried storing the dates in std::tm (it goes back to the year 1900), but once I manipulate values, the tm structure must be normalised using mktime to enable correct calculations ( which uses time_t type) Am I in for a world of pain here? or is there a way to easily manage negative 'since epoch' values? Example code: https://code.sololearn.com/coVs933C19v5/?ref=app

7th Mar 2018, 12:15 AM
jay
jay - avatar
8 Answers
+ 20
I guess you could add 1000 years to all your dates and calculate with those. It wouldn't really be accurate though. Unix time is easy because it keeps ticking forward (unless leap seconds are happening), but before epoch there was lots of weird stuff going on in calendars. We have clocks moving back by five and a half minutes and missing days and different dates in different places. For example the day after 5th of October 1582 was the 15th, but only in spain. Isaac Newton was born in 1643 or 1642 depending on who you ask. For stuff like that you just need a library. There's tons of exceptions like that. And I suppose the standard library doesn't have them all built in. Dates are hard :/
7th Mar 2018, 12:47 AM
Schindlabua
Schindlabua - avatar
+ 13
So a world of pain :) I will just stick to since epoch. I didn't really have an absolute requirement for a method of working with dates prior to epoch, I just wanted to do it, to see if I could. Thanks Schindlabua!
7th Mar 2018, 12:50 AM
jay
jay - avatar
+ 8
@Swim oooo I will have to give it a try! Thanks!
8th Mar 2018, 11:01 PM
jay
jay - avatar
+ 5
Yeah thats a job for the historians, not us programmers :D
7th Mar 2018, 12:56 AM
Schindlabua
Schindlabua - avatar
+ 5
good job for java
8th Mar 2018, 10:45 AM
Ahmed Mahmoued Abd El Metaal Abd Allah
Ahmed Mahmoued Abd El Metaal Abd Allah - avatar
+ 3
This explains the problem with time and timezones very well and in a funny way: https://www.youtube.com/watch?v=-5wpm-gesOY&t=312s In summary: read Schindlabua's answer :)
7th Mar 2018, 8:51 PM
Freddy