本文整理汇总了C++中Date函数的典型用法代码示例。如果您正苦于以下问题:C++ Date函数的具体用法?C++ Date怎么用?C++ Date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Date
Date Date::Minutes(int n) {
return Date(n * gsSecsPerMinute, true);
}
示例2: Date
Date Date::startOfYear () const
{
return Date (1, 1, year (), 0, 0, 0);
}
示例3: keyf
void MyDayInfoPlot::DrawPricePlot(wxDC&dc){
TotalDayInfoStru MyDays[TOTAY_DAYS_MYDAYINFO];
double MaxSz,MinSz,MaxSh,MinSh,MaxTotal,MinTotal,MaxDelta,MinDelta;
MaxSz=MinSz=MaxSh=MinSh=MaxTotal=MinTotal=MaxDelta=MinDelta=0;
for (int tidx=0;tidx<TOTAY_DAYS_MYDAYINFO;tidx++){
MyDays[tidx].Valid=false;
}
wxString keyPath=WStockConfig::GetMyDayInfoPath();
wxFileName keyf(keyPath);
keyf.MakeAbsolute();
xmlDocPtr doc=NULL;
if (keyf.FileExists()){
//Load Stocks Name From file
doc = xmlParseFile((const char*)keyf.GetFullPath().mb_str());
}
//If Load Fail, Create the Xml Memory
if (doc==NULL){
dc.DrawText(_("No Info File Found!"),10,10);
return;
}
for (xmlNodePtr node=doc->children->children;node;node=node->next){
if (xmlStrcmp(node->name,(const xmlChar*)"DayInfo")==0){
wxString Date(wxConvUTF8.cMB2WC(
(char*)xmlGetProp(node, (const xmlChar*)"Date")),*wxConvCurrent);
wxString Sz(wxConvUTF8.cMB2WC(
(char*)xmlGetProp(node, (const xmlChar*)"ShenZhen")),*wxConvCurrent);
wxString Sh(wxConvUTF8.cMB2WC(
(char*)xmlGetProp(node, (const xmlChar*)"ShangHai")),*wxConvCurrent);
wxString Total(wxConvUTF8.cMB2WC(
(char*)xmlGetProp(node, (const xmlChar*)"Total")),*wxConvCurrent);
wxString Delta(wxConvUTF8.cMB2WC(
(char*)xmlGetProp(node, (const xmlChar*)"TodayEarning")),*wxConvCurrent);
wxDateTime date;
date.ParseDate(Date);
int idx=(wxDateTime::Today()-date).GetDays();
if (idx<TOTAY_DAYS_MYDAYINFO){
Sz.ToDouble(&MyDays[idx].sz);
Sh.ToDouble(&MyDays[idx].sh);
Total.ToDouble(&MyDays[idx].total);
Delta.ToDouble(&MyDays[idx].delta);
MyDays[idx].Valid = true;
MyDays[idx].date = date;
}
}
}
int i;
for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){
if (MyDays[i].Valid){
if (MyDays[i].sz>MaxSz) MaxSz = MyDays[i].sz;
if (MyDays[i].sz<MinSz) MinSz = MyDays[i].sz;
if (MyDays[i].sh>MaxSh) MaxSh = MyDays[i].sh;
if (MyDays[i].sh<MinSh) MinSh = MyDays[i].sh;
if (MyDays[i].total>MaxTotal) MaxTotal = MyDays[i].total;
if (MyDays[i].total<MinTotal) MinTotal = MyDays[i].total;
if (MyDays[i].delta>MaxDelta) MaxDelta = MyDays[i].delta;
if (MyDays[i].delta<MinDelta) MinDelta = MyDays[i].delta;
}
}
dc.SetPen(wxPen(*wxBLACK,3));
int XStart=100,YStart=10,YFree=60;
int TotalY=dc.GetSize().y-30-YFree;
int XTotal = dc.GetSize().x-110;
float TotalDelta=0;
if (MinDelta<0) TotalDelta = MaxTotal - MinDelta+YFree;
else TotalDelta = MaxTotal+YFree;
if (TotalDelta<0.0003) TotalDelta = 1;
int ZeroY = (int)(double)(TotalY/TotalDelta * MaxTotal + YStart);
dc.DrawLine(XStart,YStart,XStart,YStart + TotalY + YFree);
dc.DrawLine(XStart-10,ZeroY,XStart+XTotal,ZeroY);
for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){
if (MyDays[i].Valid){
int MyTotalY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].total);
int MyDeltaY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].delta);
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyTotalY,10,Abs(ZeroY-MyTotalY));
dc.SetBrush(*wxGREEN_BRUSH);
dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyDeltaY,10,Abs(ZeroY-MyDeltaY));
//wxLogMessage(wxT("Draw Rect at:%d %d %d %d"),(int)(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5),
//MyDeltaY,10,Abs(ZeroY-MyDeltaY));
dc.DrawText(MyDays[i].date.FormatISODate(),XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1))-30,YStart+TotalY);
}
}
}
示例4: sow
Date Date::startOfWeek () const
{
Date sow (_t);
sow -= (dayOfWeek () * 86400);
return Date (sow.month (), sow.day (), sow.year (), 0, 0, 0);
}
示例5: Date
MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
settlementDays_ = settlementDays;
effectiveDate_ = Date();
return *this;
}
示例6: Date
Time ActualActual::ISMA_Impl::yearFraction(const Date& d1,
const Date& d2,
const Date& d3,
const Date& d4) const {
if (d1 == d2)
return 0.0;
if (d1 > d2)
return -yearFraction(d2,d1,d3,d4);
// when the reference period is not specified, try taking
// it equal to (d1,d2)
Date refPeriodStart = (d3 != Date() ? d3 : d1);
Date refPeriodEnd = (d4 != Date() ? d4 : d2);
QL_REQUIRE(refPeriodEnd > refPeriodStart && refPeriodEnd > d1,
"invalid reference period: "
<< "date 1: " << d1
<< ", date 2: " << d2
<< ", reference period start: " << refPeriodStart
<< ", reference period end: " << refPeriodEnd);
// estimate roughly the length in months of a period
Integer months =
Integer(0.5+12*Real(refPeriodEnd-refPeriodStart)/365);
// for short periods...
if (months == 0) {
// ...take the reference period as 1 year from d1
refPeriodStart = d1;
refPeriodEnd = d1 + 1*Years;
months = 12;
}
Time period = Real(months)/12.0;
if (d2 <= refPeriodEnd) {
// here refPeriodEnd is a future (notional?) payment date
if (d1 >= refPeriodStart) {
// here refPeriodStart is the last (maybe notional)
// payment date.
// refPeriodStart <= d1 <= d2 <= refPeriodEnd
// [maybe the equality should be enforced, since
// refPeriodStart < d1 <= d2 < refPeriodEnd
// could give wrong results] ???
return period*Real(dayCount(d1,d2)) /
dayCount(refPeriodStart,refPeriodEnd);
} else {
// here refPeriodStart is the next (maybe notional)
// payment date and refPeriodEnd is the second next
// (maybe notional) payment date.
// d1 < refPeriodStart < refPeriodEnd
// AND d2 <= refPeriodEnd
// this case is long first coupon
// the last notional payment date
Date previousRef = refPeriodStart - months*Months;
if (d2 > refPeriodStart)
return yearFraction(d1, refPeriodStart, previousRef,
refPeriodStart) +
yearFraction(refPeriodStart, d2, refPeriodStart,
refPeriodEnd);
else
return yearFraction(d1,d2,previousRef,refPeriodStart);
}
} else {
// here refPeriodEnd is the last (notional?) payment date
// d1 < refPeriodEnd < d2 AND refPeriodStart < refPeriodEnd
QL_REQUIRE(refPeriodStart<=d1,
"invalid dates: "
"d1 < refPeriodStart < refPeriodEnd < d2");
// now it is: refPeriodStart <= d1 < refPeriodEnd < d2
// the part from d1 to refPeriodEnd
Time sum = yearFraction(d1, refPeriodEnd,
refPeriodStart, refPeriodEnd);
// the part from refPeriodEnd to d2
// count how many regular periods are in [refPeriodEnd, d2],
// then add the remaining time
Integer i=0;
Date newRefStart, newRefEnd;
for (;;) {
newRefStart = refPeriodEnd + (months*i)*Months;
newRefEnd = refPeriodEnd + (months*(i+1))*Months;
if (d2 < newRefEnd) {
break;
} else {
sum += period;
i++;
}
}
sum += yearFraction(newRefStart,d2,newRefStart,newRefEnd);
return sum;
}
}
示例7: Date
void FenetreProgrammerActivite::enregistrer(){
programmation& progact = agenda::getInstance().ajouterProgrammationActivite(activite, Date(ProgDate->date().day(),ProgDate->date().month(),ProgDate->date().year()),Horaire(ProgHh->value(), ProgHm->value()));
if(&progact!=0){
QMessageBox msgBox;
msgBox.setText("L'Activité a été programmée");
msgBox.exec();
this->close();
}
else
{
delete &progact;
QMessageBox msgBox;
msgBox.setText("L'Activité n'a pas été programmée");
msgBox.exec();
}
}
示例8: main
int main()
{
try
{
odb::session s; // this keeps shared pointers consistent after reloading them from the db (turns on object cache)
std::unique_ptr<odb::database> db( new Database( "Branch_removeEmployee.test.db", true ) );
// a set storing all employees we want to add
std::unordered_set< std::shared_ptr<Employee> > employees;
employees.insert( std::shared_ptr<Employee>( new Employee( "A", Date(1,1,1967) ) ) );
employees.insert( std::shared_ptr<Employee>( new Employee( "B", Date(2,1,1968) ) ) );
employees.insert( std::shared_ptr<Employee>( new Employee( "C", Date(3,1,1969) ) ) );
// we will add all employees to one branch
std::shared_ptr<Branch> b( new Branch( "Main", Address() ) );
for( const std::shared_ptr<Employee> & e : employees )
assert( b->addEmployee( e ) );
// for accessing the stored branch by id
std::string branch_id;
// store branch and employees
{
odb::transaction t( db->begin() );
for( const std::shared_ptr<Employee> & e : employees )
{
db->persist( e );
std::cout << "Stored " << e->getName() << "\n";
}
branch_id = db->persist( b );
t.commit();
}
// remove an employee from the stored branch one after the other
for( auto i = employees.begin(); i != employees.end(); )
{
// retrieve the stored branch and remove an employee
{
odb::transaction t( db->begin() );
std::shared_ptr<Branch> b( db->load<Branch>( branch_id ) );
for( const odb::lazy_weak_ptr<Employee> & le : b->getEmployees() )
{
std::cout << "Still persistent: " << le.object_id() << "\n";
}
assert( (*i)->getBranch() == b ); // should be connected to branch
// remove employee
assert( b->removeEmployee( (*i) ) );
assert( b->getEmployees().size() == employees.size()-1 ); // should be removed locally
assert( (*i)->getBranch() == nullptr ); // should not be connected to any branch anymore
// remove second time (should fail)
assert( !b->removeEmployee( (*i) ) ); // should not be able to remove twice
assert( b->getEmployees().size() == employees.size()-1 ); // should stay the same
assert( (*i)->getBranch() == nullptr ); // should still not be connected to any branch
db->update( b );
t.commit();
}
// reload person from database and check if employee got removed
{
odb::transaction t( db->begin() );
std::shared_ptr<Branch> b( db->load<Branch>( branch_id ) );
assert( b->getEmployees().size() == employees.size()-1 ); // should be removed in database too
t.commit();
}
std::cout << "Deleting: " << (*i) << " - " << (*i)->getName() << "\n";
i = employees.erase( i );
}
}
catch( const odb::exception & e )
{
std::cerr << "Exception: " << e.what() << std::endl;
std::exit( EXIT_FAILURE );
}
return 0;
}
示例9: Date
bool CDate::EncodeDate(
const CString& DateString,
const CString& DateFormat,
struct tm& Result) {
CString Date(DateString);
static const char * Months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
static const char * WeekDays[] = {"Sun", "Mon","Tue","Wed","Thu","Fri","Sat"};
static const char * Zones[] = {"UTC", "GMT", "EDT", "EST", "CDT", "CST", "MDT", "MST", "PDT", "PST"};
static const int ZonesHoursSkew[] = {0, 0, 4, 5, 5, 6, 6, 7, 7, 8};
CString WeekDay;
CString Month;
CString Zone;
Date.Replace('-', ' ');
memset(&Result, 0, sizeof(Result));
bool fScan =
SSScan(
Date,
&DateFormat,
&WeekDay,
NULL,
&Result.tm_mday,
&Month,
&Result.tm_year,
&Result.tm_hour,
NULL,
&Result.tm_min,
NULL,
&Result.tm_sec,
&Zone);
Trace(tagDateTime, levVerbose,
("CDate:: EncodeDate - scanned %s with " \
"WeekDay: %s " \
"Day: %d " \
"Month: %s " \
"Year: %d " \
"Hour: %d " \
"Minute: %d " \
"Second: %d " \
"Zone: %s",
Date.GetBuffer(),
WeekDay.GetBuffer(),
Result.tm_mday,
Month.GetBuffer(),
Result.tm_year,
Result.tm_hour,
Result.tm_min,
Result.tm_sec,
Zone.GetBuffer()));
if (fScan) {
int i;
if (Result.tm_year > 1900)
Result.tm_year-=1900;
for (i = 0; i < BASE_DIM(Months); i++) {
if (Month.Same(Months[i])) {
Result.tm_mon = i;
break;
}
}
for (i = 0; i < BASE_DIM(WeekDays); i++) {
// support full weekdays as well
if (WeekDay.StartsWithSame(WeekDays[i])) {
Result.tm_wday = i;
break;
}
}
// time zone adjustments
int ZoneAdjustment = 0;
if (Zone.IsInt( & ZoneAdjustment)) {
ZoneAdjustment *= 3600;
} else {
for (i = 0; i < BASE_DIM(Zones); i++) {
if (Zone.Same(Zones[i])) {
ZoneAdjustment = ZonesHoursSkew[i] * 3600;
break;
}
}
}
Trace(tagDateTime, levVerbose, ("CDate:: EncodeSimpleDate - ZoneAdjustment %d second(s)", ZoneAdjustment));
Result.tm_isdst = 0;
if (ZoneAdjustment) {
time_t AdjustedTime;
#ifdef _UNIX
base_gmtime(AdjustedTime, Result);
//.........这里部分代码省略.........
示例10: SmileSection
NoArbSabrSmileSection::NoArbSabrSmileSection(
const Date &d, Rate forward, const std::vector<Real> &sabrParams,
const DayCounter &dc, Real shift)
: SmileSection(d, dc, Date()), forward_(forward), params_(sabrParams), shift_(shift) {
init();
}
示例11: Date
Date Grader07::getDueDate()
{
return Date(12, 5, 2013);
}
示例12: m_startDate
/// constructor with year
Calendar::Calendar(int year)
: m_startDate(Date(MonthOfYear::Jan, 1, year)), m_endDate(Date(MonthOfYear::Dec, 31, year))
{}
示例13: year
void
MonthDayRuleTest::test_utilities()
{
int yearIndex;
SetDate date;
Year year ( DateUtil::year());
Date newYearDate (year, Month(1), DayOfMonth(1));
Date july4Date (year, Month(7), DayOfMonth(4));
Date christmasDate(year, Month(12), DayOfMonth(25));
//test: MontDayRule::virtual Date calcDate(const Year& year) const ;
MonthDayRule newYearRule ("Rule", Month(1), DayOfMonth(1));
date = newYearRule.calcDate(year);
CPPUNIT_ASSERT(newYearDate == *date.begin());
for (yearIndex = year.getValue(); yearIndex <= year.getValue() + 50; ++yearIndex){
date = newYearRule.calcDate(Year(yearIndex));
CPPUNIT_ASSERT(newYearDate == *date.begin());
newYearDate.addYear(1);
}
MonthDayRule july4Rule ("July4Rule", Month(7), DayOfMonth(4));
date = july4Rule.calcDate(year);
CPPUNIT_ASSERT(july4Date == *date.begin());
MonthDayRule christmasRule("ChristmasRule", Month(12), DayOfMonth(25));
date = christmasRule.calcDate(year);
CPPUNIT_ASSERT(christmasDate == *date.begin());
//Test for weekendAdjustment
WeekendRuleSharedPtr weekendRulePtr(new WeekendRule("WeekendRule"));
weekendRulePtr->addDay(WeekDay::Saturday);
weekendRulePtr->addDay(WeekDay::Sunday);
MonthDayRule adjustingNewYearRule ("AdjustingNewYear", Month(1), DayOfMonth(1));
adjustingNewYearRule.setStartEffectiveDate(20110101);
adjustingNewYearRule.setWeekendAdjustment(WeekendAdjustment::ClosestWeekDay);
adjustingNewYearRule.setWeekendRule(weekendRulePtr);
//First check for Saturday -> prior Friday
date = adjustingNewYearRule.calcDate(Year(2011));
CPPUNIT_ASSERT(Date(20101231) == *date.begin());
//First check for Sunday -> next Monday
date = adjustingNewYearRule.calcDate(Year(2012));
CPPUNIT_ASSERT(Date(20120102) == *date.begin());
//Check for no adjustment is required
date = adjustingNewYearRule.calcDate(Year(2013));
CPPUNIT_ASSERT(Date(20130101) == *date.begin());
//Rule is disabled
try{
newYearRule.setEnabledFlag(false);
newYearRule.calcDate(year);
}
catch (BaseException& ex){
CAUGHT_EXCEPTION(ex,"Calculation called on disabled rule");
}
newYearRule.setEnabledFlag(true);
//Rule start date year > calc year
try{
newYearRule.calcDate(Year(2010));
}
catch (BaseException& ex){
CAUGHT_EXCEPTION(ex,"Calculation called for year before rule is in effect");
}
//Rule calc year > rule end date year
try{
newYearRule.setEndEffectiveDate(20121231);
newYearRule.calcDate(Year(2030));
}
catch (BaseException& ex){
CAUGHT_EXCEPTION(ex,"Calculation called for year after rule is in effect");
}
}
示例14: Copy
void CValue::SetDate(CString s)
{
Copy(Date(s));
}
示例15: cmsSchedule
MakeCms::operator boost::shared_ptr<Swap>() const {
Date startDate;
if (effectiveDate_ != Date())
startDate = effectiveDate_;
else {
Natural fixingDays = iborIndex_->fixingDays();
Date referenceDate = Settings::instance().evaluationDate();
Date spotDate = floatCalendar_.advance(referenceDate,
fixingDays*Days);
startDate = spotDate+forwardStart_;
}
Date terminationDate = startDate+swapTenor_;
Schedule cmsSchedule(startDate, terminationDate,
cmsTenor_, cmsCalendar_,
cmsConvention_,
cmsTerminationDateConvention_,
cmsRule_, cmsEndOfMonth_,
cmsFirstDate_, cmsNextToLastDate_);
Schedule floatSchedule(startDate, terminationDate,
floatTenor_, floatCalendar_,
floatConvention_,
floatTerminationDateConvention_,
floatRule_ , floatEndOfMonth_,
floatFirstDate_, floatNextToLastDate_);
Leg cmsLeg = CmsLeg(cmsSchedule, swapIndex_)
.withNotionals(nominal_)
.withPaymentDayCounter(cmsDayCount_)
.withPaymentAdjustment(cmsConvention_)
.withFixingDays(swapIndex_->fixingDays())
.withGearings(cmsGearing_)
.withSpreads(cmsSpread_)
.withCaps(cmsCap_)
.withFloors(cmsFloor_);
if (couponPricer_)
setCouponPricer(cmsLeg, couponPricer_);
Rate usedSpread = iborSpread_;
if (useAtmSpread_) {
QL_REQUIRE(!iborIndex_->forwardingTermStructure().empty(),
"null term structure set to this instance of " <<
iborIndex_->name());
QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(),
"null term structure set to this instance of " <<
swapIndex_->name());
QL_REQUIRE(couponPricer_,
"no CmsCouponPricer set (yet)");
Leg floatLeg = IborLeg(floatSchedule, iborIndex_)
.withNotionals(nominal_)
.withPaymentDayCounter(floatDayCount_)
.withPaymentAdjustment(floatConvention_)
.withFixingDays(iborIndex_->fixingDays());
Swap temp(cmsLeg, floatLeg);
temp.setPricingEngine(engine_);
Real npv = temp.legNPV(0)+temp.legNPV(1);
usedSpread = -npv/temp.legBPS(1)*1e-4;
} else {
QL_REQUIRE(usedSpread != Null<Spread>(),
"null spread set");
}
Leg floatLeg = IborLeg(floatSchedule, iborIndex_)
.withNotionals(nominal_)
.withPaymentDayCounter(floatDayCount_)
.withPaymentAdjustment(floatConvention_)
.withFixingDays(iborIndex_->fixingDays())
.withSpreads(usedSpread);
boost::shared_ptr<Swap> swap;
if (payCms_)
swap = boost::shared_ptr<Swap>(new Swap(cmsLeg, floatLeg));
else
swap = boost::shared_ptr<Swap>(new Swap(floatLeg, cmsLeg));
swap->setPricingEngine(engine_);
return swap;
}