NPlot.TradingDateTimeAxis.SparseWorldRemap C# (CSharp) Method

SparseWorldRemap() protected method

Remap a world coordinate into a "virtual" world, where non-trading dates and times are collapsed.
This code works under asumption that there are exactly 24*60*60 seconds in a day This is strictly speaking not correct but apparently .NET 2.0 does not count leap seconds. Luckilly, Ticks == 0 =~= 0001-01-01T00:00 =~= Monday First tried a version fully on floating point arithmetic, but failed hopelessly due to rounding errors.
protected SparseWorldRemap ( double coord ) : double
coord double world coordinate to transform.
return double
        protected double SparseWorldRemap(double coord)
        {
            long ticks = (long)coord;
            long whole_days = ticks / TimeSpan.TicksPerDay;
            long ticks_in_last_day = ticks % TimeSpan.TicksPerDay;
            long full_weeks = whole_days / 7;
            long days_in_last_week = whole_days % 7;
            if (days_in_last_week >= 5)
            {
                days_in_last_week = 5;
                ticks_in_last_day = 0;
            }
            if (ticks_in_last_day < startTradingTime_) ticks_in_last_day = startTradingTime_;
            else if (ticks_in_last_day > endTradingTime_) ticks_in_last_day = endTradingTime_;
            ticks_in_last_day -= startTradingTime_;

            long whole_working_days = (full_weeks * 5 + days_in_last_week);
            long working_ticks = whole_working_days * tradingTimeSpan_;
            long new_ticks = working_ticks + ticks_in_last_day;
            return (double)new_ticks;
        }