Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Guild of Archivists
Search
Editing
D'ni time conversion
(section)
From Guild of Archivists
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
Edit source
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Calendar Conversion Algorithms == === Required Functions === The following algorithms require the use of two functions, defined as follows: <pre>INT(x) = the greatest integer that does not exceed x. For example, INT(1.5) = 1, and INT(-1.5) = -2. FIX(x) = the value of x with the fractional portion removed. For example, FIX(1.5) = 1, and FIX(-1.5) = -1.</pre> Different programming languages may have different functions that perform these operations. For example, the INT function is known as the FLOOR function in some languages. The FIX function is sometimes known as the TRUNC function. Check the language reference for your programming language to be sure that you use the proper functions. === Gregorian Calendar Algorithms === The first two algorithms needed are those that convert Gregorian calendar dates to and from a version of the Julian day number. The algorithms are based on those provided by Peter Baum in an excellent [http://web.archive.org/web/20070613090550/http:/www.vsg.cape.com/~pbaum/date/date0.htm article] that gives the complete derivation of each algorithm, as well as implementation examples. The following algorithms differ from Baum's only in that the step of adding or subtracting the Julian base date of 1721118.5 is omitted, as this portion of the calculation is not needed for the purpose of Cavernian calendar conversion. The Julian Day used by these algorithms will be the number of days and fractions elapsed since midnight of the Gregorian date March 1, 0 CE. (Days are assumed to begin at the midnight that falls between the previous and current day, rather than at noon, as astronomers prefer.) No effort is made to account for leap seconds. ==== Algorithm 1. Gregorian Date to Julian Day Number ==== Assume a Gregorian date given as Day, Month, and Year, with optional time (on a 24-hour clock) given as Hour, Minute, and Second. All values are assumed to be integers. A. If the era of the date is BCE, convert the year to a CE year: <pre> Year = -(Year - 1)</pre> B. If the month is January or February, treat it as month 13 or 14 of the previous year. This step ensures that any leap days in the period fall at the end of a "year". <pre> if Month < 3 then Month = Month + 12 Year = Year - 1 end if</pre> C. Calculate the number of whole days (WD: an integer) that have elapsed. This is the number of days accounted for by the number of years that have passed, adjusted for leap days, plus the number of days accounted for by prior months in the current year, plus the day of the current month. <pre> WD = Day + FIX(((153 * Month) - 457) / 5) + INT(365.25 * Year) - INT(0.01 * Year) + INT(0.0025 * Year)</pre> D. Calculate fractional day (FD: a real number), if necessary. This is the time of day in seconds, expressed as a fraction of the total number of seconds in a day. If no time is included in the conversion, let FD = 0. <pre> FD = ((Hour * 3600) + (Minute * 60) + Second) / 86400</pre> E. Calculate Julian Day (JD: a real number) as: <pre> JD = WD + FD</pre> ==== Algorithm 2. Julian Day Number to Gregorian Date ==== Using real arithmetic, calculate Gregorian Year, Month, Day, Hour, Minute, and Second from a Julian Day (JD) that was calculated according to Algorithm 1. The input JD is assumed to be a real number. Output values are assumed to be integers. A. Extract the number of whole days and calculate the date: <pre> Z = INT(JD) G = Z - 0.25 A = INT(G / 36524.25) B = A - (0.25 * A) Year = INT((G + B) / 365.25) C = Z + B - INT(365.25 * Year) Month = FIX(((5 * C) + 456) / 153) Day = C - FIX(((153 * Month) - 457) / 5)</pre> B. If the month is 13 or 14, adjust the month and year to a January-1 starting point: <pre> if Month > 12 then Year = Year + 1 Month = Month - 12 end if</pre> C. The year is in CE form, meaning that years prior to 1 CE will be 0 or negative. To change such years to BCE form, use the calculation shown below. If this conversion is used, the program should include a variable indicating whether the date is CE or BCE. <pre> if Year < 1 then Year = 1 - Year</pre> D. If JD includes a fractional (time of day) part, extract the fraction and calculate the time: <pre> Z = (JD - INT(JD)) * 86400 Hour = FIX(Z / 3600) R = Z - (Hour * 3600) Minute = FIX(R / 60) Second = R - (Minute * 60)</pre> === Cavernian Calendar Algorithms === The next two algorithms needed are the Cavernian-calendar equivalents of the two algorithms above. We must be able to convert Cavernian date/time values to and from what I shall call the Atrian ''yahr'' number (named in honor of Atrus, son of Gehn), which is the number of ''yahrtee'' and fractions that have elapsed since a given base date. We will use Leefo 1, 9647 DE as our base for these algorithms, rather than Leefo 1, 0 DE, since this will simplify later conversions to and from the Gregorian calendar. (''Yahrtee'' are assumed to begin at the "midnight" β 00:00:00:00 ''gahrtahvotee''β that falls between the previous and current ''yahr''.) ==== Algorithm 3. Cavernian Date to Atrian Yahr Number ==== Assume a Cavernian date given as Yahr, Vailee, and Hahr, with optional time given as Gahrtahvo, Tahvo, Gorahn, and Prorahn. All values are assumed to be integers. A. Calculate the number of whole ''yahrtee'' (WY: an integer) that have elapsed. This is the number of ''yahrtee'' accounted for by the number of ''hahr'' that have passed, plus the number of ''yahrtee'' accounted for by prior ''vaileetee'' in the current ''hahr'', plus the ''yahr'' of the current ''vailee''. <pre> WY = Yahr + ((Vailee - 1) * 29) + ((Hahr - 9647) * 290)</pre> B. Calculate fractional ''yahr'' (FY: a real number), if necessary. This is the time of ''yahr'' in ''prorahntee'', expressed as a fraction of the total number of ''prorahntee'' in a ''yahr''. If no time is included in the conversion, let FY = 0. <pre> FY = ((Gahrtahvo * 15625) + (Tahvo * 625) + (Gorahn * 25) + Prorahn) / 78125</pre> C. Calculate Atrian ''Yahr'' (AY: a real number) as: <pre> AY = WY + FY</pre> ==== Algorithm 4. Atrian ''Yahr'' Number to Cavernian Date ==== Using real arithmetic, calculate Cavernian ''Hahr'', ''Vailee'', ''Yahr'', ''Gahrtahvo'', ''Tahvo'', ''Gorahn'', and ''Prorahn'' from an Atrian ''Yahr'' (AY) that was calculated according to Algorithm 3. The input AY is assumed to be a real number. Output values are assumed to be integers. A. Extract the number of whole ''yahrtee'' and calculate the date: <pre> Z = INT(AY) G = Z - 0.25 A = INT(G / 290) Hahr = 9647 + A C = Z - (A * 290) Vailee = INT((C - 0.25) / 29) + 1 Yahr = C - ((Vailee - 1) * 29)</pre> B. If AY includes a fractional (time of yahr) part, extract the fraction and calculate the time: <pre> Z = (AY - INT(AY)) * 78125 Gahrtahvo = FIX(Z / 15625) R = Z - (Gahrtahvo * 15625) Tahvo = FIX(R / 625) R = R - (Tahvo * 625) Gorahn = FIX(R / 25) Prorahn = R - (Gorahn * 25)</pre> === Cavernian/Gregorian Conversion Algorithms === With Julian Day and Atrian Yahr numbers firmly in hand, the conversion between the Cavernian and Gregorian calendars becomes extremely simple, as shown in the final two algorithms. ==== Algorithm 5. Cavernian Date to Gregorian Date ==== A. Calculate the Atrian ''Yahr'' (AY) for the Cavernian date, as per Algorithm 3. B. Using real arithmetic, determine the difference (AYD) between the AY of the selected date and the AY of the base Cavernian date for the conversion (which is 1.0). This gives the elapsed time in ''yahrtee'' and fractions. <pre> AYD = AY - 1.0</pre> C. Using real arithmetic, convert AYD from ''yahrtee'' to days to get the Julian Day difference (JDD). Add JDD to the Julian Day number of the base Gregorian date (which is 727249.704166666) to get the Julian Day number (JD) of the Cavernian date. <pre> JDD = AYD * 1.25945582758621 JD = JDD + 727249.704166666</pre> D. Convert the calculated Julian Day to a Gregorian date, as per Algorithm 2. ==== Algorithm 6. Gregorian Date to Cavernian Date ==== A. Calculate the Julian Day (JD) for the Gregorian date, as per Algorithm 1. B. Using real arithmetic, determine the difference (JDD) between the JD of the selected date and the JD of the base Gregorian date for the conversion (which is 727249.704166666). This gives the elapsed time in days and fractions. <pre> JDD = JD - 727249.704166666</pre> C. Using real arithmetic, convert JDD from days to ''yahrtee'' to get the Atrian ''Yahr'' difference (AYD). Add AYD to the Atrian ''Yahr'' number of the base Cavernian date (which is 1.0) to get the Atrian ''Yahr'' number (AY) of the Gregorian date. <pre> AYD = JDD * 0.793993705929756 AY = AYD + 1.0</pre> D. Convert the calculated Atrian ''Yahr'' to a Cavernian date, as per Algorithm 4.
Summary:
Please note that all contributions to Guild of Archivists may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
GoArch:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Navigation
Main Page
Random page
Categories
All pages
Recent changes
Resources
D'ni dictionary
Reference material
Utilities
Community
Forums
Jalak Game Directory
Projects
Apocrypha
Unexplored Branches
All projects
Contribute
Stubs
Wanted
Cleanup
Dead ends
Image requested
Help
Help
Guide
Policies
Wiki tools
Wiki tools
Special pages
Page values
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs