Aspectacular.DateTimeExtensions.FromSortableIntDateTime C# (CSharp) Method

FromSortableIntDateTime() public static method

Returns DateTime created from an integer in the YYYYMMDD, YYYYMMDDHHmmss, or YYYYMMDDHHmmssFFF format.
public static FromSortableIntDateTime ( this sortableDateTime, DateTimeKind dtKind = DateTimeKind.Unspecified ) : System.DateTime
sortableDateTime this
dtKind DateTimeKind
return System.DateTime
        public static DateTime FromSortableIntDateTime(this long sortableDateTime, DateTimeKind dtKind = DateTimeKind.Unspecified)
        {
            const byte digitsInDateOnly = 4 + 2 + 2;
            byte totalDigits = (byte)((int)Math.Log10(sortableDateTime) + 1);
            byte timePartDigits = (byte)(totalDigits - digitsInDateOnly);
            int timePartOrder = (int)10.Pow(timePartDigits);

            int sortableDate = (int)(sortableDateTime/timePartOrder); // YYYYMMDD
            int day = sortableDate%100;
            sortableDate /= 100;
            int month = sortableDate%100;
            sortableDate /= 100;
            int year = sortableDate;

            DateTime dt = new DateTime(year, month, day, 0, 0, 0, dtKind);

            long sortableTimePart = sortableDateTime%timePartOrder; // 0, YYYYMMDDHHmmss, or YYYYMMDDHHmmssFFF
            if(sortableTimePart > 0)
                dt = sortableTimePart.FromSortableIntTime(dt);

            return dt;
        }

Same methods

DateTimeExtensions::FromSortableIntDateTime ( this sortableDateTime, DateTimeKind dtKind = DateTimeKind.Unspecified ) : DateTime?