Home » Articles » My articles

Unified Day Number

GEDKeeper has many really nice coding stuffs. Let me reveal one such thing for you: Unified Day Number (UDN).

Every time you specify a date in GEDKeeper, for example, 'November 2, 2016', 'after July 15, 1976', 'October unknown day, 1900' and so on, UDN comes into play. Unified day number is a beast GEDKeeper uses under the hood when it's necessary to store and process dates.

Unified day number framework is based on Julian day and it is a way GEDKeeper stores continuous count of days since the beginning of the Julian Period. Just like as JDN, UDN is an integer value with some additional optional properties, like: "The date with unknown year", "Approximate date", etc. Set of such properties and the UDN value itself form one double word value (32 bits). Why do they fit one double word value? Because normal Julian day number is based on the Julian Period with size of 7980 years. The next Julian Period begins in the year 3268 AD. Thus, JDN upper limit is 0x2c7986 (0b1011000111100110000110). We need no more than 22 bits available for JDN. C#'s `uint` type provides us 32 bits. We couldn't resist the temptation to use the rest ten bits! Now six highest bits (26th-31th) are properties of the date, and the first twenty-six (0-25) bits are UDN (JDN) value.

Currently GEDKeeper's UDN framework supports the following types of dates:

  • A date before some date†,
  • A date after some date†,
  • An approximate date†,
  • A date between two dates‡,
  • A date with unknown year, or (and) unknown month, or (and) unknown day.

†A "date before" and a "date after" can't be approximate and vice versa.

‡A "date between" must have valid year number.

One of the most attractive thing I should mention about UDN is ability to order such dates. For example, GEDKeeper GUI shows 'near November 2016' right after the 'Before November 2, 2016'. That's how GEDKeeper orders UDNs:

  1. Dates with known parts are ordered as usual,
  2. A date with an unknown part is less than a date with the known one,
  3. A date "before date D" is less than a date "near date D",
  4. A date "near date D" is less than exact date D,
  5. Exact date D is less than a date "after date D".

A historical note: the UDN was born inside 'CalendarConverter' project on Bitbucket, which eventually became a part of GEDKeeper's main source code repository on GitHub.

Category: My articles | Added by: ruslanngaripov (21.05.2017) | Author: Ruslan Garipov
Views: 102 | Comments: 1 | Rating: 0.0/0
Total comments: 1
avatar
0
1 Norseman • 14:12, 23.05.2017
Nice!
avatar