0

Clarification: I am not trying to calculate friendly times (e.g., "8 seconds ago") by using a timestamp and the current time.

I need to create a timeline of events in my data model, but where these events are only relative to each other. For example, I have events A, B, and C. They happen in order, so it may be that B occurs 20 seconds after A, and that C occurs 20 years after B.

I don't care about the unit of time. For my purpose, there is no time, just relativity.

I intend to model this like 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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Matt Norris
  • 8,596
  • 14
  • 59
  • 90
  • can the same event happen more than once? – Erik Sep 08 '11 at 02:08
  • Technically no, but it could be "told" more than once. For this, I intend to identify it with some unique ID, or have an event wrapper which determines the order (and is non-repeatable) and cotains the event (which is really the event *details* at that point). – Matt Norris Sep 08 '11 at 11:05

2 Answers2

0

I don't think you need to link to previous and next event, why not just use a timestamp and order by the timestamp?

If you can have multiple, simultaneous event timelines, then you would use some kind of identifier to identify the timeline (int, guid, whatever) and key that in witht the timestamp. No id is even necessary unless you need to refer to it by an single number.

Something like this:

Event

  • TimeLineID (key)
  • datetime (key)
  • Name
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
0

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

If you store normal everyday timestamp values, you already have relative time between events if they are all sequential, you just need to subtract them to get intervals which are what you are calling 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 things at sub-millisecond resolution, you would use nanoseconds

  • What if I had 2 events that were only a millisecond apart and wanted to insert an event in between them? Do you suggest I push the first event down 1 ms and the second event up 1 ms, then insert the new event in between? – Matt Norris Sep 08 '11 at 11:11
  • @Wraith there is such a thing as `nanoseconds` which is what you would be sampling at if you have sub-millisecond event resolution. –  Sep 08 '11 at 21:58
  • Thanks, Jarrod. What I really need is something that's not necessarily based on real time; something where I could insert events in between 2 events at will and not worry about the constraint of a unit. Is there any practice or pattern like that? – Matt Norris Sep 09 '11 at 10:54
  • My point is it is all relative you have to have a sequence of number that are relative to some starting point, real time is just a handy reference point. –  Sep 16 '11 at 16:19