-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: 30 Days

Среда, 04 Апреля 2018 г. 13:30 + в цитатник

Tim B did a little work with an e-learning vendor, with some very old code. The code in question happened to be so old that “this is server side JavaScript” was a horrifying novelty when they wrote it, instead of a standard deployment option via Node.

The code in question is bad date handling code, which isn’t impressive. What is impressive is that it demonstrates a terrible approach to dates which I’ve never seen before. It doubles as a terrible approach to arrays which I have seen before, but… it remains special.

  for (i=0; intMonthsToDisplay>0; i++)  
  {
        if (IsLeapYearDate(intMonth+i+1 +"/1/" + intYear) )  
        {
          strDaysInMonths = "312931303130313130313031312931303130313130313031"  
        }
        else  
        {
          strDaysInMonths = "312831303130313130313031312831303130313130313031"  
        }
        arrNoDaysInMonth[i] = parseInt(strDaysInMonths.substr((intMonth+i)*2,2));  
        intMonthsToDisplay = intMonthsToDisplay - 1;  
        intTotalDays = intTotalDays +arrNoDaysInMonth[i]  
  }

Yes, strDaysInMonths is our old “30 days has November…” rhyme, compressed down to two characters a month. I only wish Tim sent along the implementation of IsLeapYeaarDate, which I’m sure would be a thing to see.

[Advertisement] ProGet can centralize your organization's software applications and components to provide uniform access to developers and servers. Check it out!

https://thedailywtf.com/articles/30-days

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку