Clarion date and time in .NET

In Clarion date is defined as follows:
number of days that have elapsed since December 28, 1800
Why? I think that’s when Seoftvelsocity CTO’s grandgrandma reached Florida but they say its because this date was inherited from Btrieve Record Manager. Well. Cool, but in .NET DateTime looks different. How to get a Clarion Date for a given .NET date?
public static int GetOLDate(DateTime dotNetDate)
{
CultureInfo ci = new CultureInfo("de-DE");
DateTime baseDate = DateTime.Parse("01.01.1801", ci);
System.TimeSpan ts = dotNetDate - baseDate;
int l = ts.Days + 4;
return l;
}

How does Clarion defines time?
Number of hundredths of a second that have elapsed since midnight, plus one.
How to manage this in .NET?
public static int GetOLTime(DateTime now)
{
int l = now.Hour * 360000;
l += now.Minute * 6000;
l += now.Second * 100;
l += now.Millisecond / 10;
return l + 1;
}

And another way around?
public static DateTime GetTime(int clarionTime, DateTime baseDate)
{
int lHours = Convert.ToInt32(clarionTime / 360000);
int lMinutes = Convert.ToInt32((clarionTime - (lHours * 360000)) / 6000);
int lSeconds = Convert.ToInt32((clarionTime - (lHours * 360000) - (lMinutes * 6000)) / 100);
int lMiliseconds = (clarionTime - (lHours * 360000) - (lMinutes * 6000) - (lSeconds * 100)) * 10;
DateTime then = new DateTime(baseDate.Year, baseDate.Month, baseDate.Day, lHours, lMinutes, lSeconds);
return then;
}

Hope it will help!
Originally published at Sunday, November 26, 2006

Leave a Reply

Your email address will not be published. Required fields are marked *