Beispiel #1
0
/*****************************************************************************
 * Function - DoomsdayMonth
 * DESCRIPTION:
 *
 ****************************************************************************/
int MpcTime::DoomsdayMonth(int year, int month)
{
	int r = -1;
	switch(month)
	{
    case 1: //JAN
      if( LeapYear(year) )
        r = 32;
      else
        r = 31;
      break;
    case 2: //FEB
      if( LeapYear(year) )
        r = 29;
      else
        r = 28;
		break;
      case 3: //MAR
      r = 7;
      break;
    case 4: //APR
      r = 4;
      break;
    case 5: //MAY
      r = 9;
      break;
    case 6: //JUN
      r = 6;
      break;
    case 7: //JUL
      r = 11;
      break;
    case 8: //AUG
      r = 8;
      break;
    case 9: //SEP
      r = 5;
      break;
    case 10: //OCT
      r = 10;
      break;
    case 11: //NOV
      r = 7;
      break;
    case 12: //DEC
      r = 12;
      break;
	}
	return r;
}
Beispiel #2
0
int main() {
  int a, b, c, d, e, f, n;
  int v = scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
  if (v != 7) {
    printf("input:BirthYear BirthMonth BirthDay ThisYear ThisMonth ThisDay n\n");
    exit(1);
  }
  if (a < 1900 || 2000 < a || n != 200) {
    printf("Invalid Input!\n");
    exit(1);
  }
  int totalDay = 0;
  int today = 0;
  for (int year = a; year <= a + n + 1; year++) {
    for (int month = 0; month < 12; month++) {
      int Day = MonthDay[month];
      if (LeapYear(year) && month == 1) { Day = 29; }
      for (int day = 0; day < Day; day++) {
        if (!Before(year, month + 1, day + 1, a, b, c)) {
          if (Before(year, month + 1, day + 1, a + n + 1, b, c))  { totalDay++; }
          if (Before(year, month + 1, day + 1, d, e, f)) { today++; }
        }
      }
    }
  }
  if (totalDay <= today) {
    printf("You are Dead!\n");
    exit(1);
  }
  int sec = (long long)60 * 60 * 24 * today / totalDay;
  printf("%02d:%02d:%02d\n", sec / 3600, sec / 60 % 60, sec % 60);
}
Beispiel #3
0
int LastdayInMonth(int month, int year)
{
  switch ( month )
  {
    case 1   :
    case 3   :
    case 5   :
    case 7   :
    case 8   :
    case 10  :
    case 12  :
               return 31;
    case 4   :
    case 6   :
    case 9   :
    case 11  :
               return 30;
    case  2  :
               if( LeapYear(year) )
               {
                 return 29;
               }
               else
               {
                 return 28;
               }
   default   : return 0;
  }
}
Beispiel #4
0
/* Compute the number of days from the Solar date BYEAR.1.1 */
long Solar2Day1(SSLunarSimpleDate *d)
{
    long offset, delta;
    int i;
    
    delta = d->year - BYEAR;
    if (delta<0) Error("Internal error: pick a larger constant for BYEAR.");
    offset = delta * 365 + delta / 4 - delta / 100 + delta / 400;
    for (i=1; i< d->month; i++)
    	offset += daysInSolarMonth[i];
    if ((d->month > 2) && LeapYear(d->year))
        offset++;
    offset += d->day - 1;
    
    if ((d->month == 2) && LeapYear(d->year))
    {
        if (d->day > 29) Error("Day out of range.");
    }
    else if (d->day > daysInSolarMonth[d->month]) Error("Day out of range.");
    return offset;
}
datetime_t TimePackToRel(const datepack_t *tp, bool_t Local)
{
    static uint8_t Month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    datetime_t t;
    int a;

    if (tp->Year<1933 || tp->Year>=2069 ||
        tp->Month<1 || tp->Month>12 ||
        tp->Day<1 || tp->Day>31 ||
        tp->Hour<0 || tp->Hour>=24 ||
        tp->Minute<0 || tp->Minute>=60 ||
        tp->Second<0 || tp->Second>=60)
        return INVALID_DATETIME_T;

    t = -2145916800;
    
    t += (tp->Day-1)*24*60*60;
    t += tp->Hour*60*60;
    t += tp->Minute*60;
    t += tp->Second;

    for (a=1933;a<tp->Year;++a)
        t += 24*60*60*(LeapYear(a) ? 366:365);

	for (a=1;a<tp->Month;++a)
    {
        t += Month[a-1]*24*60*60;
        if (a==2 && LeapYear(tp->Year))
            t += 24*60*60;
    }

    if (Local)
    {
    	int Timezone = configGetTimezone();
	    int DaylightSaving = configIsDaylightSavingEnabled();
	    t -= (Timezone + DaylightSaving * 60)*60;
    }

	return t;
}
Beispiel #6
0
void Day2Solar(LibLunarContext *ctx,
               long offset)
{
    int	i, m, days;
    SSLunarSimpleDate *d = &ctx->_solar;
    
    /* offset is the number of days from SolarFirstDate */
    offset -= Solar2Day(&LunarFirstDate);  /* the argument is negative */
    /* offset is now the number of days from SolarFirstDate.year.1.1 */
    
    for (i=SolarFirstDate.year;
         (i<SolarFirstDate.year+Nyear) && (offset > 0);	 i++)
        offset -= 365 + LeapYear(i);
    if (offset<0)
    {
        --i; 	/* LeapYear is a macro */
        offset += 365 + LeapYear(i);
    }
    if (i==(SolarFirstDate.year + Nyear)) Error("Year out of range.");
    d->year = i;
    
    /* assert(offset<(365+LeapYear(i))); */
    for (m=1; m<=12; m++)
    {
        days = daysInSolarMonth[m];
        if ((m==2) && LeapYear(i))	/* leap February */
            days++;
        if (offset<days)
        {
            d->month = m;
            d->day = offset + 1;
            return;
        }
        offset -= days;
    }
}
Beispiel #7
0
static WORD
MonthCalMonthLength(IN WORD Month,
                    IN WORD Year)
{
    const BYTE MonthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};

    if(Month == 2)
        return MonthDays[Month - 1] + LeapYear(Year);
    else
    {
#ifdef WITH_1752
        if ((Year == 1752) && (Month == 9))
	   return 19; // Special case: September 1752 has no 3rd-13th
	else
#endif
     	   return MonthDays[Month - 1];
    }
}
Beispiel #8
0
//Проверка правильности и коректности ввода данных
bool check(int Year,int Month, int Day)
{
if (( Month==1 || Month==3 || Month==5 || Month==7 || Month==8 || Month==10 || Month==12) && (Day > 31)) 
            return 0;           
            
if ((Month==4 || Month==6 || Month==9 || Month==11) && (Day > 30)) 
            return 0;           
            
if (Month==2 & (!LeapYear(Year)) & (Day>29)) 
            return 0;       
            
if (Month<1 || Month>12) 
            return 0;
            
if(Year<2014||Year>2222) 
            return 0;
            
else
return 1;
}
Beispiel #9
0
/*****************************************************************************
 * Function - CalcTimeDateSince1Jan1970
 * DESCRIPTION:
 *
 ****************************************************************************/
