예제 #1
0
    Date DateParser::parse(const std::string& str, const std::string& fmt) {
        std::vector<std::string> slist;
        std::vector<std::string> flist;
        Integer d=0, m=0, y=0;

        slist = split(str,'/');
        flist = split(fmt,'/');
        if (slist.size() != flist.size())
            return Null<Date>();
        Size i;
        for (i=0;i<flist.size();i++) {
            std::string sub = flist[i];
            if (boost::algorithm::to_lower_copy(sub) == "dd")
                //  d = boost::lexical_cast<Integer>(slist[i]);
                d = io::to_integer(slist[i]);
            else if (boost::algorithm::to_lower_copy(sub) == "mm")
                //     m = boost::lexical_cast<Integer>(slist[i]);
                m = io::to_integer( slist[i]);
            else if (boost::algorithm::to_lower_copy(sub) == "yyyy") {
                //     y = boost::lexical_cast<Integer>(slist[i]);
                y = io::to_integer(slist[i]);
                if (y < 100)
                    y += 2000;
            }
        }
        return Date(d,Month(m),y);
    }
예제 #2
0
파일: DBDate.C 프로젝트: rjs80/RGIS
DBFloat DBDate::DecimalMonth () const
	{
	DBFloat decDate;
	DBInt month, nDays;

	decDate  = (FlagsVAR & DBTimeStepYear)  == DBTimeStepYear  ? Year () * 12 : 0.0;
	if ((FlagsVAR & DBTimeStepMonth) != DBTimeStepMonth) return (decDate + 6.0);
	if ((FlagsVAR & DBTimeStepDay)   != DBTimeStepDay)   return (decDate + ((DBFloat) Month () + 0.5) / 12.0);
	month = Month ();
	nDays = _DBNumberOfDays [month] + ((month == 1) && DBDateIsLeapYear (Year ()) ? 1 : 0);
	if ((FlagsVAR & DBTimeStepHour)  != DBTimeStepHour)
		return (decDate + Month () + ((DBFloat) Day () / (DBFloat) nDays));
	if ((FlagsVAR & DBTimeStepMinute) != DBTimeStepMinute)
		return (decDate + ((DBFloat) Day () + Hour () / 24) / (DBDateIsLeapYear (Year ()) ? 365.0 : 366.0));
	return (decDate + ((DBFloat) Day () + (Hour () + Minute () / 60.0) / 24) / (DBDateIsLeapYear (Year ()) ? 365.0 : 366.0));
	}
예제 #3
0
Date::Date(int y, int m, int d)
{
	year = Year(((y > 0) ? y : 1));
	month = Month(m >= 1 && m <= 12 ? m : 1);
	month.setNumberOfDays(getDaysOfMonth(year.getYear(), month.getMonth()));
	day = Day(validDay(year.getYear(), month.getMonth(), d) ? d : 1);
}
예제 #4
0
// operator overloads ---------------------------
Date & Date::operator=(const Date &d)
{
	year = Year(d.year);
	month = Month(d.month);
	day = Day(d.day);
	return *this;
}
예제 #5
0
파일: DBDate.C 프로젝트: rjs80/RGIS
DBFloat DBDate::DecimalYear () const
	{
	DBFloat decDate;
	DBInt month, day;

	decDate  = (FlagsVAR & DBTimeStepYear)  == DBTimeStepYear  ? Year () : 0.0;
	if ((FlagsVAR & DBTimeStepMonth) != DBTimeStepMonth) return (decDate + 0.5);
	if ((FlagsVAR & DBTimeStepDay)   != DBTimeStepDay)   return (decDate + ((DBFloat) Month () + 0.5) / 12.0);
	day = (DBDateIsLeapYear (Year ()) && (Month () > 1)) ? 1 : 0;
	for (month = 0;month < Month ();++month) day += _DBNumberOfDays [month];
	if ((FlagsVAR & DBTimeStepHour)  != DBTimeStepHour)
		return (decDate + (DBFloat) day / (DBDateIsLeapYear (Year ()) ? 365.0 : 366.0));
	if ((FlagsVAR & DBTimeStepMinute) != DBTimeStepMinute)
		return (decDate + ((DBFloat) day + Hour () / 24) / (DBDateIsLeapYear (Year ()) ? 365.0 : 366.0));
	return (decDate + ((DBFloat) day + (Hour () + Minute () / 60.0) / 24) / (DBDateIsLeapYear (Year ()) ? 365.0 : 366.0));
	}
예제 #6
0
Date ComponentMust::eff_convert_date(std::string dateString) const
{
	// convert string type to date type
	int my_year;
	int my_month;
	int my_day;

	if (dateString.length() == 10)
	{
		my_year = boost::lexical_cast<int>(dateString.substr(1, 4));
		my_month = boost::lexical_cast<int>(dateString.substr(5, 2));
		my_day = boost::lexical_cast<int>(dateString.substr(7, 2));
	}

	if (dateString.length() == 8)
	{
		my_year = boost::lexical_cast<int>(dateString.substr(0, 4));
		my_month = boost::lexical_cast<int>(dateString.substr(4, 2));
		my_day = boost::lexical_cast<int>(dateString.substr(6, 2));
	}



	Month m = Month(my_month);
	Date date(my_day, m, my_year);
	return date; // retourne la date du format QuantLib
}
예제 #7
0
파일: part 1+2.c 프로젝트: lincomcom/C_HW2
int main()
{
    /*Part 1*/

    int StartingDay, NumofDay;

    printf("enter the starting day of week(0 = Sunday, 1 = Monday, etc): ");
    scanf("%d", &StartingDay);/*assign StartingDay*/

    printf("\nenter the number of days in the month:");
    scanf("%d", &NumofDay);/*assign Number of Day this month*/

    PrintCalender(StartingDay, NumofDay);

     /*Part 2*/
    int year, month;

    printf("\nenter the year (1753-2099): ");
    scanf("%d", &year);/*input year*/

    printf("\nenter the month (1-12):");
    scanf("%d", &month);/*input month*/

    printf("\nThe month has %d days", NumofDay=DaysofMon(year, month));/*prints the number of days in that month*/

    StartingDay=(CountDaysBefore(year)+CountDaysThisYear(year, month)+1)%7;/*(count days till this month)/7,=0:Sun*/
    printf("\nThe first day of this month is a ");/*prints the day of the week that starts that month.*/
        date(StartingDay);/*prints starting day of this month */

    printf("\n         ");
        Month(month);/*prints this month*/
            printf(" %d\n", year);/*prints this year*/
     PrintCalender(StartingDay, NumofDay);/*prints calender*/
    return 0;
}
예제 #8
0
파일: Date.cpp 프로젝트: kapyar/---
Date::Date(int d, int m, int y)
{
   fillDate(d, Month(m), y);
#ifndef NDEBUG
		cout<<"*Constructing Date without default"<<endl;
#endif
}
예제 #9
0
파일: XTime.cpp 프로젝트: hgl888/nashtest
void XTime::GetTime(XString8 &strTime)
{
	int v=GetDayOfWeek();
	strTime=WeekDay(v);
	v=GetDay();
	if(v<10)
		strTime+=",0";
	else
		strTime+=",";
	strTime+=v;
	strTime+=' ';
	strTime+=Month(GetMonth());
	strTime+=' ';
	strTime+=GetYear();
	strTime+=' ';
	if(this->GetHour()<10)
		strTime+='0';
	strTime+=GetHour();
	strTime+=':';
	if(this->GetMinute()<10)
		strTime+='0';
	strTime+=GetMinute();
	strTime+=':';
	if(this->GetSecond()<10)
		strTime+='0';
	strTime+=GetSecond();
	strTime+=" GMT";
}
예제 #10
0
/**
 * name:	Set
 * class:	MAnnivDate
 * desc:	set new date
 * param:	none
 * return:	nothing
 **/
