コード例 #1
0
ファイル: avr.c プロジェクト: ellenmliu/CS145
void incrementTime(void)
{
	Seconds++;
	if(Seconds >= 60)
	{
		Seconds = 0;
		Minutes++;
		if(Minutes >= 60)
		{
			Minutes = 0;
			Hour++;
			if(Hour >= 24)
			{
				Hour = 0;
				Day++;
				if(!isValidDate(Day,Month,Year))
				{
					Day = 1;
					Month++;
					if(!isValidDate(Day,Month,Year))
					{
						Month = 1;
						Year++;
					}	
				}
			}
		}
	}
}
コード例 #2
0
int isOlder(char *dob1, char *dob2) {
    Date date1, date2;
    if (isValidDateFormat(dob1) && isValidDateFormat(dob2)) {
        date1 = getDateFromString(dob1);
        date2 = getDateFromString(dob2);
        if (isValidDate(date1) && isValidDate(date2)) {
            return structCompare(date1, date2);
        }
        else return -1;
    }
    else return -1;
}
コード例 #3
0
ファイル: CDate.cpp プロジェクト: Tdarra/CPSC221_TA
bool CDate::isValidDate(int year, string month, int day){
	// TODO you need to fill in the code here        ********
	// comment out "return false" below
	// HINT use monthStr2Num to get the month_num 
	// and then reuse another function
	return isValidDate(year, monthStr2Num(month), day);
}
コード例 #4
0
ファイル: timeutil.cpp プロジェクト: sanjayui/tinymux
bool LinearTimeToFieldedTime(INT64 lt, FIELDEDTIME *ft)
{
    INT64 ns100;
    int iYear, iMonth, iDayOfYear, iDayOfMonth, iDayOfWeek;

    memset(ft, 0, sizeof(FIELDEDTIME));
    int d0 = static_cast<int>(i64FloorDivisionMod(lt, FACTOR_100NS_PER_DAY, &ns100));
    GregorianFromFixed_Adjusted(d0, iYear, iMonth, iDayOfYear, iDayOfMonth, iDayOfWeek);
    if (!isValidDate(iYear, iMonth, iDayOfMonth))
    {
        return false;
    }

    ft->iYear       = static_cast<short>(iYear);
    ft->iMonth      = static_cast<unsigned short>(iMonth);
    ft->iDayOfYear  = static_cast<unsigned short>(iDayOfYear);
    ft->iDayOfMonth = static_cast<unsigned short>(iDayOfMonth);
    ft->iDayOfWeek  = static_cast<unsigned short>(iDayOfWeek);

    ft->iHour = static_cast<unsigned short>(ns100 / FACTOR_100NS_PER_HOUR);
    ns100 = ns100 % FACTOR_100NS_PER_HOUR;
    ft->iMinute = static_cast<unsigned short>(ns100 / FACTOR_100NS_PER_MINUTE);
    ns100 = ns100 % FACTOR_100NS_PER_MINUTE;
    ft->iSecond = static_cast<unsigned short>(ns100 / FACTOR_100NS_PER_SECOND);
    ns100 = ns100 % FACTOR_100NS_PER_SECOND;

    ft->iMillisecond = static_cast<unsigned short>(ns100 / FACTOR_100NS_PER_MILLISECOND);
    ns100 = ns100 % FACTOR_100NS_PER_MILLISECOND;
    ft->iMicrosecond = static_cast<unsigned short>(ns100 / FACTOR_100NS_PER_MICROSECOND);
    ns100 = ns100 % FACTOR_100NS_PER_MICROSECOND;
    ft->iNanosecond = static_cast<unsigned short>(ns100 * FACTOR_NANOSECONDS_PER_100NS);

    return true;
}
コード例 #5
0
SimpleDate::SimpleDate(int monthin, int dayin, int yearin) {
	month = monthin;
	day = dayin;
	year = yearin;

	if (!isValidDate(month, day, year)) {
		throw std::invalid_argument("Not a valid date");
	}
}
コード例 #6
0
ファイル: Date.cpp プロジェクト: aerobless/HSR_Prog3
void Date::read(std::istream& in) {
    int in_day { }, in_month { }, in_year { };
    char sep1 { }, sep2 { };
    in >> in_day >> sep1 >> in_month >> sep2 >> in_year;
    if (isValidDate(1,1,1)) //should be  (isValidYear(in_day))
        std::swap(in_day, in_year);
    if (in_year >= 0 && in_year < 100)
        in_year += 2000;
    if (!in.fail() && sep1 == sep2
        && (sep1 == '.' || sep1 == '/' || sep1 == '-')
        && isValidDate(in_year, in_month, in_day)) {
        year = in_year;
        month = in_month;
        day = in_day;
    } else {
        in.setstate(std::ios::failbit | in.rdstate());
    }
}
コード例 #7
0
ファイル: CDate.cpp プロジェクト: Tdarra/CPSC221_TA
void CDate::setDate(int year, int month, int day){
	if(isValidDate(year, month, day)){    
		m_year = year;
		m_month = month;
		m_day = day;
	}
	else {
		m_year = m_month = m_day = 0;
	}
}
コード例 #8
0
ファイル: Time.c プロジェクト: Rodmg/DataLoggerPSoC
void Time_Adj_Y(BOOL direction)
{
	BYTE date, month, year, bcd10, bcd;

	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	bcdToDec(datetime._04h.bits.date10, datetime._04h.bits.date, &date);
	bcdToDec(datetime._05h.bits.month10, datetime._05h.bits.month, &month);
	bcdToDec(datetime._06h.bits.year10, datetime._06h.bits.year, &year);

	bcd10 = datetime._06h.bits.year10;
	bcd = datetime._06h.bits.year;

	if(direction == TIME_UP)
	{
		year++;
		if(isValidDate(date, month, year))
		{
			decToBcd(&bcd10, &bcd, year);
		}
	}
	else
	{
		year--;
		if(isValidDate(date, month, year))
		{
			decToBcd(&bcd10, &bcd, year);
		}
	}

	datetime._06h.bits.year10 = bcd10;
	datetime._06h.bits.year = bcd;

	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}
コード例 #9
0
ファイル: Date.c プロジェクト: Jorl17/projecto-ppp
Date getDateFromUser(const char* msg) {
#define MAX_DATE_SIZE 12 /* dd/mm/aaaa 0 -- the extra space has an explanation below.*/
#define MIN_DATE_CHARACTERS 6/* d/m/aa\0 */
    size_t read;
    char str[MAX_DATE_SIZE];
    char* token;
    Date ret;
    if (msg) {
        printf("%s", msg);
        fflush(stdout);
    }

    read = readString(str, MAX_DATE_SIZE-2);
    /* Add a space at the end because of strtok() eating it up as if it were a token */
    str[read]=' ';
    str[read+1]='\0';

    if (read < MIN_DATE_CHARACTERS)
        goto err;

    token = strtok(str, "/");
    if (!token)
        goto err;
    ret.day = (uint8_t)atoi(token);

    token = strtok(NULL, "/");
    if (!token)
        goto err;
    ret.month = (uint8_t)atoi(token);

    token = strtok(NULL, "/");
    if (!token)
        goto err;
    ret.year = (unsigned int)atoi(token);

    if (ret.year <= 99)
        ret.year += 2000; /* FIXME: assume yy means 20yy or 19yy? */

    if (isValidDate(ret))
        return ret;

err:
    return DATEMIN;
}
コード例 #10
0
ファイル: timeutil.cpp プロジェクト: sanjayui/tinymux
bool FieldedTimeToLinearTime(FIELDEDTIME *ft, INT64 *plt)
{
    if (!isValidDate(ft->iYear, ft->iMonth, ft->iDayOfMonth))
    {
        *plt = 0;
        return false;
    }

    int iFixedDay = FixedFromGregorian_Adjusted(ft->iYear, ft->iMonth, ft->iDayOfMonth);
    ft->iDayOfWeek = static_cast<unsigned short>(iMod(iFixedDay+1, 7));

    INT64 lt;
    lt  = iFixedDay * FACTOR_100NS_PER_DAY;
    lt += ft->iHour * FACTOR_100NS_PER_HOUR;
    lt += ft->iMinute * FACTOR_100NS_PER_MINUTE;
    lt += ft->iSecond * FACTOR_100NS_PER_SECOND;
    lt += ft->iMicrosecond * FACTOR_100NS_PER_MICROSECOND;
    lt += ft->iMillisecond * FACTOR_100NS_PER_MILLISECOND;
    lt += ft->iNanosecond / FACTOR_NANOSECONDS_PER_100NS;

    *plt = lt;
    return true;
}
コード例 #11
0
ファイル: avr.c プロジェクト: ellenmliu/CS145
void setDateTime(void)
{
	// keep track of LCD pos
	int row, col;
	row = 0;
	col = 2;
	// number is the number entered
	int number;
	// counter to keep track of how many digits entered
	int counter = 0;
	// number to keep track of the number so far
	int userInput = 0;
	char buf[1]; 
	do 
	{
		while(col < 10 || row != 1)
		{
			pos_lcd(row, col);
			number = get_key();
			if(isValidKey(number))
			{
				sprintf(buf, "%i", number);
				put_str_lcd(buf);
				wait_avr(400);

				if(col >= 11 && row == 0)
				{
					row++;
					col = 2;
				}
				else if(col <= 11)
				{
					col++;
					if(col == 4 || col == 7)
						col++;
				}
					
				counter++;
				if(counter%2 == 0 && counter != 6)
					userInput += number;
				else if(counter == 5)
					userInput = 1000*number;
				else if(counter == 6)
					userInput += 100*number;
				else if(counter == 7)
					userInput += 10*number;
				else 
					userInput = 10*number;
			
			}
			if(counter == 2)
				Month = userInput;
			else if(counter == 4)
				Day = userInput;
			else if(counter == 8)
				Year = userInput;
			else if(counter == 10)
				Hour = userInput;
			else if(counter == 12)
				Minutes = userInput;
			else if(counter == 14)
				Seconds = userInput;
		}
		if(!isValidDate(Day, Month, Year))
		{
			clr_lcd();
			sprintf(buf, "%s", "invalid date");
			put_str_lcd(buf);
			wait_avr(2000);
			row = 0;
			col = 2;

			// counter to keep track of how many digits entered
			counter = 0;
			// number to keep track of the number so far
			userInput = 0;
			resetLCD();
		}
	}while(!isValidDate(Day, Month, Year));


	while(1)
	{
		wait_avr(1000);
		incrementTime();
		pos_lcd(0, 2);
		sprintf(buf, "%02i/%02i/%02i", Month, Day, Year);
		put_str_lcd(buf);
		pos_lcd(1, 2);
		sprintf(buf, "%02i:%02i:%02i", Hour, Minutes, Seconds);
		put_str_lcd(buf);
	}	
}
コード例 #12
0
ファイル: dates.c プロジェクト: caizongchao/open-mika
w_int millis2date(w_millis millis, w_date date) {

  w_int days = (w_int)(millis / MSECS_PER_DAY);
  w_int day;
  w_int month;
  w_int year;
  w_int i;
  w_byte const *daysInMonth;

  /*
  ** Adjust millis for non-whole days only.
  */
 
  millis -= days * MSECS_PER_DAY;

  /*
  ** When we have a number of days past 1582, we adjust for the 10 days lost
  ** from Thursday, October 4, 1582 to Friday, October 15 1582 which jumped
  ** 10 days.
  */

  if (days > 577737) {
    days += 10;
  }
 
  year = days / 365;
  days = days % 365;

  /*
  ** 'year' now holds the number of elapsed year, so add 1 for the current year.
  */

//  year += 1;
  days++;
  //woempa(9, "DATE: year = %i and days = %i\n",year,days);
  /*
  ** Prior to 1700, all years evenly divisible by 4 are leap.
  */

  if (year < 1700) {
    days -= year / 4;
  }
  else {
    days -= year / 4;      /* deduct the leap years            */
    days += year / 100;    /* add in century years             */
    days -= year / 400;    /* deduct years / 400               */
    days -= 12;            /* deduct century years before 1700 */
  }

  //woempa(9, "leap year correction: year = %i and days = %u\n",year,(unsigned int)days);

  /*
  ** We now make sure that days left is > 0
  */

  while (days <= 0) {
    w_boolean lpy = isLeapYear(year);
    year -= 1;
    days +=( lpy ? 366 : 365 );
  }
  //woempa(9, "second day correction: year = %i and days = %i\n",year,(signed int)days);

  /*
  ** 'year' now holds the number of elapsed year, so add 1 for the current year.
  */
 
  year += 1;
 
  /*
  ** Now deduct the days in each month, starting from January to find each month and
  ** day of the month, while adjusting for leap years.
  */
 
  day = days;
  month = 0;
 
  if (isLeapYear(year)) {
    daysInMonth = DaysInMonthLeap;
  }
  else {
    daysInMonth = DaysInMonth;
  }
 
  for (i = 1; i < 13; i++) {
    month = i;
    if (day <= daysInMonth[i]) {
      break;
    }
    else {
      day -= daysInMonth[i];
    }
  }
 
  date->year = year;
  date->month = month;
  date->day = day;

  /*
  ** We have in millis the number of milliseconds that don't fit in a whole day;
  ** fill up the rest of the structure.
  */

  date->hour = (w_int)(millis / MSECS_PER_HOUR);
  millis -= (w_millis)(date->hour * MSECS_PER_HOUR);
  date->minute = (w_int)(millis / MSECS_PER_MINUTE);
  millis -= (w_millis)(date->minute * MSECS_PER_MINUTE);
  date->second = (w_int)(millis / MSECS_PER_SECOND);
  millis -= (w_millis)(date->second * MSECS_PER_SECOND);
  date->msec = (w_int)millis;

  if (isValidDate(date)) {
    return 0;
  }
  else {
    return -1;
  }
     
}
コード例 #13
0
ファイル: timeutil.cpp プロジェクト: sanjayui/tinymux
bool do_convtime(const UTF8 *str, FIELDEDTIME *ft)
{
    memset(ft, 0, sizeof(FIELDEDTIME));
    if (!str || !ft)
    {
        return false;
    }

    // Day-of-week OR month.
    //
    const UTF8 *p = str;
    int i, iHash;
    if (!ParseThreeLetters(&p, &iHash))
    {
        return false;
    }

    for (i = 0; (i < 12) && iHash != MonthTabHash[i]; i++)
    {
        ; // Nothing.
    }

    if (i == 12)
    {
        // The above three letters were probably the Day-Of-Week, the
        // next three letters are required to be the month name.
        //
        if (!ParseThreeLetters(&p, &iHash))
        {
            return false;
        }

        for (i = 0; (i < 12) && iHash != MonthTabHash[i]; i++)
        {
            ; // Nothing.
        }

        if (i == 12)
        {
            return false;
        }
    }

    // January = 1, February = 2, etc.
    //
    ft->iMonth = static_cast<unsigned short>(i + 1);

    // Day of month.
    //
    ft->iDayOfMonth = (unsigned short)mux_atol(p);
    if (ft->iDayOfMonth < 1 || daystab[i] < ft->iDayOfMonth)
    {
        return false;
    }
    while (*p && *p != ' ') p++;
    while (*p == ' ') p++;

    // Hours
    //
    ft->iHour = (unsigned short)mux_atol(p);
    if (ft->iHour > 23 || (ft->iHour == 0 && *p != '0'))
    {
        return false;
    }
    while (*p && *p != ':') p++;
    if (*p == ':') p++;
    while (*p == ' ') p++;

    // Minutes
    //
    ft->iMinute = (unsigned short)mux_atol(p);
    if (ft->iMinute > 59 || (ft->iMinute == 0 && *p != '0'))
    {
        return false;
    }
    while (*p && *p != ':') p++;
    if (*p == ':') p++;
    while (*p == ' ') p++;

    // Seconds
    //
    ft->iSecond = (unsigned short)mux_atol(p);
    if (ft->iSecond > 59 || (ft->iSecond == 0 && *p != '0'))
    {
        return false;
    }
    while (mux_isdigit(*p))
    {
        p++;
    }

    // Milliseconds, Microseconds, and Nanoseconds
    //
    if (*p == '.')
    {
        p++;
        size_t n;
        const UTF8 *q = (UTF8 *)strchr((char *)p, ' ');
        if (q)
        {
            n = q - p;
        }
        else
        {
            n = strlen((char *)p);
        }

        ParseDecimalSeconds(n, p, &ft->iMillisecond, &ft->iMicrosecond,
            &ft->iNanosecond);
    }
    while (*p && *p != ' ') p++;
    while (*p == ' ') p++;

    // Year
    //
    ft->iYear = (short)mux_atol(p);
    while (mux_isdigit(*p))
    {
        p++;
    }
    while (*p == ' ') p++;
    if (*p != '\0')
    {
        return false;
    }

    // DayOfYear and DayOfWeek
    //
    ft->iDayOfYear = 0;
    ft->iDayOfWeek = 0;

    return isValidDate(ft->iYear, ft->iMonth, ft->iDayOfMonth);
}
コード例 #14
0
TimeDateValue::TimeDateValue(const CSSM_DATA &data)
:	BlobValue(data)
{
	if (Length != kTimeDateSize || !isValidDate())
		CssmError::throwMe(CSSMERR_DL_INVALID_VALUE);
}
コード例 #15
0
Date::Date(int year, Month month, int day) :
year { year }, month { month }, day { day } {
    if (!isValidDate(year, month, day))
        throw std::out_of_range { "invalid date" };
}