1. Список говнокодов пользователя valery_chistyakov

    Всего: 1

  2. C# / Говнокод #15935

    +124

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    private int MsUntilNextRefresh(DayOfWeek refreshDay, uint refreshHour)
    {
    	int days = 0;
    	if (DateTime.Now.DayOfWeek > refreshDay)
    		days = refreshDay + 7 - DateTime.Now.DayOfWeek;
    	else if (DateTime.Now.DayOfWeek < refreshDay)
    		days = refreshDay - DateTime.Now.DayOfWeek;
    	else
    		days = 7;
    
    	int hours = 0;
    	if (DateTime.Now.Hour > refreshHour)
    	{
    		days--;
    		hours = (int)refreshHour + 24 - DateTime.Now.Hour;
    	}
    	else if (DateTime.Now.Hour < refreshHour)
    	{
    		hours = (int)refreshHour - DateTime.Now.Hour;
    	}
    	return days * 86400000 + hours * 3600000 - DateTime.Now.Minute * 60000 - DateTime.Now.Second * 1000 - DateTime.Now.Millisecond;
    }

    классический индусский код, вместо:

    private int MsUntilNextRefresh(DayOfWeek refreshDay, uint refreshHour)
    {
    var dtnow = DateTime.UtcNow;
    var nextRefreshDate =
    dtnow.Date.AddDays(dtnow.DayOfWeek >= refreshDay ? dtnow.DayOfWeek + 7 - refreshDay : refreshDay - dtnow.DayOfWeek).AddHours(refreshHour);
    return (nextRefreshDate - dtnow).Milliseconds;
    }

    valery_chistyakov, 07 Мая 2014

    Комментарии (8)