void MAnnivDate::SetDate(const SYSTEMTIME &st)
{
	ZeroDate();
	Year(st.wYear);
	Month(st.wMonth);
	Day(st.wDay);
}
예제 #11
0
파일: Date.cpp 프로젝트: rgmabs19357/fzsvn
/*
 *  add @n months to date
 */
Date& Date::add_month(int n)
{
    if (n) {
	int   mm;
	int   yy;

	yy = n / 12;
	mm = m + n % 12;

	// left n add m great than 12
	if (mm > 12) {
	    yy++;
	    mm -= 12;
	}

	// month first
	m = Month(mm);
	if (d > month_days(m, y))
	    d = month_days(m, y);

	add_year(yy);

	cache->valid = false;
    }

    return *this;
}
예제 #12
0
    Date Date::advance(const Date& date, Integer n, TimeUnit units) {
        switch (units) {
          case Days:
            return date + n;
          case Weeks:
            return date + 7*n;
          case Months: {
            Day d = date.dayOfMonth();
            Integer m = Integer(date.month())+n;
            Year y = date.year();
            while (m > 12) {
                m -= 12;
                y += 1;
            }
            while (m < 1) {
                m += 12;
                y -= 1;
            }

            QL_ENSURE(y >= 1900 && y <= 2199,
                      "year " << y << " out of bounds. "
                      << "It must be in [1901,2199]");

            Integer length = monthLength(Month(m), isLeap(y));
            if (d > length)
                d = length;

            return Date(d, Month(m), y);
          }
          case Years: {
              Day d = date.dayOfMonth();
              Month m = date.month();
              Year y = date.year()+n;

              QL_ENSURE(y >= 1900 && y <= 2199,
                        "year " << y << " out of bounds. "
                        << "It must be in [1901,2199]");

              if (d == 29 && m == February && !isLeap(y))
                  d = 28;

              return Date(d,m,y);
          }
          default:
            QL_FAIL("undefined time units");
        }
    }
예제 #13
0
/**
 *\en
 * 	\brief Returns a aDateService object containing a date nyears later than the date of 
 * 	this object (or earlier if nyears is negative). 
 *\_en
 *\ru
 * 	\brief Возвращает объект класса aDateService содержащий дату на nyears лет позднее хранимой
 * 	в объекте даты (или ранее, если nyears меньше нуля).
 *\_ru
 */
aDateService*
aDateService::AddYears ( int nyears ) const
{
	QDate		currentDate( Year(), Month(), Day() );
	aDateService*	result = new aDateService( currentDate.addYears( nyears ) );

	return result;
}	
예제 #14
0
/**
 * name:	Compare
 * class:	MAnnivDate
 * desc:	compare the current date with the given one in st
 * param:	st	- SYSTEMTIME to compare with
 * return:	number of days the st differs from the class value
 **/
BOOLEAN MAnnivDate::IsEqual(const SYSTEMTIME &st) const
{
	return (
		Day() == st.wDay &&
		Month() == st.wMonth &&
		Year() == st.wYear
 );
}
예제 #15
0
void Date::printOn( ostream& outputStream ) const
{
    char temp[BufSize];
    ostrstream os( temp, BufSize );
    os << MonthNames[ Month() ] << " "
       << Day() << ", " << Year() << ends;
    outputStream << temp;
}
예제 #16
0
void outDate(int x)
{
    printf("%d\n",x);
    int year = 2000, month = 1, day = 1, hour = 0, minute = 0, second = 0;
    while (x >= Year(year)) x -= Year(year++);
    while (x >= Month(year, month)) x -= Month(year, month++);
    while (x >= Day(year, month, day)) x -= Day(year, month, day++);
    while (x >= 60*60) x -= 60*60, ++hour;
    while (x >= 60) x -= 60, ++minute;
    second = x;
    if (hour == 24){
        hour = 23;
        minute = 59;
        second = 60;
    }
    printf("%d.%02d.%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second);
}
Simulation::Simulation()
    : m_monthSimulated(0)
{
    // Initialise les 12 mois de l'année
    for (unsigned int i = 0 ; i < 12 ; i++)
        m_months.push_back(Month(i));

    // Population de depart (cf. Australie)
    m_youngRabbits.addYoungRabbit(24);
}
예제 #18
0
void Insert() {
    TimePass::ShmHashlist<Month> months(SHM_FILE);
    if (false == months.Open()) {
        printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str());
        return;
    }
    for (int i = 0; i < 12; ++i) {
        months.Insert(Month(t_month[i], n_month[i]));
    }
}
예제 #19
0
    Date Date::todaysDate() {
        std::time_t t;

        if (std::time(&t) == std::time_t(-1)) // -1 means time() didn't work
            return Date();
        std::tm *lt = std::localtime(&t);
        return Date(Day(lt->tm_mday),
                    Month(lt->tm_mon+1),
                    Year(lt->tm_year+1900));
    }
