示例#1
0
int getDate( int month, int day, int week )
{
    if ( month == 6 && day == 2 && week == 5 )
    {
        //      ShowMessage("now");
    }
    // day 6 week 1 means "first Saturday of the month"
    // and day 2 week 1 means "first Tuesday of the month".
    // week 2 day 2 would mean "2nd Tuesday of the month".
    // day 6+1 is Sunday after Saturday
    // return the date of the month/day/week
    TDateTime startMonth( curYear, month, 1 );
    int dw = getDayOfWeek( startMonth ) - 1;    // make it 0 based

    // So now we need to go through
    int wcount = 1;   // start in first week
    for ( int i = 0; i < monthLength[ month - 1 ]; i++ )
    {
        if ( ( dw + i ) % 7 == day - 1 )
        {
            // we are on the correct day
            if ( wcount == week )
            {
                return i + 1;
            }
            wcount++;
        }
    }

    return 0;
}
TEST(FakeTimeService, Set)
{
  FakeTimeService_SetMinute(42);
  FakeTimeService_SetDay(SATURDAY);
  LONGS_EQUAL(42, getMinuteOfDay());
  LONGS_EQUAL(SATURDAY, getDayOfWeek());
}
示例#3
0
int main (int argc, char *argv[]) {

    int leapYear;
    int doomsday;
    int month;
    int daysInMonth;
    int day;
    int dayOfWeek;

    //get leap and non-leap years
    for (leapYear = 0; leapYear < 2; leapYear++) {
        // get doomsdays for each day of the week
        for (doomsday = 0; doomsday < 7; doomsday++) { 
            // for every month
            for (month = 1; month <= 12; month++) {
                daysInMonth = getDaysInMonth (leapYear, month);
                // for each day of the month print an assert
                for (day = 1; day <= daysInMonth; day++) {
                    dayOfWeek = getDayOfWeek (leapYear, doomsday,
                                             month, day, dayOfWeek);
                    printAssert(leapYear, doomsday,
                                month, day, dayOfWeek);
                }
            }
        }
    }

    return EXIT_SUCCESS;
}
示例#4
0
//==============================================================================
void ICACHE_FLASH_ATTR printTime(void)
{
	int x = 12, y = 48;
	printDigitT_16x24(x, y, GREEN, 0x1f, date_time.TIME.hour/10); x += 16;
	printDigitT_16x24(x, y , GREEN, 0x1f,  date_time.TIME.hour%10);x += 16;
	printDigitT_16x24(x, y , GREEN, 0x1f,  10);x += 16;
	printDigitT_16x24(x, y , GREEN, 0x1f,  date_time.TIME.min/10);x += 16;
	printDigitT_16x24(x, y , GREEN, 0x1f,  date_time.TIME.min%10);x += 32;
//	printDigitT_16x24(x, y , YELLOW, BLUE,  10);x += 16;
//	printDigitT_16x24(x, y , YELLOW, BLUE,  date_time.TIME.sec/10);x += 17;
//	printDigitT_16x24(x, y , YELLOW, BLUE,  date_time.TIME.sec%10);x += 16;

	printDigitT_16x24(x, y , 0x7f7fff, 0x1f,  date_time.DATE.day/10);x += 16;
	printDigitT_16x24(x, y , 0x7f7fff, 0x1f,  date_time.DATE.day%10);x += 16;
	printDigitT_16x24(x, y , 0x7f7fff, 0x1f,  19);x += 16;
	printDigitT_16x24(x, y , 0x7f7fff, 0x1f,  (date_time.DATE.month+1)/10);x += 16;
	printDigitT_16x24(x, y , 0x7f7fff, 0x1f,  (date_time.DATE.month+1)%10);x += 20;


	switch(getDayOfWeek())
	{
		case 0: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  16);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  18);x += 16; break;
		case 1: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  17);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  16);x += 16; break;
		case 2: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  15);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  12);x += 16; break;
		case 3: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  17);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  11);x += 16; break;
		case 4: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  16);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  13);x += 16; break;
		case 5: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  14);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  11);x += 16; break;
		case 6: printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  15);x += 16; printDigitT_16x24(x, y , 0x7f7f00, 0x1f,  11);x += 16; break;
	}
}
void printDate(const Date& date){
	//output the date in a readable format
	std::cout << std::string(20, '*') << std::endl;
	std::cout << "\nmonth : " << date.month << std::endl;
	std::cout << "day : " << date.day << std::endl;
	std::cout << "year : " << date.year << std::endl;
	std::cout << "day of week : " << getDayOfWeek(dow(date)) << std::endl;
	std::cout << std::string(20, '*') << std::endl;
}
示例#6
0
void getCalenday(int y, int m, int calenday[][5]) {
	int day;
	int days = days_of_month(m,y);
	for (day = 1;day <= days;day++) {
		int i = getDayOfWeek(y,m,day);
		int j = day / 7;
		printf("i = %d,j = %d, day = %d\n", i,j,day);
		calenday[i][j] = day;
	}
}
示例#7
0
void sendDoctorsInDate(){
	printf("start doctorsInDay\n");
		int dayOfWeek = getDayOfWeek(informationMessage.day,informationMessage.month,informationMessage.year);
		int isTaken = 0;
		char buffer[100];
		char result[1000];
		strcpy(result,"");
		int i,k,j;
			for(j=0;j<3;j++){
				
				strcat(result,"\nGodzina: ");
				char intStr[15];
				sprintf(intStr,"%d", visitTerms[j]);
				strcat(result,intStr);
				strcat(result,":00\n");		
				for(i=0;i<doctorCount;i++){
						strftime(buffer,100,"%w",&doctor[i].visitDay);
						int doctorVisitDay = atoi(buffer);
						if(doctorVisitDay != dayOfWeek){
							continue;
						}

						
		
		
						for(k=0;k<20;k++){	
							isTaken = 0;
							if(doctor[i].visits[k].tm_hour == visitTerms[j]){
								isTaken =1;
								break;
							}
						}
						if(isTaken == 0)	
												
								strcat(result,doctor[i].lastName);
								if(doctor[i].vacationDate.tm_mday == informationMessage.day &&
								doctor[i].vacationDate.tm_mon == (informationMessage.month-1) &&
								doctor[i].vacationDate.tm_year == (informationMessage.year-1900)){
									strcat(result, "lekarz ma urlop tego dnia!\n");
									
								}
					}
		}
		if(strlen(result) == 0){
			strcpy(informationMessage.information, "Nikt nie przyjmuje tego dnia!\n");
		}
		else{
			strcpy(informationMessage.information, result);
		}
		informationMessage.mtype = informationMessage.type;
		msgsnd(msgid,&informationMessage,sizeof(informationMessage),0);
			printf("ends doctorsInDay\n");

}
示例#8
0
文件: Utils.cpp 项目: Hoglet/TimeIT
time_t getEndOfWeek(const time_t& rawtime)
{
	struct tm * timeInfo;
	int dayOfWeek = getDayOfWeek(rawtime);
	time_t eow = rawtime + (6 - dayOfWeek) * SECOND_PER_DAY;
	timeInfo = localtime(&eow);
	timeInfo->tm_sec = 59;
	timeInfo->tm_min = 59;
	timeInfo->tm_hour = 23;
	timeInfo->tm_isdst = -1;
	return mktime(timeInfo);
}
示例#9
0
文件: Utils.cpp 项目: Hoglet/TimeIT
time_t getBeginingOfWeek(const time_t& rawtime)
{
	struct tm * timeInfo;
	int dayOfWeek = getDayOfWeek(rawtime);
	time_t bow = rawtime - (dayOfWeek) * SECOND_PER_DAY;
	timeInfo = localtime(&bow);
	timeInfo->tm_sec = 0;
	timeInfo->tm_min = 0;
	timeInfo->tm_hour = 0;
	timeInfo->tm_wday = 1;
	timeInfo->tm_isdst = -1;
	return mktime(timeInfo);
}
示例#10
0
char* getDate() {
	char* date = malloc(sizeof(char) * 512);
	
	time_t curTime = time(NULL);
	struct tm t;

	localtime_r(&curTime, &t);

	sprintf(date,/* ctime(&curTime));*/ "%s %02d %s %d %02d:%02d:%02d %s", getDayOfWeek(t.tm_wday), t.tm_mday,
		 getMonth(t.tm_mon), t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, "GMT");
	return date;
/*	char* testdate = malloc(sizeof(char) * 512);
	sprintf(testdate, "Mon 21 Jan 2008 18:06:16 GMT");
	return testdate ;*/
}
示例#11
0
//==============================================================================
uint16 ICACHE_FLASH_ATTR getSetTemperature()
{
	 
  unsigned int aTime = date_time.TIME.hour * 60 + date_time.TIME.min;

  int aDayNumber = getDayOfWeek();

  unsigned char aDay;
  u_CONFIG *aPtr;
  unsigned long col;
  
  if      (aDayNumber == 0)  aDay = configs.nastr.day[5];
  else if (aDayNumber == 1)  aDay = configs.nastr.day[6]; 
  else                       aDay = configs.nastr.day[aDayNumber - 2]; 
  
  u_CONFIG_u cPtr;// = (aDay == 'H') ? configs.cfg[1] : configs.cfg[0];

  if(aDay == 'H'){ cPtr = configs.cfg[1]; print_icon(8, 8, 0xff7f7f, 0x5f, 4);}
  else           { cPtr = configs.cfg[0]; print_icon(8, 8, 0x7f00, 0x5f, 5);}

  cPtr = (aDay == 'H') ? configs.cfg[1] : configs.cfg[0];
      
  uint32 curPeriod = 0;

  for(curPeriod = 0; curPeriod < (cPtr.periodsCnt - 1); curPeriod++)
  {
	//uint32 a = cPtr.pConfig[curPeriod + 1].hmStart;
	unsigned int end = cPtr.pConfig[curPeriod + 1].hStart * 60 + cPtr.pConfig[curPeriod + 1].mStart;;
//			(((a>>24) - '0') * 10 +   (((a>>16) & 0x00000ff) - '0')) * 60 +
//                       ((((a>>8) & 0x00000ff) - '0') * 10 +   ((a & 0x00000ff) - '0'));
    if(aTime < end)  break;     
  }

  // set temperature
  char_6x8(36 + 28 , 12 , GREEN, 0x5f, (char)(cPtr.pConfig[curPeriod].temperature / 100) + '0');
  char_6x8(48 + 28 , 12 , GREEN, 0x5f, (char)((cPtr.pConfig[curPeriod].temperature % 100) /10) + '0');
  char_6x8(60 + 28 , 12 , GREEN, 0x5f, ',');
  char_6x8(72 + 28 , 12 , GREEN, 0x5f, (char)(cPtr.pConfig[curPeriod].temperature % 10) + '0');

  // delta
  char_6x8(96 + 28 , 12 , 0x7f00, 0x5f, 0x7e);
  char_6x8(108 + 28 , 12 , 0x7f00, 0x5f, configs.nastr.delta/10 + '0');
  char_6x8(120 + 28 , 12 , 0x7f00, 0x5f, ',');
  char_6x8(132 + 28 , 12 , 0x7f00, 0x5f, configs.nastr.delta%10 + '0');


  return cPtr.pConfig[curPeriod].temperature;
}
示例#12
0
void OsDateTimeBase::getHttpTimeString(UtlString& dateString)
{
    char dateBuffer[200];

    // Need a day of the week function which takes year, month and day
    int dayOfTheWeek;
    getDayOfWeek(dayOfTheWeek);

    // Wed, 06 Mar 2002 05:51:44 GMT
    sprintf(dateBuffer, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", 
            spDayStrings[dayOfTheWeek],
            mDay, spMonthStrings[mMonth], mYear,
            mHour, mMinute, mSecond);

    dateString = dateBuffer;
}
示例#13
0
void
Clock::tick(void)
{
    unsigned long delta_millis = millis() - lastMillis;
    unsigned long secs_elapsed = delta_millis / 1000;
    lastMillis += secs_elapsed * 1000;

    secsToday += secs_elapsed;

    if (secsToday >= SECS_PER_DAY) {
        // Roll the seccond counter
        secsToday = secsToday - SECS_PER_DAY;

        // Increment the day counters
        setDayOfWeek((getDayOfWeek() + 1) % 7);

        // Don't let the day number roll over
        if (dayNumber < 0xFF) {
            setDayNumber(getDayNumber() + 1);
        }
    }
}
示例#14
0
int main(int argc, char *argv[]) {
    int day = 0;
    int month = 0;
    int year = 0;

    if (argc == 2) {
        if (strcmp(argv[1], "-t") == EQUAL) {
            runTests();
        } else {
            displayUsage();
        }
    } else if (argc == 3) {
        if (strcmp(argv[1], "-l") == EQUAL) {
            year = atoi(argv[2]);
            printf("%d is ", year);
            if (!isLeapYear(year))
                printf("not ");
            printf("a leap year.\n");
        } else if (strcmp(argv[1], "-d") == EQUAL) {
            year = atoi(argv[2]);
            printf("The doomsday for %d is %s.\n", year, getDayName(getDoomsday(year)));
        } else {
            displayUsage();
        }
    } else if (argc == 4) {
        day = atoi(argv[1]);
        month = atoi(argv[2]);
        year = atoi(argv[3]);

        printf("%d %d %d\n", day, month, year);
        printf("%s\n", getDayName(getDayOfWeek(day, month, year)));
    } else {
        displayUsage();
    }

    return EXIT_SUCCESS;
}
示例#15
0
DateLUTImpl::DateLUTImpl(const std::string & time_zone_)
    : time_zone(time_zone_)
{
    size_t i = 0;
    time_t start_of_day = DATE_LUT_MIN;

    cctz::time_zone cctz_time_zone;
    if (!cctz::load_time_zone(time_zone.data(), &cctz_time_zone))
        throw Poco::Exception("Cannot load time zone " + time_zone_);

    cctz::time_zone::absolute_lookup start_of_epoch_lookup = cctz_time_zone.lookup(std::chrono::system_clock::from_time_t(start_of_day));
    offset_at_start_of_epoch = start_of_epoch_lookup.offset;
    offset_is_whole_number_of_hours_everytime = true;

    cctz::civil_day date{1970, 1, 1};

    do
    {
        cctz::time_zone::civil_lookup lookup = cctz_time_zone.lookup(date);

        start_of_day = std::chrono::system_clock::to_time_t(lookup.pre);    /// Ambiguouty is possible.

        Values & values = lut[i];
        values.year = date.year();
        values.month = date.month();
        values.day_of_month = date.day();
        values.day_of_week = getDayOfWeek(date);
        values.date = start_of_day;

        if (values.day_of_month == 1)
        {
            cctz::civil_month month(date);
            values.days_in_month = cctz::civil_day(month + 1) - cctz::civil_day(month);
        }
        else
            values.days_in_month = i != 0 ? lut[i - 1].days_in_month : 31;

        values.time_at_offset_change = 0;
        values.amount_of_offset_change = 0;

        if (start_of_day % 3600)
            offset_is_whole_number_of_hours_everytime = false;

        /// If UTC offset was changed in previous day.
        if (i != 0)
        {
            auto amount_of_offset_change_at_prev_day = 86400 - (lut[i].date - lut[i - 1].date);
            if (amount_of_offset_change_at_prev_day)
            {
                lut[i - 1].amount_of_offset_change = amount_of_offset_change_at_prev_day;

                const auto utc_offset_at_beginning_of_day = cctz_time_zone.lookup(std::chrono::system_clock::from_time_t(lut[i - 1].date)).offset;

                /// Find a time (timestamp offset from beginning of day),
                ///  when UTC offset was changed. Search is performed with 15-minute granularity, assuming it is enough.

                time_t time_at_offset_change = 900;
                while (time_at_offset_change < 65536)
                {
                    auto utc_offset_at_current_time = cctz_time_zone.lookup(std::chrono::system_clock::from_time_t(
                        lut[i - 1].date + time_at_offset_change)).offset;

                    if (utc_offset_at_current_time != utc_offset_at_beginning_of_day)
                        break;

                    time_at_offset_change += 900;
                }

                lut[i - 1].time_at_offset_change = time_at_offset_change >= 65536 ? 0 : time_at_offset_change;

/*                std::cerr << lut[i - 1].year << "-" << int(lut[i - 1].month) << "-" << int(lut[i - 1].day_of_month)
                    << " offset was changed at " << lut[i - 1].time_at_offset_change << " for " << lut[i - 1].amount_of_offset_change << " seconds.\n";*/
            }
        }

        /// Going to next day.
        ++date;
        ++i;
    }
    while (start_of_day <= DATE_LUT_MAX && i <= DATE_LUT_MAX_DAY_NUM);

    /// Fill excessive part of lookup table. This is needed only to simplify handling of overflow cases.
    while (i < DATE_LUT_SIZE)
    {
        lut[i] = lut[0];
        ++i;
    }

    /// Fill lookup table for years and months.
    for (size_t day = 0; day < DATE_LUT_SIZE && lut[day].year <= DATE_LUT_MAX_YEAR; ++day)
    {
        const Values & values = lut[day];

        if (values.day_of_month == 1)
        {
            if (values.month == 1)
                years_lut[values.year - DATE_LUT_MIN_YEAR] = day;
            years_months_lut[(values.year - DATE_LUT_MIN_YEAR) * 12 + values.month - 1] = day;
        }
    }
}
示例#16
0
void OsDateTimeBase::getDayOfWeek(int& dayOfWeek)
{
    getDayOfWeek(mYear, mMonth, mDay, dayOfWeek);
}
示例#17
0
文件: TagProc.c 项目: Batilan/rtl-wx
/*-----------------------------------------------------------------------------------------------------------------------------------------------------
   processTimestampField()

  This function causes some part of a WX_Timestamp structure to be written to the parser output buffer as part of a tag
  replacement.  

  Timestamps are used for vaious purposes including to indicate the time and packet count when the last update from a sensor 
  arrived as well as to store the current date and time or the date and time that the Rain Gauge was last reset.

  The WMR9X8 weather station sends full date and time updates every hour on the hour, while the minute count is updated once
   per minute.  Arrival rates of data from sensors vary.

  For Tag processing, the Timestamp part of the tag may have come from the sensorToGetFrom or from the fieldToGet depending
  on the Tag being processed.  This routine expects that any additional formatting options are stored in the formatCommandStr 
  buffer in the parser control structure.
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
void processTimestampField(char *tsParams, ParserControlVars *pVars)
{
  WX_Timestamp *ts = pVars->ts;
  struct tm *localts;
  
  time_t timeNow = time(NULL);
  if (ts->PktCnt == 0)
     localts = localtime(&timeNow); // When timestamp is invalid, init localts to something
  else
     localts = localtime(&ts->timet);

  if (strcmp(tsParams,"TSDATE") == 0) {
    // TSDATE - Need to handle no data case specially
    if (ts->PktCnt == 0) {
      if (pVars->formatForNoData == 'D')
          sprintf(pVars->outputStr,"--/--/----");
      else if (pVars->formatForNoData == 'S')
         strcpy(pVars->outputStr, pVars->NoDataStr);       
      else
          sprintf(pVars->outputStr,"00/00/0000");
    }
    else {
      sprintf(pVars->outputStr,"%02d/%02d/%04d", localts->tm_mon+1, localts->tm_mday, localts->tm_year+1900);  
    }
  }
  else if (strcmp(tsParams, "TSTIME") == 0) {
   if (ts->PktCnt != 0) {
     if (pVars->formatControlStr[0] != '2')
        sprintf(pVars->outputStr,"%02d:%02d %s",
               (localts->tm_hour>12?localts->tm_hour-12:(localts->tm_hour<1?12:localts->tm_hour)),
                    localts->tm_min,((localts->tm_hour >=12)?"PM":"AM"));
     else
        sprintf(pVars->outputStr,"%02d:%02d",localts->tm_hour, localts->tm_min);
   }
   else {
     if (pVars->formatForNoData == 'D')
       sprintf(pVars->outputStr,"--:--   ");
     else if (pVars->formatForNoData == 'S')
           sprintf(pVars->outputStr,"%s",pVars->NoDataStr);
     else if (pVars->formatForNoData == '0')
       sprintf(pVars->outputStr,"00:00   ");
     else
       sprintf(pVars->outputStr,"  :     ");    
   }
  } 
  else if (strcmp(tsParams, "TSPKTCNT") == 0)
      sprintf(pVars->outputStr,"%d",ts->PktCnt);
  else if (strcmp(tsParams, "TSMINUTE") == 0)
      sprintf(pVars->outputStr,"%02d",localts->tm_min);
  else if (strcmp(tsParams, "TSYEAR") == 0)
      sprintf(pVars->outputStr,"%04d",localts->tm_year+1900);
  else if (strcmp(tsParams, "TSMONTH") == 0) 
        sprintf(pVars->outputStr,"%02d",localts->tm_mon+1);
  else if (strcmp(tsParams, "TSMONTHTEXT") == 0) {
      int maxLen = pVars->formatControlStr[0]- '0';
      if ((localts->tm_mon >=0) && (localts->tm_mon < 12))
        sprintf(pVars->outputStr, "%s",textMonth[localts->tm_mon]);
      if ((maxLen > 0) && (maxLen <= 9))
         pVars->outputStr[maxLen]=0;
    }
  else if (strcmp(tsParams, "TSDAY") == 0) 
      sprintf(pVars->outputStr,"%02d",localts->tm_mday);
  else if (strcmp(tsParams, "TSHOUR") == 0)  {
      if (pVars->formatControlStr[0] != '2')
        sprintf(pVars->outputStr,"%02d",
                  (localts->tm_hour>12? localts->tm_hour-12 : (localts->tm_hour<1?12:localts->tm_hour)));
      else
        sprintf(pVars->outputStr,"%02d",localts->tm_hour);
    }
  else if (strcmp(tsParams, "TSDAYOFWEEK") == 0) {
      int maxLen = pVars->formatControlStr[0]-'0';
      sprintf(pVars->outputStr,"%s", getDayOfWeek(localts->tm_mon+1, localts->tm_mday, localts->tm_year+1900));
      if ((maxLen > 0) && (maxLen <= 9))
         pVars->outputStr[maxLen]=0;
    }
  else if (strcmp(tsParams, "TSAMPM") == 0) {
      if (localts->tm_hour < 12)
        strcpy(pVars->outputStr,"AM");
      else
        strcpy(pVars->outputStr,"PM");
  }
}
示例#18
0
TEST(dateTest, Date){
	//validation based on http://www.timeanddate.com/date/weekday.html	
	Date birthday;
	birthday.day = 7;
	birthday.month = 11;
	birthday.year = 1984;
	
	Date dday;
	dday.day = 6;
	dday.month = 6;
	dday.year = 1944;
	
	Date apolloEleven;
	apolloEleven.day = 20;
	apolloEleven.month = 7;
	apolloEleven.year = 1969;
	
	// begin addDay check	
	addDay(birthday);
	CHECK(birthday.day == 8 && birthday.month == 11 && birthday.year == 1984);
	CHECK(getDayOfWeek(dow(birthday)) == "Thursday");
	
	addDay(dday);
	CHECK(dday.day == 7 && dday.month == 6 && dday.year == 1944);
	CHECK(getDayOfWeek(dow(dday)) == "Wednesday");
	
	addDay(apolloEleven);
	CHECK(apolloEleven.day == 21 && apolloEleven.month == 7 && apolloEleven.year == 1969);
	CHECK(getDayOfWeek(dow(apolloEleven)) == "Monday");	
	// end addDay check
	
	// begin addMonth check
	addMonth(birthday);
	CHECK(birthday.day == 8 && birthday.month == 12 && birthday.year == 1984);
	CHECK(getDayOfWeek(dow(birthday)) == "Saturday");
	
	addMonth(dday);
	CHECK(dday.day == 7 && dday.month == 7 && dday.year == 1944);
	CHECK(getDayOfWeek(dow(dday)) == "Friday");
	
	addMonth(apolloEleven);
	CHECK(apolloEleven.day == 20 && apolloEleven.month == 8 && apolloEleven.year == 1969);
	CHECK(getDayOfWeek(dow(apolloEleven)) == "Wednesday");
	// end addMonth check
	
	// begin addYear check
	addYear(birthday);
	CHECK(birthday.day == 8 && birthday.month == 12 && birthday.year == 1985);
	CHECK(getDayOfWeek(dow(birthday)) == "Sunday");
	
	addYear(dday);
	CHECK(dday.day == 7 && dday.month == 7 && dday.year == 1945);
	CHECK(getDayOfWeek(dow(dday)) == "Saturday");
	
	addYear(apolloEleven);
	CHECK(apolloEleven.day == 20 && apolloEleven.month == 8 && apolloEleven.year == 1970);
	CHECK(getDayOfWeek(dow(apolloEleven)) == "Thursday");
	// end addYear check

	// begin getNextMonday check
	Date nmBirthday = getNextMonday(birthday);
	CHECK(nmBirthday.day == 9 && nmBirthday.month == 12 && nmBirthday.year == 1985);
	CHECK(getDayOfWeek(dow(nmBirthday)) == "Monday");
	
	Date nmDDay = getNextMonday(dday);
	CHECK(nmDDay.day == 9 && nmDDay.month == 7 && nmDDay.year == 1945);
	CHECK(getDayOfWeek(dow(nmDDay)) == "Monday");
	
	Date nmApolloEleven = getNextMonday(apolloEleven);
	CHECK(nmApolloEleven.day == 24 && nmApolloEleven.month == 8 && nmApolloEleven.year == 1970);
	CHECK(getDayOfWeek(dow(nmApolloEleven)) == "Monday");
	// end getNextMonday check
}
示例#19
0
int getDayOfWeek(Interval i, int CalendarSystem) {
  return getDayOfWeek(i.months, i.days, i.years, CalendarSystem);
}
示例#20
0
int getDayOfWeek(ULL timestamp, int CalendarSystem) {
  int year, month, day;
  year = month = day = 0;
  date_to_ymd(timestamp_date(timestamp), year, month, day);
  return getDayOfWeek(month, day, year, CalendarSystem);
}
示例#21
0
void test_date_time_implementation() {
  ULL timestamp = 20090618001732ULL;
  int dt;
  int tm;
  int Y,M,D,h,m,s;

  split_timestamp(timestamp, dt, tm);
  date_to_ymd(dt, Y, M, D);
  time_to_hms(tm, h, m, s);

  cout << "Timestamp: " << timestamp << endl;
  cout << "Date: " << dt << " -> " << Y << "/" << M << "/" << D << endl;
  cout << "Time: " << tm << " -> " << h << ":" << m << ":" << s << endl << endl;

  UL seconds = 31834133;
  Interval i = Interval(0,0,0,0,0,seconds);
  cout << "20080101 + 31834133 seconds  = " << join_timestamp(20080101, 0) + i << endl;
  cout << "20080101 - -31834133 seconds = " << join_timestamp(20080101, 0) - -i << endl;
  cout << "20080101 - 31834133 seconds  = " << join_timestamp(20080101, 0) - i << endl;
  cout << "20080101 + -31834133 seconds = " << join_timestamp(20080101, 0) + -i << endl;

  cout << endl;
  
  i = Interval(1, 3, 3, 25, 7, 38);
  cout << "20090601 + (1 year 3 months 3 days 25 hours 7 minutes 38 seconds)  = " << join_timestamp(20090601, 0) + i << endl;
  cout << "20090601 - -(1 year 3 months 3 days 25 hours 7 minutes 38 seconds) = " << join_timestamp(20090601, 0) - (-i) << endl;
  cout << "20090601 - (1 year 3 months 3 days 25 hours 7 minutes 38 seconds)  = " << join_timestamp(20090601, 0) - i << endl;
  cout << "20090601 + -(1 year 3 months 3 days 25 hours 7 minutes 38 seconds) = " << join_timestamp(20090601, 0) + (-i) << endl;

  cout << endl;
  
  Interval l = Interval(2, 3, 32, 25, 7, 112);
  Interval r = Interval(1, 15, 33, 1, 8, 52);
  cout << "(2 years 3 months 32 days 25 hours 7 minutes 112 seconds) <=> (1 year 15 months 33 days 1 hour 8 minutes 52 seconds) = " << leg(l,r) << endl;

  cout << endl;
  
  l = Interval(0,0,0,0,0,31834133);
  r = Interval(0, 0, 368, 10, 48, 52);
  cout << "(31834133 seconds) <=> (368 days 10 hours 48 minutes 52 seconds) = " << leg(l,r) << endl;
  cout << "(31834133 seconds) > (368 days 10 hours 48 minutes 52 seconds) = " << ((l > r) ? "true" : "false") << endl;
  r = Interval(0, 0, 368, 10, 48, 53);
  cout << "(31834133 seconds) <=> (368 days 10 hours 48 minutes 53 seconds) = " << leg(l,r) << endl;
  cout << "(31834133 seconds) == (368 days 10 hours 48 minutes 53 seconds) = " << ((l == r) ? "true" : "false") << endl;
  r = Interval(0, 0, 368, 10, 48, 54);
  cout << "(31834133 seconds) <=> (368 days 10 hours 48 minutes 54 seconds) = " << leg(l,r) << endl;
  cout << "(31834133 seconds) < (368 days 10 hours 48 minutes 54 seconds) = " << ((l < r) ? "true" : "false") << endl;
  
  cout << endl;
  
  ULL t1 = 19831129031500ULL;       // my birth date (time?)
  ULL t2 = 20090626005206ULL;       // now
  i = Interval::between(t1, t2);
  l = Interval(25, 6, 27, 21, 37, 6);
  r = Interval(0, 0, 9340, 21, 37, 6);
  cout << "Interval between 1983-11-29 03:15:00 and 2009-06-26 00:52:06 = " << i.to_s() << endl;
  cout << i.to_s() << " <=> " << l.to_s() << " = " << leg(i, l) << endl;
  cout << i.to_s() << " <=> " << r.to_s() << " = " << leg(i, r) << endl;
  cout << l.to_s() << " <=> " << r.to_s() << " = " << leg(l, r) << endl;
  
  cout << endl;
  
  l = Interval(0, 1, -29, 4, -29, 0);
  r = Interval(0, 0, 2, 3, 31, 0);
  cout << l.to_s() << " <=> " << r.to_s() << " = " << leg(l, r) << endl;
  cout << l.to_s() << " < " << r.to_s() << "  -> " << ((l < r) ? "true" : "false") << endl;
  cout << l.to_s() << " == " << r.to_s() << " -> " << ((l == r) ? "true" : "false") << endl;
  cout << l.to_s() << " > " << r.to_s() << "  -> " << ((l > r) ? "true" : "false") << endl;
  
  cout << endl;
  
  i = Interval(390, -1354, -3395, -6671, -5719, 0);       // ~9.7556 days
  long divisor = 10000;
  cout << i.to_s() << " / " << divisor << " = " << (i / divisor).to_s() << endl;
  
  cout << endl;
  
  cout << "Day of week of 20090623 is a " << getDayOfWeek(6, 23, 2009, 1);
}
示例#22
0
文件: FTPParse.cpp 项目: DJMatty/xbmc
void CFTPParse::setTime(string str)
{
  /* Variables used to capture patterns via the regexes */
  string month;
  string day;
  string year;
  string hour;
  string minute;
  string second;
  string am_or_pm;

  /* time struct used to set the time_t variable */
  struct tm time_struct = {};

  /* Regex to read Unix, NetWare and NetPresenz time format */
  pcrecpp::RE unix_re("^([A-Za-z]{3})" // month
    "\\s+(\\d{1,2})" // day of month
    "\\s+([:\\d]{4,5})$" // time of day or year
  );

  /* Regex to read MultiNet time format */
  pcrecpp::RE multinet_re("^(\\d{1,2})" // day of month
    "-([A-Za-z]{3})" // month
    "-(\\d{4})" // year
    "\\s+(\\d{2})" // hour
    ":(\\d{2})" // minute
    "(:(\\d{2}))?$" // second
  );

  /* Regex to read MSDOS time format */
  pcrecpp::RE msdos_re("^(\\d{2})" // month
    "-(\\d{2})" // day of month
    "-(\\d{2})" // year
    "\\s+(\\d{2})" // hour
    ":(\\d{2})" // minute
    "([AP]M)$" // AM or PM
  );

  if (unix_re.FullMatch(str, &month, &day, &year))
  {
    /* set the month */
    if (pcrecpp::RE("jan",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 0;
    else if (pcrecpp::RE("feb",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 1;
    else if (pcrecpp::RE("mar",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 2;
    else if (pcrecpp::RE("apr",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 3;
    else if (pcrecpp::RE("may",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 4;
    else if (pcrecpp::RE("jun",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 5;
    else if (pcrecpp::RE("jul",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 6;
    else if (pcrecpp::RE("aug",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 7;
    else if (pcrecpp::RE("sep",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 8;
    else if (pcrecpp::RE("oct",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 9;
    else if (pcrecpp::RE("nov",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 10;
    else if (pcrecpp::RE("dec",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 11;

    /* set the day of the month */
    time_struct.tm_mday = atoi(day.c_str());

    time_t t = time(NULL);
    struct tm *current_time = localtime(&t);
    if (pcrecpp::RE("(\\d{2}):(\\d{2})").FullMatch(year, &hour, &minute))
    {
      /* set the hour and minute */
      time_struct.tm_hour = atoi(hour.c_str());
      time_struct.tm_min = atoi(minute.c_str());

      /* set the year */
      if ((current_time->tm_mon - time_struct.tm_mon < 0) ||
         ((current_time->tm_mon - time_struct.tm_mon == 0) &&
          (current_time->tm_mday - time_struct.tm_mday < 0)))
        time_struct.tm_year = current_time->tm_year - 1;
      else
        time_struct.tm_year = current_time->tm_year;
    }
    else
    {
      /* set the year */
      time_struct.tm_year = atoi(year.c_str()) - 1900;
    }

    /* set the day of the week */
    time_struct.tm_wday = getDayOfWeek(time_struct.tm_mon + 1,
                                   time_struct.tm_mday,
                                   time_struct.tm_year + 1900);
  }
  else if (multinet_re.FullMatch(str, &day, &month, &year,
                            &hour, &minute, (void*)NULL, &second))
  {
    /* set the month */
    if (pcrecpp::RE("jan",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 0;
    else if (pcrecpp::RE("feb",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 1;
    else if (pcrecpp::RE("mar",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 2;
    else if (pcrecpp::RE("apr",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 3;
    else if (pcrecpp::RE("may",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 4;
    else if (pcrecpp::RE("jun",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 5;
    else if (pcrecpp::RE("jul",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 6;
    else if (pcrecpp::RE("aug",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 7;
    else if (pcrecpp::RE("sep",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 8;
    else if (pcrecpp::RE("oct",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 9;
    else if (pcrecpp::RE("nov",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 10;
    else if (pcrecpp::RE("dec",
        pcrecpp::RE_Options().set_caseless(true)).FullMatch(month))
      time_struct.tm_mon = 11;

    /* set the day of the month and year */
    time_struct.tm_mday = atoi(day.c_str());
    time_struct.tm_year = atoi(year.c_str()) - 1900;

    /* set the hour and minute */
    time_struct.tm_hour = atoi(hour.c_str());
    time_struct.tm_min = atoi(minute.c_str());

    /* set the second if given*/
    if (second.length() > 0)
      time_struct.tm_sec = atoi(second.c_str());

    /* set the day of the week */
    time_struct.tm_wday = getDayOfWeek(time_struct.tm_mon + 1,
                                   time_struct.tm_mday,
                                   time_struct.tm_year + 1900);
  }
  else if (msdos_re.FullMatch(str, &month, &day,
                              &year, &hour, &minute, &am_or_pm))
  {
    /* set the month and the day of the month */
    time_struct.tm_mon = atoi(month.c_str()) - 1;
    time_struct.tm_mday = atoi(day.c_str());

    /* set the year */
    time_struct.tm_year = atoi(year.c_str());
    if (time_struct.tm_year < 70)
      time_struct.tm_year += 100;

    /* set the hour */
    time_struct.tm_hour = atoi(hour.c_str());
    if (time_struct.tm_hour == 12)
      time_struct.tm_hour -= 12;
    if (pcrecpp::RE("PM").FullMatch(am_or_pm))
      time_struct.tm_hour += 12;

    /* set the minute */
    time_struct.tm_min = atoi(minute.c_str());

    /* set the day of the week */
    time_struct.tm_wday = getDayOfWeek(time_struct.tm_mon + 1,
                                   time_struct.tm_mday,
                                   time_struct.tm_year + 1900);
  }

  /* now set m_time */
  m_time = mktime(&time_struct);
}