Esempio n. 1
0
void calendarMoveCursor(int x, int y)
{
	switch(getControlID())
	{
		case 0: // up button
			if(curDay > 7)
			{
				curDay -= 7;
			}
			break;
		case 1: // down button
			if(curDay < daysInMonth(curMonth-1,curYear)-6)
			{
				curDay += 7;
			}
			break;
		case 2: // left button
			--curDay;
			if(curDay < 1)
			{
				curDay = 1;
			}
			break;
		case 3: // right button
			++curDay;
			if(curDay > daysInMonth(curMonth-1,curYear))
			{
				curDay = daysInMonth(curMonth-1,curYear);
			}
			break;
		case 4: // edit up button
			moveKBCursorAbsolute(getPositionAbove());
			break;
		case 5: // edit down button
			moveKBCursorAbsolute(getPositionBelow());
			break;
		case 6: // edit left button
			if(getKBCursor() > 0)
			{
				moveKBCursorRelative(CURSOR_BACKWARD);
			}
			break;
		case 7: // edit right button
			if(!isReminderEnd(getKBCursor()))
			{
				moveKBCursorRelative(CURSOR_FORWARD);	
			}
			break;
	}
}
Esempio n. 2
0
int getDayFromTouch(int tx, int ty)
{
	uint16 z = 1;	
	uint16 x = dayOfWeek(1,curMonth,curYear);
	uint16 y = 0;
	
	while(z <= daysInMonth(curMonth-1,curYear))
	{	
		if(tx > (x*31) && tx < 21+(x*31))
		{
			if(ty > (15*y) && ty < 13+(15*y))
				return z;
		}		
		
		x++;
		if(x > 6)
		{
			x = 0;
			y++;
		}
		
		z++;
	}
	
	return -1;
}
Esempio n. 3
0
uint8_t Calendar::getDaysInMonth()
{
    time_t unixtime = time(NULL);
    struct tm * timeinfo = localtime(&unixtime);

    return daysInMonth(timeinfo->tm_mon, timeinfo->tm_year);
}
inline QString RecordingsModel::sectionName(const QDate &modDate)
{
    auto curDate = QDate::currentDate();
    auto days = modDate.daysTo(curDate);
    if (days == 0)
    {
        return tr("Today");
    }
    if (days == 1)
    {
        return tr("Yesterday");
    }
    if (days < 7 && modDate.dayOfWeek() < curDate.dayOfWeek())
    {
        return tr("This week");
    }
    if (days < curDate.daysInMonth() && modDate.day() < curDate.day())
    {
        return tr("This month");
    }
    if (days < 183)
    {
        return tr("Last 6 months");
    }
    return tr("Older");
}
Esempio n. 5
0
void nextDate(TimeVal* time)
{
    // If this is the last day of the current month
    if (time->date >= daysInMonth(time->month, time->year))
    {
        // It is now the first of the following month
        time->date = 1;
        
        // If this is the last month of the year
        if (time->month == 12)
        {
            // It is now the first month of the next year
            time->month = 1;
            
            // Move to the next year
            time->year++;
        }
        else
        {
            // Simply move to the next month
            time->month++;
        }
    }
    else
    {
        // Simply move to the next day of the month
        time->date++;
    }
}
Esempio n. 6
0
// Get date for next day
struct date updateDate(struct date d)
{
	int daysInMonth(struct date);
	
	//Update day
	if(d.day >= daysInMonth(d))
	{
		d.day = 1;
		
		// Update month
		if(d.month >= 12)
		{
			d.month = 1;
			
			// Update year
			++d.year;
		} else {
			++d.month;
		}
	} else {
		++d.day;
	}
	
	return d;
}
Esempio n. 7
0
int SDateTime::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: { QString _r = longMonthName((*reinterpret_cast< int(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 1: { bool _r = isLeapYear((*reinterpret_cast< int(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 2: { int _r = daysInMonth((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        case 3: { QString _r = amText();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 4: { QString _r = pmText();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 5: { int _r = hourMode();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
Esempio n. 8
0
QDate KCalendarSystem::addYears( const QDate &date, int numYears ) const
{
    if ( isValid( date ) ) {

        int originalYear, originalMonth, originalDay;
        int newYear, newMonth, newDay;
        QDate firstOfNewMonth, newDate;

        julianDayToDate( date.toJulianDay(), originalYear, originalMonth, originalDay );

        newYear = originalYear + numYears;
        newMonth = originalMonth;

        //Adjust day number if new month has fewer days than old month
        if ( setDate( firstOfNewMonth, newYear, newMonth, 1 ) ) {
            int daysInNewMonth = daysInMonth( firstOfNewMonth );
            newDay = ( daysInNewMonth < originalDay ) ? daysInNewMonth : originalDay;

            if ( setDate( newDate, newYear, newMonth, newDay ) ) {
                return newDate;
            }
        }

    }

    //Is QDate's way of saying is invalid
    return QDate::fromJulianDay( 0 );
}
Esempio n. 9
0
bool SimpleDate::isValidDate(int month, int day, int year) {
	if (month < 1 || month > NUM_MONTHS)
		return false;
	if (day < 1 || day > daysInMonth(month, year))
		return false;
	return year >= MIN_YEAR;
}
Esempio n. 10
0
 DateTime& MTD_FLASHMEM DateTime::setUnixDateTime(uint32_t unixTime)
 {
     unixTime      -= SECONDS_FROM_1970_TO_2000;
     seconds        = unixTime % 60;
     unixTime      /= 60;
     minutes        = unixTime % 60;
     unixTime      /= 60;
     hours         = unixTime % 24;
     uint16_t days = unixTime / 24;
     uint8_t leap;
     for (year = 2000; ; ++year)
     {
         leap = year % 4 == 0;
         if (days < 365u + leap)
             break;
         days -= 365 + leap;
     }
     for (month = 1; ; ++month)
     {
         uint8_t daysPerMonth = daysInMonth(month - 1);
         if (leap && month == 2)
             ++daysPerMonth;
         if (days < daysPerMonth)
             break;
         days -= daysPerMonth;
     }
     day = days + 1;    
     return *this;
 }
Esempio n. 11
0
uint16_t RTCx::dayOfYear(uint16_t year, uint8_t month, uint8_t day)
{
  uint16_t doy = 0;
  uint8_t m = 1;
  while (m < month)
    doy += daysInMonth(year, m++);
  doy += day;
  return doy;
}
Esempio n. 12
0
Date::Date(double time, int offset):
    offset_(offset),
    time_(time)
{
    const int C1   = 365;
    const int C4   =  4 * C1 + 1;
    const int C100 = 25 * C4 - 1;
    const int C400 =  4 * C100 + 1;
    const int N0   = 719528; // linear day number of Jan 1st year 0

    int64_t t = int64_t(time) + int64_t(N0) * 86400;
    int n = t / 86400;
    if (n < 0) n = 0;

    hour_ = (t / 3600) % 24;
    minutes_ = (t / 60) % 60;
    seconds_ = t % 60;
    weekDay_ = (n + 6) % 7;

    int y = 400 * (n / C400);
    n = n % C400;

    while (true) {
        int h = C100 + leapYear(y);
        if (n < h) break;
        n -= h;
        y += 100;
    }

    while (true) {
        int h = C4 - !leapYear(y);
        if (n < h) break;
        n -= h;
        y += 4;
    }

    while (true) {
        int h = C1 + leapYear(y);
        if (n < h) break;
        n -= h;
        ++y;
    }

    year_ = y;
    yearDay_ = n;

    month_ = 0;
    while (true) {
        int h = daysInMonth(month_, y);
        if (n < h) break;
        ++month_;
        n -= h;
    }
    ++month_;
    day_ = n + 1;
}
Esempio n. 13
0
 uint16_t MTD_FLASHMEM DateTime::date2days(uint16_t y, uint8_t m, uint8_t d)
 {
     if (y >= 2000)
         y -= 2000;
     uint16_t days = d;
     for (uint8_t i = 1; i < m; ++i)
         days += daysInMonth(i - 1);
     if (m > 2 && y % 4 == 0)
         ++days;
     return days + 365 * y + (y + 3) / 4 - 1;
 }
Esempio n. 14
0
void main()
{
    //Test Variables
    int year, leap, num, num2, month, day, bitCount;
    month = 2;
    num = 22;
    num2 = 37;
    year = 2004;
    day = daysInMonth(month, year);
    bitCount = countOnes(num);
    leap = isLeap(year);

    //Testing countOnes
    printf("The number of bits in %u is %d\n", num, bitCount);

    //Testing isEven
    if (isEven(num))
    {
        printf("%d is an even number\n", num);
    }
    else
    {
        printf("%d is not an even number\n", num);
    }

    //Testing isOdd
    if (isOdd(num2))
    {
        printf("%d is an odd number\n", num2);
    }
    else
    {
        printf("%d is not an odd number\n", num2);
    }

    //Testing isLeap
    if (leap == 1)
    {
        printf("The year %d is a leap year\n",year);
    }
    else
    {
        printf("The year %d is not a leap year\n",year);
    }

    //Testing daysInMonth
    printf("Febuary has %d days in the year %d\n",day, year);

    //Testing packChars
    printf("Packing %d and %d together forms 0x%x\n", 3, 5, packChars(3,5));

    getchar();
}
Esempio n. 15
0
const bool Date::isValidDate() const
{
    if(year<1)
        return false;
    if(!isValidMonth())
        return false;
    if(day>daysInMonth(month))
        return false;
    
    return true;
    
}
Esempio n. 16
0
// Ok
TQDate KCalendarSystemHebrew::addMonths( const TQDate & date, int nmonths ) const
{
  TQDate result = date;

  while ( nmonths > 0 )
  {
    result = addDays(result, daysInMonth(result));
    --nmonths;
  }

  while ( nmonths < 0 )
  {
    // get the number of days in the previous month to be consistent with
    // addMonths where nmonths > 0
    int nDaysInMonth = daysInMonth(addDays(result, -day(result)));
    result = addDays(result, -nDaysInMonth);
    ++nmonths;
  }

  return result;
}
Esempio n. 17
0
struct RTCx::tm *RTCx::gmtime_r(const time_t *timep, struct tm *result)
{
  time_t t = *timep;
  // Find multiples of 4 years since epoch
  int8_t fourYears = (int8_t)(t / SECS_PER_4_YEARS);
  if (t < 0)
    --fourYears; // Now remaining time will be positive and must add
  result->tm_year = (fourYears * 4) + (RTCX_EPOCH - 1900); // years since 1900
  t -= (fourYears * SECS_PER_4_YEARS);

  // Split t into seconds in day and days remaining.
  int16_t days = (t / SECS_PER_DAY); // Fits into 16 bits
  time_t partialDay_s = (t % SECS_PER_DAY); // seconds
  
  // Calculate hours, minutes and seconds next so that the rest of the
  // calculations can be made in days using 16 bit arithmetic.
  result->tm_sec = (partialDay_s % 60);
  int16_t partialDay_m = partialDay_s / 60; // minutes
  result->tm_min = (partialDay_m % 60);
  result->tm_hour = partialDay_m / 60; 

  if (days >= (365 + 365 + 366)) {
    // Third year in a four year block is a leap year
    days -= (365 + 365 + 366);
    result->tm_year += 3;
  }
  else
    while (days >= 365) {
      days -= 365;
      ++(result->tm_year);
    }

  // days is now the day of year
  result->tm_yday = days;
  result->tm_mon = 0;
  result->tm_mday = 1 + days;

  while (true) {
    uint8_t dim = daysInMonth(result->tm_year+1900, result->tm_mon+1);
    if (result->tm_mday > dim) {
      result->tm_mday -= dim;
      ++(result->tm_mon);
    }
    else
      break;
  }

  // Compute day of week
  uint16_t daysSinceEpoch = (*timep / 86400L);
  result->tm_wday = (daysSinceEpoch + 4) % 7; // 1970-01-01 was Thursday (day 4)
  return result;
}
Esempio n. 18
0
extern void
fixBadDate(SystemCounts *sc) {
	int maxDays;
	
	if (sc->year < FILE_YEAR_MIN)
		sc->year = FILE_YEAR_MIN;
	if (sc->monthday < 1)
		sc->monthday = 1;

	maxDays = daysInMonth(sc->month);

	do {
		if (sc->monthday > maxDays) {
			sc->month++;
			if (sc->month > 12) {
				sc->month = 1;
				sc->year++;
			}
			sc->monthday -= maxDays;
		}
		maxDays = daysInMonth(sc->month);
	} while (sc->monthday > maxDays);
}
Esempio n. 19
0
static void carryTimeInc(unsigned &yr, unsigned &mon, unsigned &dy, unsigned &hr, unsigned &min)
{
    hr += (min/60);
    min %= 60;
    dy += (hr/24);
    hr %= 24;
    if (mon==0)
        mon++;
    if (dy==0)
        dy++;
    if (mon<=12) {
        if (dy<=daysInMonth(yr,mon))
            return;
    }
    for (;;) {
        yr += (mon-1)/12;
        mon = (mon-1)%12+1;
        unsigned dinm = daysInMonth(yr,mon);
        if (dy<=dinm)
            break;
        mon++;
        dy -= dinm;
    }
}
Esempio n. 20
0
	//increment operator
	void operator++()
	{
		if (day < daysInMonth(month, year))
			day += 1;
		else if(month == 12)
		{
			day = 1;
			month = 1;
			year += 1;
		}
		else
		{
			day = 1;
			month += 1;
		}
	}
Esempio n. 21
0
File: day.c Progetto: sheab/cs137
int dayOfYear(int day, int month, int year) {
    if(year < 1583)
        return -1;
    int i = 0;
    int testMonth;
    for(testMonth = 1; testMonth <= 12; testMonth++) {
        int daysInTestMonth = daysInMonth(testMonth,year);
        int testDay;
        for(testDay = 1; testDay <= daysInTestMonth; testDay++) {
            i++;
            if(testDay == day && testMonth == month)
                return i;
        }
    }
    return -1;
}
Esempio n. 22
0
void Calendar::setDate(uint8_t date)
{
    time_t unixtime = time(NULL);
    struct tm * timeinfo = localtime(&unixtime);

    // check date integrity
    int days = daysInMonth(timeinfo->tm_mon, timeinfo->tm_year);

    if ((date >= 1) && (date <= days))
    {
        timeinfo->tm_mday = date;

        struct timeval tvp;
        tvp.tv_sec = mktime(timeinfo);
        settimeofday(&tvp, NULL);
    }
}
Esempio n. 23
0
void CDateTime::addMonths(int add)
{
    if (add == 0)
        return;

    // Date inférieure
    if (add < 0)
    {
        for (int i = 0; i > add; --i)
        {
            if (m_month == 1)
            {
                m_month = 12;
                --m_year;
            }
            else
            {
                --m_month;
            }
        }
    }
    // Date supérieure
    else if (add > 0)
    {
        for (int i = 0; i < add; ++i)
        {
            if (m_month == 12)
            {
                m_month = 1;
                ++m_year;
            }
            else
            {
                ++m_month;
            }
        }
    }

    unsigned int days = daysInMonth(m_month, m_year);

    // Le jour est trop grand
    if (m_day > days)
        m_day = days;
}
Esempio n. 24
0
int findDayOfWeek(int date, int month, int year) {
    int refYear = 1990;
    int refWeekDay = 1; // Jan 1, 1990 was a Monday
    
    if(year < 1990)
        std::cerr << "ERROR: Year chosen earlier than reference year!\n";
    
    int numDays = 0;
    for(int i=refYear; i<year; i++)
        if(isLeapYear(i)) 
            numDays += 366;
        else
            numDays += 365;
    for(int j=1; j<month; j++)
        numDays += daysInMonth(j, year);
    numDays += date;
    
    return((numDays - refWeekDay)%7 + 1);
}
Esempio n. 25
0
Date::Date(int year, int month, int day, int hour, int minutes, int seconds, int offset):
    year_(year),
    month_(month),
    day_(day),
    hour_(hour),
    minutes_(minutes),
    seconds_(seconds),
    offset_(offset)
{
    if (year < 1) year = 1;
    if (month > 12) month = 12;
    else if (month < 1) month = 1;
    if (day > 31) day = 31;
    else if (day < 1) day = 1;
    if (hour < 0) hour = 0;
    else if (hour > 23) hour = 23;
    if (minutes > 59) minutes = 59;
    else if (minutes < 0) minutes = 0;
    if (seconds > 59) seconds = 59;
    else if (seconds < 0) seconds = 0;
    if (offset > 600) offset = 600;
    else if (offset < -600) offset = -600;

    --day;
    --month;

    int64_t t = 0;
    for (int i = 0; i < month; ++i)
        t += daysInMonth(i, year);
    t += day;
    yearDay_ = t;
    t += (31 * 7 + 30 * 4 + 28) * (year - 1970);
    if (year >= 1970)
        t += leaps(1970, year);
    else
        t -= leaps(1970, year - 1);
    weekDay_ = (719528 + t + 6) % 7;
    t *= 86400;
    t += 3600 * hour + 60 * minutes + seconds;
    time_ = t;
}
Esempio n. 26
0
QDate KCalendarSystem::addMonths( const QDate &date, int numMonths ) const
{
    if ( isValid( date ) ) {

        int originalYear, originalMonth, originalDay;
        int newYear, newMonth, newDay;
        int monthsInOriginalYear, daysInNewMonth;
        QDate firstOfNewMonth, newDate;

        julianDayToDate( date.toJulianDay(), originalYear, originalMonth, originalDay );

        monthsInOriginalYear = monthsInYear( date );

        newYear = originalYear + ( ( originalMonth + numMonths ) / monthsInOriginalYear );
        newMonth = ( originalMonth + numMonths ) % monthsInOriginalYear;

        if ( newMonth == 0 ) {
            newYear = newYear - 1;
            newMonth = monthsInOriginalYear;
        }
        if ( newMonth < 0 ) {
            newYear = newYear - 1;
            newMonth = newMonth + monthsInOriginalYear;
        }

        //Adjust day number if new month has fewer days than old month
        if ( setDate( firstOfNewMonth, newYear, newMonth, 1 ) ) {
            daysInNewMonth = daysInMonth( firstOfNewMonth );
            newDay = ( daysInNewMonth < originalDay ) ? daysInNewMonth : originalDay;

            if ( setDate( newDate, newYear, newMonth, newDay ) ) {
                return newDate;
            }
        }

    }

    //Is QDate's way of saying is invalid
    return QDate::fromJulianDay( 0 );
}
Esempio n. 27
0
void Calendar::setYear(uint32_t year)
{
    if (year >= 1900)
    {
        time_t unixtime = time(NULL);
        struct tm * timeinfo = localtime(&unixtime);

        // tm_year is using 1900 as zero
        timeinfo->tm_year = year - 1900;

        // check date integrity
        int days = daysInMonth(timeinfo->tm_mon, timeinfo->tm_year);
        if (timeinfo->tm_mday > days)
        {
            timeinfo->tm_mday = days;
        }

        struct timeval tvp;
        tvp.tv_sec = mktime(timeinfo);
        settimeofday(&tvp, NULL);
    }
}
Esempio n. 28
0
void Calendar::setMonth(uint8_t month)
{
    if ((month >= 1) && (month <= 12))
    {
        time_t unixtime = time(NULL);
        struct tm * timeinfo = localtime(&unixtime);

        // months are 0-indexed
        timeinfo->tm_mon = month - 1;

        // check date integrity
        int days = daysInMonth(timeinfo->tm_mon, timeinfo->tm_year);

        if (timeinfo->tm_mday > days)
        {
            timeinfo->tm_mday = days;
        }

        struct timeval tvp;
        tvp.tv_sec = mktime(timeinfo);
        settimeofday(&tvp, NULL);
    }
}
Esempio n. 29
0
	//checks if a given date is a valid date
	bool isDate(int d, int m, int y)
	{
		if (y < 1950 || y > 2015)
		{
			cout << "Error! Unsupported year." << endl;
			return false;
		}

		if (m < 1 || m > 12) 
		{
			cout << "Error! Invalid month." << endl;
			return false;
		}

		int maxDays = daysInMonth(m, y);

		if (d <= 0 || d > maxDays) 
		{
			cout << "Error! Invalid day of the month." << endl;
			return false;
		}
		return true;
	}
Esempio n. 30
0
void DateTime::increment(int numMinutes) {
    minute += numMinutes;
    
    while (minute >= 60) {
        minute-= 60;
        hour++;
    }
    while(hour >= 24) {
        hour -= 24;
        weekday ++;
        day++;
    }
    while(weekday > 7)
        weekday -= 7;

    if(day > daysInMonth(month, year)) {
        day = 1;
        month++;
        if(month > 12) {
            month = 1;
            year++;
        }
    }
}