예제 #20
0
파일: Date.cpp 프로젝트: haroldzmli/cuboid
	bool Date::operator< (const Date & other) const
	{
		if (Year() < other.Year())
		{
			return true;
		}
		else if (Year() == other.Year())
		{
			if (Month() < other.Month())
			{
				return true;
			}
			else if (Month() == other.Month())
			{
				return Day() < other.Day();
			}
		}

		return false;
	}
예제 #21
0
/**
 * name:	DateStamp
 * class:	MAnnivDate
 * desc:	return the current date encoded as an DWORD
 * param:	nothing
 * return:	DWORD encoded date
 **/
DWORD MAnnivDate::DateStamp() const
{
	DWORD dwStamp;

	if (!IsValid()) return 0;

	dwStamp	= (Day() << 24) & 0xFF000000;
	dwStamp |= (Month() << 16) & 0x00FF0000;
	dwStamp |= Year() & 0x0000FFFF;
	return dwStamp;
}
예제 #22
0
void setLastModifDate(directory_entry* e, TANGGAL T){
	//asumsi disimpan dalam big endian
	//TODO tanyakan lagi

	uint16_t word = ((Year(T)-2000)<<9) | Month(T)<<5 | Day(T);
	
	e->bytearr[0x18] = (word&0xff00) >> 8;
	e->bytearr[0x19] = (word&0x00ff);

	return;
}
예제 #23
0
void
MonthDayRuleTest::test_lifecycle_invalid()
{
	//test: MontDayRule::MonthDayRule(const Month& month, const DayOfMonth& dayOfMonth);
	try{
		MonthDayRule rule("Rule", Month(4), DayOfMonth(31));
	}
	catch (BaseException& ex)
	{
		std::cout << "Caught expected exception (invalid month, day in month combination); details: " << ex.what() << std::endl;
	}
}
예제 #24
0
void Remove() {
    TimePass::ShmHashlist<Month> months(SHM_FILE);
    if (false == months.Open()) {
        printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str());
        return;
    }
    char name[10];
    for (int i = 0; i < len; ++i) {
        months.Remove(Month(t_month[i], n_month[i]));
        snprintf(name, sizeof(name) - 1, "%02d", i);
        ToDotPs(name, &months);
    }
}
예제 #25
0
파일: DBDate.C 프로젝트: rjs80/RGIS
DBInt DBDate::DaysAD () const
	{
	DBInt month, days = 0, i;
	DBInt year = YearsAD ();
	
	_DBSetFebruary (DBDateIsLeapYear (year));
	days += year * 365 + year / 4 - year / 100 + year / 400;

	if ((FlagsVAR & DBTimeStepMonth) == DBTimeStepMonth) month = Month () ; else month = 5;
	for (i = 0;i < month;++i) days += _DBNumberOfDays [month];
	if ((FlagsVAR & DBTimeStepDay) == DBTimeStepDay) days += Day () ; else days += 15;
	return (days); 
	}
