Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » Indigo Rose AutoPlay Media Studio (часть 5)

Модерирует : gyra, Maz

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

Octanium



Junior Member
Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору

Код:
-- Calculation days between dates
-- Use: result = dbd(" date from "," date to ");
-- Date format: day.month.year
-- Example: deys = dbd("22.06.2014", "22.08.2016");
-- Error code: 0001 - incorrect data to calculate, "date to" later than "from date"
function dbd(dbd_date_from, dbd_date_to)
-- table month deys
dbd_tbl_month_deys = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
dbd_tbl_month_deys_ly = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
-- get date from, d - day, m - month, y - year
dbd_g_f_d = String.Mid(dbd_date_from, 1, 2) + 1 - 1;
dbd_g_f_m = String.Mid(dbd_date_from, 4, 2) + 1 - 1;
dbd_g_f_y = String.Mid(dbd_date_from, 7, 4) + 1 - 1;
 
-- get date to, d - day, m - month, y - year
dbd_g_t_d = String.Mid(dbd_date_to, 1, 2) + 1 - 1;
dbd_g_t_m = String.Mid(dbd_date_to, 4, 2) + 1 - 1;
dbd_g_t_y = String.Mid(dbd_date_to, 7, 4) + 1 - 1;
 
-- calculation is carried out within this year?
dbd_year_difference = dbd_g_t_y - dbd_g_f_y
dbd_deys_all = "0";
dbd_year_difference_mns = String.Mid(dbd_year_difference, 1, 1)
--determine the correct calculation, "date to" later than "from date"
if dbd_year_difference_mns ~= "-" then
 if dbd_year_difference == 0 then
 -- calculation of the difference in the current year
  dbd_year_calc = dbd_g_f_y + 1;
  dbd_month_difference = dbd_g_f_m - 1;
  -- calculation months
  repeat
    dbd_month_difference = dbd_month_difference + 1;
    --calculation the leap year
     if String.Find(dbd_g_f_y-(dbd_g_f_y/4), ".", 1, true) == -1 then
     -- leap year
      dbd_deys_all = dbd_deys_all + dbd_tbl_month_deys_ly[dbd_month_difference];
     else
    -- not leap year
      dbd_deys_all = dbd_deys_all + dbd_tbl_month_deys[dbd_month_difference];
     end
   until dbd_month_difference == dbd_g_t_m ;
   --calculation and removal of the difference
     if String.Find(dbd_g_f_y-(dbd_g_f_y/4), ".", 1, true) == -1 then
     -- leap year
      dbd_deys_del = (dbd_tbl_month_deys_ly[dbd_g_f_m] + dbd_tbl_month_deys_ly[dbd_g_t_m]) - ((dbd_tbl_month_deys_ly[dbd_g_f_m] - dbd_g_f_d) +  dbd_g_t_d);
     else
    -- not leap year
      dbd_deys_del = (dbd_tbl_month_deys_ly[dbd_g_f_m] + dbd_tbl_month_deys_ly[dbd_g_t_m]) - ((dbd_tbl_month_deys[dbd_g_f_m] - dbd_g_f_d) +  dbd_g_t_d);
     end
   dbd_deys_all = dbd_deys_all - dbd_deys_del;
 else
 -- calculation the difference considering years
 -- Calculate years
  dbd_year_calc = dbd_g_t_y + 1;
  dbd_year_difference = dbd_year_difference + 1;
  repeat
    dbd_year_difference = dbd_year_difference - 1;
    dbd_year_calc  = dbd_year_calc  - 1;
    --calculation the leap year
     if String.Find(dbd_year_calc-(dbd_year_calc/4), ".", 1, true) == -1 then
     -- leap year
      dbd_deys_all = dbd_deys_all + 366;
     else
    -- not leap year
      dbd_deys_all = dbd_deys_all + 365;
     end
  until dbd_year_difference == 0 ;
 
  -- calculation months, year from
  dbd_month_difference = "0";
  dbd_mf_difference = "0";
  repeat
    dbd_month_difference = dbd_month_difference + 1;
    --calculation the leap year
     if String.Find(dbd_g_f_y-(dbd_g_f_y/4), ".", 1, true) == -1 then
     -- leap year
      dbd_mf_difference = dbd_mf_difference + dbd_tbl_month_deys_ly[dbd_month_difference];
     else
    -- not leap year
      dbd_mf_difference = dbd_mf_difference + dbd_tbl_month_deys[dbd_month_difference];
     end
  until dbd_month_difference == dbd_g_f_m ;
  --calculation and removal of the difference
  dbd_deys_all = dbd_deys_all - (dbd_mf_difference - (dbd_tbl_month_deys[dbd_g_f_m] - dbd_g_f_d));
 
  -- calculation months, year to
  dbd_month_difference = "0";
  dbd_mt_difference = "0";
  repeat
    dbd_month_difference = dbd_month_difference + 1;
    --calculation the leap year
     if String.Find(dbd_g_t_y-(dbd_g_t_y/4), ".", 1, true) == -1 then
     -- leap year
      dbd_mt_difference = dbd_mt_difference + dbd_tbl_month_deys_ly[dbd_month_difference];
     else
    -- not leap year
      dbd_mt_difference = dbd_mt_difference + dbd_tbl_month_deys[dbd_month_difference];
     end
   until dbd_month_difference == dbd_g_t_m;
   --calculation and removal of the difference
   dbd_mt_difference = dbd_mt_difference - (dbd_tbl_month_deys[dbd_g_t_m] - dbd_g_t_d);
   --calculation the leap year
    if String.Find(dbd_g_t_y-(dbd_g_t_y/4), ".", 1, true) == -1 then
    -- leap year
     dbd_mt_difference = 366 - dbd_mt_difference
    else
   -- not leap year
     dbd_mt_difference = 365 - dbd_mt_difference
    end
   dbd_deys_all = dbd_deys_all - dbd_mt_difference;
 end
else
 --give an error code
 dbd_deys_all = "0001";
end
 return dbd_deys_all
end

Всего записей: 50 | Зарегистр. 07-02-2011 | Отправлено: 19:36 11-09-2016 | Исправлено: Octanium, 19:50 26-10-2016
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » Indigo Rose AutoPlay Media Studio (часть 5)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru