Exemple #1
0
 void NDateTime::addHours(const nint hours)
 {
     nint _hours = hours;
     while (getHour() * _hours > 23)
     {
         _hours -= 24;
         addDays(1);
     }
     while (getHour() + _hours < 0)
     {
         _hours += 24;
         addDays(-1);
     }
     m_Time.addHours(_hours);
 }
Exemple #2
0
void Date::setDateAsWeekday(int yy,int mm,int nn,int ww)
{
	int d;
	setDate(yy,mm,1);
	if(nn>0)
	{
		int w=getWeekday();
		if(ww>=w)
		{
			d=(nn-1)*7+ww-w;
		}
		else
		{
			d=(nn-1)*7+7+ww-w;
		}
	}
	else
	{
		setDate(yy,mm,getDaysOfMonth());
		int w=getWeekday();
		if(ww<=w)
		{
			d=(nn+1)*7+ww-w;
		}
		else
		{
			d=(nn+1)*7-7+ww-w;
		}
	}
	addDays(d);
}
Exemple #3
0
void Date::setDateAsWeekday(int yy,int nn,int ww)
{
	int d;
	if(nn>0)
	{
		setDate(yy,1,1);
		int w=getWeekday();
		if(ww>=w)
		{
			d=(nn-1)*7+ww-w;
		}
		else
		{
			d=(nn-1)*7+7+ww-w;
		}
	}
	else
	{
		setDate(yy,12,31);
		int w=getWeekday();
		if(ww<=w)
		{
			d=(nn+1)*7+ww-w;
		}
		else
		{
			d=(nn+1)*7-7+ww-w;
		}
	}
	addDays(d);
}
int KCalendarSystemHebrew::weekNumber(const TQDate& date, int * yearNum) const
{
  TQDate firstDayWeek1, lastDayOfYear;
  int y = year(date);
  int week;
  int weekDay1, dayOfWeek1InYear;

  // let's guess 1st day of 1st week
  setYMD(firstDayWeek1, y, 1, 1);
  weekDay1 = dayOfWeek(firstDayWeek1);

  // iso 8601: week 1  is the first containing thursday and week starts on
  // monday
  if (weekDay1 > 4 /*Thursday*/)
    firstDayWeek1 = addDays(firstDayWeek1 , 7 - weekDay1 + 1); // next monday

  dayOfWeek1InYear = dayOfYear(firstDayWeek1);

  if ( dayOfYear(date) < dayOfWeek1InYear ) // our date in prev year's week
  {
    if ( yearNum )
      *yearNum = y - 1;
    return weeksInYear(y - 1);
  }

  // let's check if its last week belongs to next year
  setYMD(lastDayOfYear, y + 1, 1, 1);
  lastDayOfYear = addDays(lastDayOfYear, -1);
  if ( (dayOfYear(date) >= daysInYear(date) - dayOfWeek(lastDayOfYear) + 1)
       // our date is in last week
       && dayOfWeek(lastDayOfYear) < 4) // 1st week in next year has thursday
    {
      if ( yearNum )
        *yearNum = y + 1;
      week = 1;
    }
  else
  {
   if( weekDay1 < 5 ) // To calculate properly the number of weeks
                     //  from day a to x let's make a day 1 of week
      firstDayWeek1 = addDays( firstDayWeek1, -( weekDay1 - 1));

   week = firstDayWeek1.daysTo(date) / 7 + 1;
  }

  return week;
}
Exemple #5
0
Date Date::addHours(long hours)
{
	long days = (getHh()+hours)/24;
	hours = (getHh()+hours)%24;
	Date d = addDays(days);
	d.setHh(hours);
	return d;
}
bool HDate::isDateBeforeHoliday(hdate_struct h,int d)
{
    hdate_struct  h1 = addDays(h,1);
    int hol_tomorow = hdate_get_holyday(&h1, d);
    if(h.hd_dw==6||hdate_get_holyday_type(hol_tomorow)==1)
        return true;

    return false;
}
hdate_struct HDate::weekStart(hdate_struct h)
{
   // hdate_struct date = h;
    int day = h.hd_dw, n = 0;
    while (day != 1) {
        if (day == 0) day = 6;
        else day = day - 1;
        n = n + 1;
    }
    return addDays(h,-n);

}
// 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;
}
Exemple #9
0
int KCalendarSystem::monthsInYear( const QDate &date ) const
{
    // Last day of this year = first day of next year minus 1 day
    // Use setAnyDate() to allow correct calculation in last valid year

    if ( isValid( date ) ) {
        QDate firstDayOfNextYear;
        d->setAnyDate( firstDayOfNextYear, year( date ) + 1, 1, 1 );
        QDate lastDayOfThisYear = addDays( firstDayOfNextYear, -1 );
        return month( lastDayOfThisYear );
    }

    return -1;
}
Exemple #10
0
void CDateTime::addHours(int add)
{
    // Date inférieure
    if (add < 0)
    {
        for (int i = 0; i > add; --i)
        {
            // Jour précédent
            if (m_hour == 0)
            {
                addDays(-1);
                m_hour = 23;
            }
            else
            {
                --m_hour;
            }
        }
    }
    // Date supérieure
    else if (add > 0)
    {
        for (int i = 0; i < add; ++i)
        {
            // Jour suivant
            if (m_hour == 23)
            {
                addDays(1);
                m_hour = 0;
            }
            else
            {
                ++m_hour;
            }
        }
    }
}
Exemple #11
0
QString Tasty::parseDate(const QString& d, const bool bigLetter)
{
    auto datetime = QDateTime::fromString(d.left(19), "yyyy-MM-ddTHH:mm:ss");
    auto date = datetime.date();
    auto today = QDate::currentDate();

    if (today == date)
        return datetime.toString(QString("%1егодня в H:mm").arg(bigLetter ? "С" : "с"));
    if (today == date.addDays(1))
        return datetime.toString(QString("%1чера в H:mm").arg(bigLetter ? "В" : "в"));

    bool showYear = date.year() != today.year();
    QString format = showYear ? "d MMM yyyy" : "d MMM в H:mm";
    return datetime.toString(format);
}
Exemple #12
0
void
Date::addTime(double time, std::string unit)
{
    if( unit.size() == 0 )
        unit = unitStr;

    if( unit[0] == 'y' )
        addYears( time );
    else if( unit.substr(0,2) == "mo" )
        addMonths( time );
    else if( unit[0] == 'd' )
        addDays( time );
    else if( unit[0] == 'h' )
        addHours( time );
    else if( unit.substr(0,2) == "mi" )
        addMinutes( time );
    else if( unit[0] == 's' )
        addSeconds( time );

    else  // the default
        addDays( time );

    return;
}
void
MainWindow::silentlyCheckForUpdates() {
  auto forceUpdateCheck = mtx::sys::get_environment_variable("FORCE_UPDATE_CHECK") == "1";

  if (!forceUpdateCheck && !Util::Settings::get().m_checkForUpdates)
    return;

  auto lastCheck = Util::Settings::get().m_lastUpdateCheck;
  if (!forceUpdateCheck && lastCheck.isValid() && (lastCheck.addDays(1) >= QDateTime::currentDateTime()))
    return;

  auto thread = new UpdateCheckThread(this);

  connect(thread, &UpdateCheckThread::checkFinished, this, &MainWindow::updateCheckFinished);

  thread->start();
}
Exemple #14
0
void CDateTime::addSeconds(int add)
{
    if (add == 0)
        return;

    // On ajoute les jours entiers séparemment pour alléger les calculs
    int days = add / 86400;
    if (days)
        addDays(days);

    add %= 86400;

    if (add < 0)
    {
        for (int i = 0; i > add; --i)
        {
            // Minute précédente
            if (m_second == 0)
            {
                addMinutes(-1);
                m_second = 59;
            }
            else
            {
                --m_second;
            }
        }
    }
    // Date supérieure
    else if (add > 0)
    {
        for (int i = 0; i < add; ++i)
        {
            // Minute suivante
            if (m_second == 59)
            {
                addMinutes(1);
                m_second = 0;
            }
            else
            {
                ++m_second;
            }
        }
    }
}
void
MainWindow::silentlyCheckForUpdates() {
  auto forceUpdateCheck = mtx::sys::get_environment_variable("FORCE_UPDATE_CHECK") == "1";

  if (!forceUpdateCheck && !Util::Settings::get().m_checkForUpdates)
    return;

  auto lastCheck = Util::Settings::get().m_lastUpdateCheck;
  if (!forceUpdateCheck && lastCheck.isValid() && (lastCheck.addDays(1) >= QDateTime::currentDateTime()))
    return;

  auto thread = new UpdateCheckThread(this);

  connect(thread, SIGNAL(checkFinished(mtx::gui::UpdateCheckStatus, mtx_release_version_t)), this, SLOT(updateCheckFinished(mtx::gui::UpdateCheckStatus, mtx_release_version_t)));

  thread->start();
}
void
TestRecurrentTransaction::testSetEndDate() {
    auto endDate = QDate::currentDate().addYears(1);
    auto newEndDate = endDate.addDays(1);
    auto amount = .45;
    auto account = std::make_shared<PublicAccount>("Test account", .0, "");
    auto category = std::make_shared<com::chancho::Category>("Sushi", com::chancho::Category::Type::EXPENSE);
    auto transactionPtr = std::make_shared<com::chancho::Transaction>(account, amount, category);
    auto recurrentPtr = std::make_shared<com::chancho::RecurrentTransaction>(transactionPtr,
        std::make_shared<com::chancho::RecurrentTransaction::Recurrence>(
                com::chancho::RecurrentTransaction::Recurrence::Defaults::DAILY, QDate::currentDate(), endDate));

    auto qmlTransaction = std::make_shared<com::chancho::tests::PublicRecurrentTransaction>(recurrentPtr);
    QSignalSpy spy(qmlTransaction.get(), SIGNAL(endDateChanged(QDate)));
    qmlTransaction->setEndDate(newEndDate);
    QCOMPARE(spy.count(), 1);
}
int main(int argc, char *argv[])
{
    std::cout<<"start"<<std::endl;
    QCoreApplication a(argc, argv);
    YahooFinance yf;

    time_t  timeNow = time(0);
    tm* tmNow = localtime(&timeNow);
    tm tmPast = addDays(tmNow, -30);


    std::vector<HistoricalStockData*> data;

    yf.historicalDataGet("GOOG",&tmPast, tmNow,FTSE_INDICES, data);

    while(true)
    {

    }

    return 0;
}
Exemple #18
0
// ISO compliant week numbering, not traditional number, rename in KDE5 to isoWeeksInYear()
int KCalendarSystem::weeksInYear( int year ) const
{
    // Last day of this year = first day of next year minus 1 day
    // Use setAnyDate() to allow correct calculation in last valid year

    if ( isValid( year, 1, 1 ) ) {
        QDate firstDayOfNextYear;
        d->setAnyDate( firstDayOfNextYear, year + 1, 1, 1 );
        QDate lastDayOfThisYear = addDays( firstDayOfNextYear, -1 );

        int lastWeekInThisYear = weekNumber( lastDayOfThisYear );

        // If the last day of the year is in the first week of next year use the week before
        if ( lastWeekInThisYear == 1 ) {
            lastDayOfThisYear = lastDayOfThisYear.addDays( -7 );
            lastWeekInThisYear = weekNumber( lastDayOfThisYear );
        }

        return lastWeekInThisYear;
    }

    return -1;
}
void QDateTimeModel::setWeekNumber(int week)
{
    Q_D(QDateTimeModel);
    int diff = week - d->value.date().weekNumber();
    addDays(7 * diff);
}
Exemple #20
0
Date& Date::addWeeks(int n)
{
	return addDays(n*7);
}
Exemple #21
0
Date& Date::operator -=(const int& n)
{
	addDays(-n);
	return *this;
}
void addMonth(Date& date){
	// broad assumption that adding a month is 30 days
	// could add a switch statement using dayTab and switch statement,
	// but that would require 'adding a Februrary' or similar which feels bizarre
	addDays(date, 30);
}
Exemple #23
0
VSDateTime VSDateTime::addSecs(int secs) const
{
	return addDays(secs/86400).addMSecs((secs%86400)*1000);
}
Exemple #24
0
	/**
	 * Add week to the date represented by this object.
	 * @param weeks The number of weeks to add to this object.
	 * @throws DateTimeException if the resulting DateTime don't represent a valid DateTime
	 */
	void addWeeks(int weeks)
	{
		addDays(weeks * 7);
	}
