How to simulate the "relative" time in the database?

Clarification: I am not trying to calculate friendship times (for example, β€œ8 seconds ago”) using a timestamp and current time.

I need to create an event timeline in my data model, but where these events relate only to each other. For example, I have events A, B and C. They occur in order, so it may be that B occurs 20 seconds after A, and C - 20 years after B.

I do not need a unit of time. There is no time for my purpose, just relativity.

I intend to simulate this as a linked list , where each event is a node:

Event

  • id
  • name
  • prev_event
  • next_event

Is this the most efficient way to model relative events?

0
source share
2 answers

All the time recorded by computers , relative time, nominally it refers to the era as an offset in milliseconds. Usually this era is an offset from 1970/01/01, as is the case with Unix .

If you keep the usual daily timestamp values, you already have the relative time between events, if all of them are consecutive, you just need to subtract them to get the intervals that you call relative times but they are actually intervals .

You can use whatever resolution you need to use, milliseconds is what most things use, if you are sampling at submillisecond resolution you should use nanoseconds

0
source

I don’t think you need to refer to the previous and next event, why not just use the timestamp and timestamp order?

If you can have several simultaneous deadlines for events, then you should use some kind of identifier to determine the timeline (int, guid, whatever) and the key, which is located in the timeline. No identifier is required unless you need to reference it with a single number.

Something like that:

Event

  • TimeLineID (key)
  • datetime (key)
  • Name
0
source

Source: https://habr.com/ru/post/896971/


All Articles