예제 #26
0
void Find(const char* t_month) {
    TimePass::ShmHashlist<Month> months(SHM_FILE);
    if (false == months.Open()) {
        printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str());
        return;
    }
    TimePass::ListNode<Month>* p_node = months.Find(Month(t_month, 0));
    if (NULL == p_node) {
        printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str());
        return;
    } else {
        printf("%s-%d\n", p_node->data.t_month, p_node->data.n_month);
    }
}
예제 #27
0
파일: XTime.cpp 프로젝트: hgl888/nashtest
XBOOL XTime::SetTime(XString8 &strTime)
{
	//int id=strTime.Find(',');
	//if(id<3) return XFALSE;
	XU32 is=0,id=0;
	XU16 nYear=0,nMon=0,nDay=0,nHour=0,nMin=0,nSec=0;
	while(id<=strTime.GetLength())
	{
		if(strTime[id]==' '||strTime[id]==','||strTime[id]=='-'||strTime[id]==0)
		{
			if(id>is+1)
			{
				XString8 str;
				strTime.Mid(str,is,id-is);
				XString8Array list;
				list.SplitString(str,':');
				if(list.GetSize()>1)
				{
					nHour=list[0].ToInt();
					nMin=list[1].ToInt();
					if(list.GetSize()>2)
						nSec=list[2].ToInt();
				}
				else 
				{
					int id=Month(str);
					if(id>0&&id<=12&&nMin<1) nMon=id;
					else 
					{
						id=str.ToInt();
						if(id>0&&id<32&&nDay<1) nDay=id;
						else if(id>=1900) nYear=id;
						else nHour=id;
					}
				}
			}
			id++;
			is=id;
		}
		id++;
	}
	if(nYear<1900||nMon<1||nDay<1) return XFALSE;
	SetTime(nYear,nMon,nDay,nHour,nMin,nSec);
	return XTRUE;
}
예제 #28
0
파일: DBDate.C 프로젝트: rjs80/RGIS
char *DBDate::Get () const

	{
	static char dateStr [DBStringLength];

	if ((FlagsVAR & DBTimeStepYear) == DBTimeStepYear)
			sprintf (dateStr,"%04d",Year ());
	else	sprintf (dateStr,"XXXX");
	if ((FlagsVAR & DBTimeStepMonth) == DBTimeStepMonth)
		sprintf (dateStr + strlen (dateStr),"-%02d",Month () + 1);
	if ((FlagsVAR & DBTimeStepDay) == DBTimeStepDay)
		sprintf (dateStr + strlen (dateStr),"-%02d",Day () + 1);
	if ((FlagsVAR & DBTimeStepHour) == DBTimeStepHour)
		sprintf (dateStr + strlen (dateStr)," %02d",Hour ());
	if ((FlagsVAR & DBTimeStepMinute) == DBTimeStepMinute)
		sprintf (dateStr + strlen (dateStr),":%02d",Minute ());
	return (dateStr);
	}
예제 #29
0
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 (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 = Month(in_month);
        day = in_day;
    } else {
        in.setstate(std::ios::failbit | in.rdstate());
    }
}
예제 #30
0
파일: iTime.cpp 프로젝트: corburn/ISIS
  /**
   * Returns the internally stored time, formatted as a UTC time
   *
   * @return string The internalized time, in UTC format
   */
  QString iTime::UTC() const {
    QString utc = YearString() + "-" ;
    if(Month() < 10) utc += "0" + MonthString() + "-";
    else utc += MonthString() + "-";

    if(Day() < 10) utc += "0" + DayString() + "T";
    else utc += DayString() + "T";

    if(Hour() < 10) utc += "0" + HourString() + ":";
    else utc += HourString() + ":";

    if(Minute() < 10) utc += "0" + MinuteString() + ":";
    else utc += MinuteString() + ":";

    if(Second() < 10) utc += "0" + SecondString();
    else utc += SecondString();

    return utc;
  }