void MpcTime::CalcSecondsSince1Jan1970()
{
  U32 time = 0; //0 is used as illegal time
  int i;

  if( IsValid() )
  {
    /* Handle years */
    time = 946684800;// 60*60*24*366*7 + 60*60*24*365*23
    for( i=2000; i<mYear; i++ )
    {
      if(LeapYear(i))
        time+=31622400; //60*60*24*366
      else
        time+=31536000; //60*60*24*365
    }

    /* Handle months */
    for( i=1; i<mMonth; i++ )
    {
      time+=LastDayInMonth(i, mYear)*86400; //60*60*24*DAYS
    }

    /* Handle Days */
    time+=(mDay-1)*86400; //60*60*24*DAYS

    /* Handle hours */
    time += mHours*3600;          //60*60*HOUR

    /* Handle minutes */
    time += mMinutes*60;          //60*MINUTES

    /* Handle seconds */
    time += mSecunds;             //SECONDS
  }
  mSecSince1970 = time;
}
bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local)
{
	static const uint16_t Days[12] = 
    {
		0,
		31,
		31+28,
		31+28+31,
		31+28+31+30,
		31+28+31+30+31,
		31+28+31+30+31+30,
		31+28+31+30+31+30+31,
		31+28+31+30+31+30+31+31,
		31+28+31+30+31+30+31+31+30,
		31+28+31+30+31+30+31+31+30+31,
		31+28+31+30+31+30+31+31+30+31+30,
	};

	unsigned int a;
	unsigned int b;
	unsigned int c;

	if (!tp || t == INVALID_DATETIME_T) return 0;

    if (t<-2145916800)
        return 0;

    if (Local)
    {
    	int Timezone = configGetTimezone();
	    int DaylightSaving = configIsDaylightSavingEnabled();
	    t += (Timezone + DaylightSaving * 60)*60;
    }

    a = t+2145916800; //2001 -> 1933

    b = a % (24*60*60);
	a = a / (24*60*60);

	tp->Second	= b %60; 
    b /= 60;
	tp->Minute	= b %60;
	tp->Hour	= b /60;

	tp->WeekDay = 1 + a % 7;

	for (b=1933;;++b)
    {
		c = LeapYear(b) ? 366:365;
		if (a >= c)
			a -= c;
		else
			break;
	}
	
	tp->Year = b;
	tp->Day = 1;

	if (LeapYear(b) && a>58) 
    {
		if (a==59)
		    tp->Day = 2;
		--a;
	}
	
    for (b = 11; b && (Days[b] > a); --b) {}

	tp->Month = b+1;
	tp->Day += a - Days[b];
	
    return 1;
}
Beispiel #11
0
/*****************************************************************************
 * Function - SetTimeDateSince1Jan1970
 * DESCRIPTION:
 *
 ****************************************************************************/
void MpcTime::SetSecondsSince1Jan1970(U32 secondsSince1Jan1970)
{
  U32 sum = secondsSince1Jan1970;
  bool found;

  if(sum>946684800)// 60*60*24*366*7 + 60*60*24*365*23
  {
    /* Find year */
    sum-=946684800;
    mYear = 2000;
    found = false;
    while(found==false)
    {
      int y_s;
      if(LeapYear(mYear))
        y_s = 31622400;
      else
        y_s = 31536000;

      if(sum>y_s)
      {
        sum-=y_s;
        mYear++;
      }
      else
      {
        found=true;
      }
    }

    /* Find month */
    found = false;
    mMonth = 1;
    while(found==false)
    {
      int m_s;
      m_s = LastDayInMonth(mMonth, mYear)*86400; //60*60*24*DAYS
      if(sum>m_s)
      {
        sum-=m_s;
        mMonth++;
      }
      else
      {
        found=true;
      }
    }
    /* Find day */
    mDay = 1 + (sum / 86400);       //60*60*24  [sec/day]
    sum -= (mDay-1)*86400;

    /* Find hour */
    mHours = (sum / 3600);          //60*60  [sec/hour]
    sum -= (mHours)*3600;

    /* Find minute */
    mMinutes = (sum / 60);          //60  [sec/minute]
    sum -= (mMinutes)*60;

    /* Find second */
    mSecunds = sum;

    CalcWeekday();
  }
}