本文整理汇总了C++中date类的典型用法代码示例。如果您正苦于以下问题:C++ date类的具体用法?C++ date怎么用?C++ date使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
date dateUtil::dayRollAdjust(date aDate,DayRollEnum aDayRollConvention, enums::CurrencyEnum market) {
long adjustedJDN;
switch(aDayRollConvention){
case enums::Following:
adjustedJDN = getFolloingJDN(aDate, market);
break;
case enums::Preceding:
adjustedJDN = getPrecedingJDN(aDate, market);
break;
case enums::Mfollowing:
adjustedJDN = getFolloingJDN(aDate, market);
if (getYearMonthDay(adjustedJDN)[1]!=aDate.getMonth())
adjustedJDN = getPrecedingJDN(aDate, market);
break;
case enums::Mfollowingbi:
adjustedJDN = getFolloingJDN(aDate, market);
if (getYearMonthDay(adjustedJDN)[1]!=aDate.getMonth()||
getYearMonthDay(adjustedJDN)[2]>=15)
adjustedJDN = getPrecedingJDN(aDate, market);
break;
case enums::EOM:
break;
case enums::DayRollNull:
adjustedJDN = aDate.getJudianDayNumber();
break;
}
date adjustedDate(adjustedJDN);
return adjustedDate;
}
示例2: to_tm
//! Converts a date to a tm struct. Throws out_of_range exception if date is a special value
inline
std::tm to_tm(const date& d)
{
if (d.is_special())
{
std::string s = "tm unable to handle ";
switch (d.as_special())
{
case date_time::not_a_date_time:
s += "not-a-date-time value";
break;
case date_time::neg_infin:
s += "-infinity date value";
break;
case date_time::pos_infin:
s += "+infinity date value";
break;
default:
s += "a special date value";
break;
}
boost::throw_exception(std::out_of_range(s));
}
std::tm datetm;
std::memset(&datetm, 0, sizeof(datetm));
boost::gregorian::date::ymd_type ymd = d.year_month_day();
datetm.tm_year = ymd.year - 1900;
datetm.tm_mon = ymd.month - 1;
datetm.tm_mday = ymd.day;
datetm.tm_wday = d.day_of_week();
datetm.tm_yday = d.day_of_year() - 1;
datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst
return datetm;
}
示例3: json_object_new_object
int stat_file_manager::merge(date time){
std::vector<stat_file>::iterator it = stat_files.begin();
json_object* jobj = json_object_new_object();
bool update = false;
while(it != stat_files.end()){
if(time.is_child(it->get_date())){
json_object* jelement = it->get_jobj();
if(jelement != NULL){
json_object_object_add(jobj, it->get_filename().c_str(), jelement);
#ifdef DEBUG
std::cout << "remove(): " << it->get_filename() << std::endl;
#endif
it->remove();
update = true;
}
}
it++;
}
if(update == false){
return -1;
}
json_merge(jobj);
#ifdef DEBUG
std::cout << "write(): " << time.get_stime() << std::endl;
#endif
write(time.get_stime(), jobj);
return 0;
}
示例4: day
void
date::_copy_members (const date& other)
{
day (other.day());
month (other.month());
year (other.year());
}
示例5: endDate
date dateUtil::getEndDateMonthIncrement(date startDate, int numMonth){
if (numMonth==0) return startDate;
short startMonth = startDate.getMonth();
short endMonth = (startMonth + numMonth)%12;
int yearIncrement = (startMonth + numMonth)/12;
yearIncrement = (startMonth + numMonth)<=0?yearIncrement-1:yearIncrement;
endMonth = endMonth<=0?endMonth+12:endMonth;
short endYear= startDate.getYear()+yearIncrement;
date endDate(endYear, endMonth, startDate.getDay());
return endDate;
}
示例6: julian_date
void object_serializer::serialize(const char *id, date &x)
{
if (restore) {
int julian_date(0);
buffer_->release(&julian_date, sizeof(julian_date));
x.set(julian_date);
} else {
int jd(x.julian_date());
serialize(id, jd);
}
}
示例7: sequential_date
bool sequential_date(date current_date, date next_date)
{
if (current_date.day_of_week().as_enum() == Monday)
return next_date.day_of_week().as_enum() == Tuesday;
if (current_date.day_of_week().as_enum() == Tuesday)
return next_date.day_of_week().as_enum() == Wednesday;
if (current_date.day_of_week().as_enum() == Wednesday)
return next_date.day_of_week().as_enum() == Thursday;
if (current_date.day_of_week().as_enum() == Thursday)
return next_date.day_of_week().as_enum() == Friday;
if (current_date.day_of_week().as_enum() == Friday)
return next_date.day_of_week().as_enum() == Monday;
return true;
}
示例8: assert
void FoxPro::setDate(size_t record, size_t field, const date &value) {
assert((record < _records.size()) && (field < _fields.size()));
Record &r = _records[record];
Field &f = _fields[field];
if (f.type != kTypeDate)
throw Exception("Field is not of date type ('%c')", f.type);
char *data = (char *) r.fields[field];
snprintf(data, 8, "%04d%02d%02d",
(int) value.year(), (int) value.month(), (int) value.day());
updateUpdate();
}
示例9: inferieur_a
bool date::inferieur_a (const date & d) const
{
bool resultat = true;
if (annee () > d.annee ())
resultat = false;
else if (annee () == d.annee ())
{
if (mois () > d.mois ())
resultat = false;
else if (mois () == d.mois ())
resultat = jour () < d.jour ();
}
return resultat;
}
示例10: quote
std::unique_ptr<quoteVector_t>
YahooFDS::get_historical_prices(const std::string &symbol,
date &start,
date &end)
{
//quoteVector_t *quotes = new quoteVector_t;
auto quotes = new quoteVector_t;
auto start_d = start.year_month_day();
auto end_d = end.year_month_day();
std::vector<std::string> quoteStrings;
std::ostringstream url;
url << "http://ichart.yahoo.com/table.csv?s=" << symbol << "&d=" \
<< end_d.month - 1 << "&e=" \
<< end_d.day << "&f=" \
<< end_d.year << "&a=" \
<< start_d.month - 1 << "&b=" \
<< start_d.day << "&c=" \
<< start_d.year << "&ignore=.csv";
// split the response into lines
boost:split(quoteStrings, (const std::string &)request(url.str()), boost::is_any_of("\n"),boost::token_compress_on);
// Remove header line
quoteStrings.erase(quoteStrings.begin());
for (auto it = quoteStrings.rbegin(); it < quoteStrings.rend(); ++it)
{
// Ensure we have a valid quote here. 38 is presumably the shortest possible quote. 35 is magic as fuck (MAF).
if ((*it).length() > 35)
{
std::vector<std::string> temp;
boost::split(temp, *it, boost::is_any_of(", "));
HistoricalQuote quote(symbol,
temp.at(0),
atof(temp.at(1).c_str()),
atof(temp.at(2).c_str()),
atof(temp.at(3).c_str()),
atof(temp.at(4).c_str()),
atol(temp.at(5).c_str()),
atof(temp.at(6).c_str()));
// Make it rain!
quotes->push_back(quote);
}
}
return std::unique_ptr<quoteVector_t>(std::move(quotes));
}
示例11: getFolloingJDN
long dateUtil::getFolloingJDN(date refDate, enums::CurrencyEnum market){
//date adjustedDate = adjustInvalidateDate(refDate,true);
long JDN = refDate.getJudianDayNumber();
while(!isBizDay(JDN) || isHoliday(JDN,market)){
JDN++;
}
return JDN;
}
示例12: getPrecedingJDN
long dateUtil::getPrecedingJDN(date refDate, enums::MarketEnum market){
//date adjustedDate = adjustInvalidateDate(refDate,false);
long JDN = refDate.getJudianDayNumber();
while(!isBizDay(JDN) || isHoliday(JDN,market)){
JDN--;
}
return JDN;
}
示例13: adjustInvalidateDate
date dateUtil::adjustInvalidateDate(date aDate, bool forwardAdjust){
unsigned short monthlen[]={31,28,31,30,31,30,31,31,30,31,30,31};
if (isleapyear(aDate.getYear()) && aDate.getMonth()==2)
monthlen[1]++;
if (aDate.getDay()>monthlen[aDate.getMonth()-1]){
if (forwardAdjust){
aDate.setMonth(aDate.getMonth()%12+1);
aDate.setDay(1);
}
else
aDate.setDay(monthlen[aDate.getMonth()-1]);
}
return aDate;
}
示例14: abs
date dateUtil::getEndDateMonthIncrement(date startDate, int numMonth){
if (numMonth==0) return startDate;
short startMonth = startDate.getMonth();
short endMonth = (startMonth + numMonth);
bool isEndMonthPow12 = (startMonth + numMonth)%12==0?true:false;
endMonth = isEndMonthPow12 ? 12 : (startMonth + numMonth)%12;
int yearIncrement = abs((startMonth + numMonth)/12) - (isEndMonthPow12 ? 1 : 0);
if (startMonth + numMonth<0)
yearIncrement = -abs((startMonth + numMonth)/12) - 1 - (isEndMonthPow12 ? 1 : 0);
endMonth = endMonth<=0 ? endMonth+12 : endMonth;
short endYear= startDate.getYear()+ yearIncrement;
date endDate(endYear, endMonth, startDate.getDay());
// Adjust the return day to the end of month if the start date is also end of month
//if (startDate.getDay() == getMonthLastDay(startDate.getYear(), startDate.getMonth()))
//endDate.setDay(getMonthLastDay(endDate.getYear(), endDate.getMonth()));
return endDate;
}
示例15: b
date date::backDate(date a,int in)
{
int adays,amonth,ayear;
adays=a.getDay();
amonth=a.getMonth();
ayear=a.getYear();
adays=adays+in;
if(adays>30)
{amonth++; adays+=-30;}
if(amonth>12)
{
ayear++;
amonth-=30;
}
date b(adays,amonth,ayear);
return b;
}