# Designing Storage for Different Time Systems

I've been considering doing some kind of application that allows users to track events in mythical settings. However, not all mythical settings allow for normal times. What if one user wants star dates, another wants BD/AD (Before Debbie/After Debbie, the heroine of an adventure?), another wants to count ticks from the start of the universe?

I'm trying to wrap my mind around displaying and entering these times in any way really. Not only that, but it's practically impossible to determine a good way of handling them "behind the scenes".

For instance, just using ticks everywhere and defining a new conversion as a paid-for service. Plus, what if one user decides their world exists from 1/1/0 to 1/1/2535100000000 (arbitrarily large number I assume will overflow float in ticks)? I tell them to pack their imaginations up and take a walk?

I'm probably overthinking it, but any input into the design of a system with this sort of requirement?

• There's no way to even start the discussion without actual use cases. May 31, 2016 at 22:49
• You cannot really store arbitrarily large numbers in a computer (or the universe, for that matter). There are hardware limits. If the range goes up, precision has to go down, there is no way around that.
– Hulk
Jun 1, 2016 at 9:51

As with all things software, 'unlimited' merely means 'limited by the system, not the developer'.

A 64-bit int would allow you to store 18446744073709551615 ticks.

# Precision vs Scale

Now, this is where you get to trade precision for scale. If you use ticks=microseconds, you'll get just over 1/2 million years to play with. Milliseconds gives you 1/2 billion. Once you decide the precision vs scale trade off in the system, just document it for your users so they know the range they can work within.

# Dynamic Range

The above makes it pretty clear that a 64-bit gives you plenty of leeway for working with during current times. However, if you someone to take arbitrary events (let's say the Big Bang and the Universe's heat death or Big Crunch), then it gets harder, but still possible!

The further in the past (or future) events are, the lower the precision you need. It is doubtful you need to allow the Big Bang's time/date to have a millisecond precision, or even a daily precision.

You could simply define ranges of your 'tick-space' that operate at different precision. For example:

``` [-86400000000, 86400000000] = Microseconds (+/- 1 million years) [-9223372036854775808,-86400000000) = Hours (-1 Quadrillion years) (86400000000, 9223372036854775808] = Hours (+1 Quadrillion years) ```

# Converting time to arbitrary schemes

I think storage here is your easy question, is the conversion function and how much freedom you give there that will. Do you just allow them to tweak values in a prefixed equation and formatting string, or do you give them some limited scripting language to do ad-hoc creations?