Date manipulation prior to Epoch | Sololearn: Learn to code for FREE!


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:

3/7/2018 12:15:31 AM


8 Answers

New Answer


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 :/


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!


@Swim oooo I will have to give it a try! Thanks!


@Jay, Don't know if this will work ! You can try giving negative value to epoch timestamp. Also take a look at chrono header.


@Eeshan, Please don't post out of context contents in someone's else thread. I hope you will take my comment in the right way.


Yeah thats a job for the historians, not us programmers :D



This explains the problem with time and timezones very well and in a funny way: In summary: read Schindlabua's answer :)