Epicor ClockInMInutes and ClockOutMinutes to and from DateTime, decimal time

Working on a few projects lately where I need to work with the ClockInMInute (capital I intentional) and ClockOutMinute data in LaborDtl. There are some other posts on here with the SQL to convert datetime data to clock minutes. I thought I would share some of the C# helpers I am using.

ClockInMInute and ClockOutMinute are stored as number of minutes since 1953-10-30 00:00:00. Knowing that, we can calculate datetimes based on minutes or convert minutes into datetime.

I also added a DspClockIn string time to decimal time function - I’m sure there are many out there already.

class Tests { 
    static void Main()
    {
        var t = new TimeHelpers();
        DateOnly TestDate = new DateOnly(2023,10,11);  //date only field
        Decimal TestTime = 16.45m; //decimal time for 16:27 (4:27PM)
        DateTime TestDateTime = new DateTime(2023, 10, 11, 16, 27, 0);
        string TestDspTime = "21:17"; // epicor display is 24h
        int TestMinutes = t.ConvertToEpicorMinutesFromDecimalTime(TestDate, TestTime);
        Console.WriteLine(TestMinutes.ToString()); // Epicor Minutes
        Console.WriteLine(TestDateTime.ToString() + " : " + t.ConvertToEpicorMinutesFromDateTime(TestDateTime).ToString()); // Epicor Minutes
        Console.WriteLine(t.ConvertEpicorMinutesToDateTime(TestMinutes).ToString("yyyy-MM-dd HH:mm")); //should equal test date and time
        Console.WriteLine("Dsp Format:" + TestDspTime + " Decimal: " + t.TimeToDecimalTime(TestDspTime).ToString()); //should be decimal version of TestDspTime
        Console.WriteLine("Now: " + t.EpicorMinutesNow().ToString());
        Console.WriteLine("Epicor Birth: " + t.EpicorBirth);
    }
}
class TimeHelpers
{
    public int ConvertToEpicorMinutesFromDateTime(DateTime InDate)
    {
        int EpicorMinutes = 0;
        DateTime EpicorBirth = new DateTime(1953, 10, 30, 0, 0, 0);
        EpicorMinutes = Convert.ToInt32((InDate - EpicorBirth).TotalMinutes);
        return EpicorMinutes;
    }
    public int ConvertToEpicorMinutesFromDecimalTime(DateOnly InDate, decimal Time)
    {
        int EpicorMinutes = 0;
        DateTime EpicorBirth = new DateTime(1953, 10, 30, 0, 0, 0);
        DateTime Day = InDate.ToDateTime(TimeOnly.Parse("00:00:00"));
        int TodayMinutes = Convert.ToInt32(Math.Floor(Time * 60));
        int SpanMinutes = Convert.ToInt32((Day - EpicorBirth).TotalMinutes);
        EpicorMinutes = SpanMinutes + TodayMinutes;
        return EpicorMinutes;
    }
    public DateTime ConvertEpicorMinutesToDateTime (int EpicorMinutes)
    {
        DateTime EpicorBirth = new DateTime(1953, 10, 30, 0, 0, 0); 
        int Mins = EpicorMinutes % 1440;
        int Days = Convert.ToInt32(Math.Floor( EpicorMinutes / 1440m));
        DateTime date = EpicorBirth.AddDays(Days).AddMinutes(Mins);
        return date;
    }
    public decimal TimeToDecimalTime(string timeString)
    {
        decimal TimeDecimal = 0m;
        TimeOnly time = TimeOnly.Parse(timeString);
        TimeDecimal = time.Hour + Math.Round((time.Minute / 60m), 2);
        return TimeDecimal;

    }
    public int EpicorMinutesNow()
    {
        DateTime EpicorBirth = new DateTime(1953, 10, 30, 0, 0, 0);
        return Convert.ToInt32((DateTime.Now - EpicorBirth).TotalMinutes);
    }
    public DateTime EpicorBirth { get { return new DateTime(1953, 10, 30, 0, 0, 0); } private set { } }
}

PS - does anyone know the significance of 1953-10-30? I assume someone’s birthday?

:grinning:

It’s Chip Ziering’s birthday I believe.

https://www.finpug.fi/historiaa/a-history-of-progress/

https://community.progress.com/s/question/0D54Q00008CmT0xSAF/encode-humor

It was actually an Epicor developer (DCD at the time the function was coded). Orv Rehfeldt.

Orv is the subject of one of my “look how far technology has come stories”.
Back in the mid 2000’s, Orv and his wife decided they wanted a simpler life and they moved from Minneapolis to their 2nd home in northern Minnesota. Orv still wanted to work for Epicor (and Epicor still wanted Orv) but the 2nd home did not have fast enough connectivity (or they had no phone service) so Orv would go to the local town where his wife had a resale shop and he worked from a desk in the back of the store.
After a few years, one of the trees on their property grew tall enough that they could install a line-of-sight microwave link so he was able to work from home.