void addDay(Date& date){
	addDays(date, 1);
}
QList<QVariantMap> DatabaseManager::getStartPageSeries()
{
    auto date = QDateTime::currentDateTime().date();
    auto locale  = QLocale(QLocale::English);
    auto firstAiredStart = date.addDays(1 - date.dayOfWeek()).toString(Qt::ISODate); // Monday == 1
    auto firstAiredEnd = date.addDays(7 - date.dayOfWeek()).toString(Qt::ISODate); // Sunday == 7
    auto status = "Continuing";
    const auto kTwelveHoursInSecs = 12 * 60 * 60;
    
    QList<QVariantMap> series;
    
    if (m_db.isOpen()) {
        
        QSqlQuery query(m_db);
        query.exec(QString("SELECT Series.seriesName, Series.network, Series.airsTime, Series.airsDayOfWeek, Series.status, Series.id, Episode.id, Episode.episodeName, Episode.episodeNumber, Episode.seasonNumber, Episode.firstAired, Episode.filename, Episode.overview, Episode.guestStars, Episode.writer, Episode.watched "
                           "FROM Series, Episode "
                           "WHERE Series.status = '%1' AND Episode.firstAired BETWEEN '%2' AND '%3' AND Series.id = Episode.seriesID AND Episode.seasonNumber != 0 "
                           "ORDER BY Episode.firstAired;").arg(status).arg(firstAiredStart).arg(firstAiredEnd));
        
        if (query.isSelect()) {
            
            while (query.next()) {
                
                QVariantMap temp;
                
                auto seriesName = query.value(0).toString();
                temp["seriesName"] = seriesName;
                
                auto network = query.value(1).toString();
                temp["network"] = network;
                
                auto airsTime = query.value(2).toString();
                QTime time;

                if (airsTime.contains("PM")) {
                    airsTime.resize(airsTime.indexOf("PM") - 1);
                    time = QTime::fromString(airsTime, "h:m").addSecs(kTwelveHoursInSecs);
                } else {
                    time = QTime::fromString(airsTime, "h:m");
                }
                
                temp["airsTime"] = time.toString("h:mm");
                
                auto airsDayOfWeek = query.value(3).toString();
                temp["airsDayOfWeek"] = airsDayOfWeek;
                
                auto status = query.value(4).toString();
                temp["status"] = status;
                
                auto id = query.value(5).toString();
                temp["id"] = id;
                
                auto episodeId = query.value(6).toString();
                temp["nextEpisodeId"] = episodeId;
                
                auto episodeName = query.value(7).toString();
                episodeName.replace("''", "'");
                temp["nextEpisodeName"] = episodeName;
                
                auto episodeNumber = query.value(8).toString();
                temp["nextEpisodeNumber"] = episodeNumber;
                
                auto seasonNumber = query.value(9).toString();
                temp["nextEpisodeSeasonNumber"] = seasonNumber;
                
                auto firstAired = query.value(10).toString();
                temp["nextEpisodeFirstAired"] = firstAired;
                
                // Sometimes the series info airsDayOfWeek is wrong so lets take it from the episode directly then
                auto airsDayOfWeekFromEpisode = locale.toString(QDate::fromString(firstAired, Qt::ISODate), "dddd");
                temp["airsDayOfWeek"] = airsDayOfWeek == airsDayOfWeekFromEpisode ? airsDayOfWeek : airsDayOfWeekFromEpisode;
                
                auto banner = query.value(11).toString();
                temp["nextEpisodeBanner"] = banner;
                
                auto overview = query.value(12).toString();
                overview.replace("''", "'");
                temp["nextEpisodeOverview"] = overview;
                
                auto guestStars = query.value(13).toString();
                temp["nextEpisodeGuestStars"] = guestStars;
                
                auto writer = query.value(14).toString();
                temp["nextEpisodeWriter"] = writer;
                
                auto watched = query.value(15).toString();
                temp["nextEpisodeWatched"] = watched;
                
                series.append(temp);
            }
        }
    }

    return series;
}