Example #1
0
// Lчтыхў№ Hour:Min:Sec шч яюыэющ фрЄv/тЁхьхэш Date
void time_decode(date_time D, int *Hour, int *Min, int *Sec) {
  double Int;  int Secs;
  Secs=(int)(modf(D+Second/2,&Int)*24*3600);
  DivMod(Secs,3600,Hour,&Secs);
  DivMod(Secs,60,Min,&Secs);
  *Sec=Secs;
}
Example #2
0
void DecodeTime(const TDateTime & DateTime, unsigned short & Hour,
  unsigned short & Min, unsigned short & Sec, unsigned short & MSec)
{
  uintptr_t MinCount, MSecCount;
  DivMod(DateTimeToTimeStamp(DateTime).Time, 60000, MinCount, MSecCount);
  uintptr_t H, M, S, MS;
  DivMod(MinCount, 60, H, M);
  DivMod(MSecCount, 1000, S, MS);
  Hour = static_cast<unsigned short>(H);
  Min = static_cast<unsigned short>(M);
  Sec = static_cast<unsigned short>(S);
  MSec = static_cast<unsigned short>(MS);
}
Example #3
0
void Fl_Date_Time::decode_date(const double dat, short& year, short& month, short& day) {
   int Y, M, D, I;
   int T = (int) dat + DateDelta;

   T--;
   Y = 1;
   while (T >= D400) {
      T -= D400;
      Y += 400;
   }

   DivMod(T, D100, I, D);
   if (I == 4) {
      I--;
      D += D100;
   }

   Y += I * 100;
   DivMod(D, D4, I, D);
   Y += I * 4;
   DivMod(D, D1, I, D);
   if (I == 4) {
      I--;
      D += D1;
   }
   Y += I;
   year = Y;
   //year  = short (Y + 1900);

   int leapYear = is_leap_year(short(year));
   for (M = 0;;M++) {
      I = _monthDays[leapYear][M];
      if (D < I)
         break;
      D -= I;
   }

   month = short (M + 1);
   day   = short (D + 1);
}
Example #4
0
// Lчтыхў№ Day.Month.Year шч яюыэющ фрЄv/тЁхьхэш Date
void date_decode(date_time Date, int *Year, int *Month, int *Day) {
  int
    D1 = 365,
    D4 = D1 * 4 + 1,
    D100 = D4 * 25 - 1,
    D400 = D100 * 4 + 1,
    Y, M, D, I, T,
    *DayTable;

  T=(int)Date;
  if(T<=0){ *Year=0; *Month=0; *Day=0; }
  else
  {
    for(T--,Y=1; T>=D400; T-=D400,Y+=400);              // ъєёъш яю 400 ыхЄ
    DivMod(T,D100,&I,&D);  if(I==4){I--;D+=D100;};  Y+=I*100; // яю 100 ыхЄ
    DivMod(D, D4,&I,&D);   Y+=I*4;                            // яю 4 уюфр
    DivMod(D, D1,&I,&D);   if(I==4){I--;D+=D1;};    Y+=I;     // яю уюфє

    DayTable = dt_month_day[dt_leap_year(Y)];  // фэхщ т ьхё Ўрї
    for(M = 1; 1; D-=I,M++){ I=DayTable[M-1];  if(D<I) break; }

    *Year=Y;   *Month=M;   *Day= D + 1;
  }
}
Example #5
0
//---------------------------------------------------------------------------
static bool DecodeDateFully(const TDateTime & DateTime,
  unsigned short & Year, unsigned short & Month, unsigned short & Day,
  unsigned short & DOW)
{
  static const int D1 = 365;
  static const int D4 = D1 * 4 + 1;
  static const int D100 = D4 * 25 - 1;
  static const int D400 = D100 * 4 + 1;
  bool Result = false;
  uintptr_t T = DateTimeToTimeStamp(DateTime).Date;
  if (static_cast<int>(T) <= 0)
  {
    Year = 0;
    Month = 0;
    Day = 0;
    DOW = 0;
    return false;
  }
  else
  {
    DOW = T % 7 + 1;
    T--;
    uintptr_t Y = 1;
    while (T >= D400)
    {
      T -= D400;
      Y += 400;
    }
    uintptr_t D = 0;
    uintptr_t I = 0;
    DivMod(T, D100, I, D);
    if (I == 4)
    {
      I--;
      D += D100;
    }
    Y += I * 100;
    DivMod(D, D4, I, D);
    Y += I * 4;
    DivMod(D, D1, I, D);
    if (I == 4)
    {
      I--;
      D += static_cast<Word>(D1);
    }
    Y += I;
    Result = IsLeapYear(static_cast<Word>(Y));
    const TDayTable * DayTable = &MonthDays[Result];
    uintptr_t M = 1;
    while (true)
    {
      I = (*DayTable)[M - 1];
      if (D < I)
      {
        break;
      }
      D -= I;
      M++;
    }
    Year = static_cast<unsigned short>(Y);
    Month = static_cast<unsigned short>(M);
    Day = static_cast<unsigned short>(D + 1);
  }
  return Result;
}