int CTimeDate::DaysSince1AD (void) const // DaysSince1AD // // Returns the number of days elapsed since Jan 1, 1 AD. { int iDays = 0; // Add all years before this one iDays += 365 * (Year() - 1); iDays += (Year() - 1) / 4; iDays -= (Year() - 1) / 100; iDays += (Year() - 1) / 400; // Now add the day months for this year if (timeIsLeapYear(Year())) iDays += g_DaysOfLeapYearByMonth[Month()-1]; else iDays += g_DaysOfYearByMonth[Month()-1]; iDays += Day()-1; return iDays; }
/** * name: Set * class: MAnnivDate * desc: set new date * param: none * return: nothing **/ VOID MAnnivDate::SetDate(SYSTEMTIME &st) { ZeroDate(); Year(st.wYear); Month(st.wMonth); Day(st.wDay); }
/** *\en * \brief Returns the number of days from this date to target (which is negative * if target is earlier than this date). *\_en * \brief Возвращает количество дней до указанной даты от даты, представленной объектом. * * Возвращаемое значение может быть отрицательным, если указанная дата находится в прошлом по * отношению к дате, представленной объектом. *\_ru */ int aDateService::DaysTo ( const aDateService& target ) const { QDate currentDate( Year(), Month(), Day() ); QDate targetDate( target.Year(), target.Month(), target.Day() ); return currentDate.daysTo( targetDate ) ; }
void outDate(int 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); }
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)); }
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)); }
// operator overloads --------------------------- Date & Date::operator=(const Date &d) { year = Year(d.year); month = Month(d.month); day = Day(d.day); return *this; }
/** * name: Compare * desc: compare a systemtime with the value of current object and return difference as number of seconds it handles some strange, too. * param: st - SYSTEMTIME to compare with * return: number of seconds the st differs from the class value **/ LONG MTime::Compare(SYSTEMTIME st) const { FILETIME ft2; //strange day-in-month thing if (st.wYear == 0) { if (Month() < st.wMonth) return -1; if (Month() > st.wMonth) return 1; MTime mtTmp(st, FALSE); mtTmp.Year(Year()); mtTmp.Day(1); mtTmp.Set(mtTmp.FileTime(), FALSE); //gets the day of week of the first of the month mtTmp.Day(1 + (7 + st.wDayOfWeek - mtTmp.DayOfWeek()) % 7); //last wDayOfWeek in month if (st.wDay == 5) { mtTmp.Day(mtTmp.Day() + 7 * 3); //can't be less than 4 of that day in the month if (mtTmp.Day() + 7 <= mtTmp.DaysInMonth(st.wMonth - 1)) mtTmp.Day(mtTmp.Day() + 7); } else mtTmp.Day(7 * (st.wDay - 1)); //nth of month ft2 = mtTmp.FileTime(); } else { SystemTimeToFileTime(&st, &ft2); } return Compare(ft2); }
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); }
/** * 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 ); }
/** *\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; }
void Date::printOn( ostream& outputStream ) const { char temp[BufSize]; ostrstream os( temp, BufSize ); os << MonthNames[ Month() ] << " " << Day() << ", " << Year() << ends; outputStream << temp; }
/** * name: IsValid * 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 **/ __inline BOOLEAN MAnnivDate::IsValid() const { return ( Year() > 1600 && Month() > 0 && Month() < 13 && Day() > 0 && Day() <= DaysInMonth(Month()) ); }
void USFederalHolidayCalendarTest::test_2012_data_driven() { CalendarSharedPtr calA = getCalendar ("United States Federal Holiday Calendar"); BusinessCalendarSharedPtr busCalA = CHECKED_SHARED_POINTER_CAST(BusinessCalendar,Calendar,calA); runCalendaTest(*busCalA, Year(2012)); }
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)); }
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; }
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; }
/** * 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; }
void USFederalHolidayCalendarTest::test_2012() { USFederalHolidayCalendar cal; //Load the rules cal.configure(); //Compare data generated by the rules to test data loaded from xml test data file runCalendaTest(cal, Year(2012)); }
void USFederalHolidayCalendarTest::test_2010() { USFederalHolidayCalendar cal; //Load the rules cal.configure(); //Compare data generated by the rules to test data loaded from xml test data file runCalendaTest(cal, Year(2010)); CPPUNIT_ASSERT(false == cal.isBusinessDay(Date(20101231))); }
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); }
int main() { T=MakeTANGGAL(2,12,1989); T1=MakeTANGGAL(2,12,1989); TulisTANGGAL(T);TulisTANGGAL(T1); printf("Prev Day 2/12/1989 : ");TulisTANGGAL(PrevDay(T)); printf("Next Day 2/12/1989 : ");TulisTANGGAL(NextDay(T)); printf("Next 15 Day 2/12/1989 : ");TulisTANGGAL(NextNday(T,15)); printf("Prev 15 Day 2/12/1989 : ");TulisTANGGAL(PrevNDay(T,15)); printf("Tanggal 2/12/1989 ada : %4d hari",HariKe(T));printf("\n"); printf("hari ke- %4d jatuh pada tanggal :",HariKe(T));TulisTANGGAL(DayOfYear(HariKe(T),Year(T)));printf("\n"); printf("IsEqD T dan T1 ? %s\n",(IsEqD(T,T1)?"true":"false")); printf("IsBefore T dan T1 ? %s\n",(IsBefore(T,T1)?"true":"false")); printf("IsAfter T dan T1 ? %s\n",(IsAfter(T,T1)?"true":"false")); printf("IsKabisat T ?%s\n",(IsKabisat(Year(T))?"true":"false")); printf("IsKabisat 1972 ? %s\n",(IsKabisat(1972)?"true":"false")); printf("#hari/tahun : 100/1972 ? ");TulisTANGGAL(DayOfYear(100,1972)); return 0; }
DatePickerWindow initDatePicker() { DatePickerWindow w; w.selected = 0; w.date = Today(); w.window = window_create(); w.day.layer = text_layer_create(GRect(9, 66, 28, 35)); w.month.layer = text_layer_create(GRect(43, 66, 28, 35)); w.year.layer = text_layer_create(GRect(76, 66, 58, 35)); char* day = Day(&w.date); text_layer_set_text(w.day.layer, day); text_layer_set_font(w.day.layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(w.day.layer, GTextAlignmentCenter); text_layer_set_background_color(w.day.layer, C_BACKGROUND); text_layer_set_text_color(w.day.layer, C_FOREGROUND); layer_add_child(window_get_root_layer(w.window), text_layer_get_layer(w.day.layer)); char* month = Month(&w.date); text_layer_set_text(w.month.layer, month); text_layer_set_font(w.month.layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(w.month.layer, GTextAlignmentCenter); text_layer_set_background_color(w.month.layer, C_BACKGROUND); text_layer_set_text_color(w.month.layer, C_FOREGROUND); layer_add_child(window_get_root_layer(w.window), text_layer_get_layer(w.month.layer)); char* year = Year(&w.date); text_layer_set_text(w.year.layer, year); text_layer_set_font(w.year.layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(w.year.layer, GTextAlignmentCenter); text_layer_set_background_color(w.year.layer, C_BACKGROUND); text_layer_set_text_color(w.year.layer, C_FOREGROUND); layer_add_child(window_get_root_layer(w.window), text_layer_get_layer(w.year.layer)); updateWhichSelected(w); window_set_click_config_provider_with_context(w.window, (ClickConfigProvider)config_provider, (void*)&w); return w; }
void modifyDisplayDate(int direction, DatePickerWindow w) { switch (w.selected % 3) { case 0: w.date.day += direction; NormalizeDay(&w.date); break; case 1: w.date.month += direction; NormalizeMonth(&w.date); break; case 2: w.date.year += direction; NormalizeMonth(&w.date); break; } text_layer_set_text(w.day.layer, Day(&w.date)); text_layer_set_text(w.month.layer, Month(&w.date)); text_layer_set_text(w.year.layer, Year(&w.date)); updateWhichSelected(w); }
/** * Returns the year portion of the time as a string * * @return string */ QString iTime::YearString() const { return toString(Year()); }
void MonthWeekDayRuleTest::test_utilities() { SetDate date; Year year (2010); Date ruleStartDate(20100101); //test: MonthWeekDayRule::virtual Date calcDate(const Year& year) const ; MonthWeekDayRule laborDayRule ("LaborDay", MonthOfYear::September, MonthWeek::First, WeekDay::Monday); laborDayRule.setStartEffectiveDate(ruleStartDate); Date labourDayHoliday(20100906); date = laborDayRule .calcDate(year); CPPUNIT_ASSERT(labourDayHoliday == *date.begin()); MonthWeekDayRule mlkRule ("MLKDay", MonthOfYear::January, MonthWeek::Third, WeekDay::Monday); mlkRule.setStartEffectiveDate(ruleStartDate); Date mlkBirthDateHoliday(20100118); date = mlkRule.calcDate(year); CPPUNIT_ASSERT(mlkBirthDateHoliday == *date.begin()); MonthWeekDayRule presidentDayRule("PresidentDay", MonthOfYear::February, MonthWeek::Third, WeekDay::Monday); presidentDayRule.setStartEffectiveDate(ruleStartDate); Date presidentDayHoliday(20100215); date = presidentDayRule.calcDate(year); CPPUNIT_ASSERT(presidentDayHoliday == *date.begin()); MonthWeekDayRule thanksGivingRule("ThanksGiving", MonthOfYear::November, MonthWeek::Fourth, WeekDay::Thursday); thanksGivingRule.setStartEffectiveDate(ruleStartDate); Date thanksgivingHoliday(20101125); date = thanksGivingRule.calcDate(year); CPPUNIT_ASSERT(thanksgivingHoliday == *date.begin()); //Check IMM dates MonthWeekDayRule imm1("IMM1", MonthOfYear::March, MonthWeek::Third, WeekDay::Wednesday); imm1.setStartEffectiveDate(20050101); CPPUNIT_ASSERT(Date(20050316) == *imm1.calcDate(Year(2005)).begin()); MonthWeekDayRule imm2("IMM2", MonthOfYear::June, MonthWeek::Third, WeekDay::Wednesday); imm2.setStartEffectiveDate(20050101); CPPUNIT_ASSERT(Date(20050615) == *imm2.calcDate(Year(2005)).begin()); MonthWeekDayRule imm3("IMM3", MonthOfYear::September, MonthWeek::Third, WeekDay::Wednesday); imm3.setStartEffectiveDate(20050101); CPPUNIT_ASSERT(Date(20050921) == *imm3.calcDate(Year(2005)).begin()); MonthWeekDayRule imm4("IMM4", MonthOfYear::December, MonthWeek::Third, WeekDay::Wednesday); imm4.setStartEffectiveDate(20050101); CPPUNIT_ASSERT(Date(20051221) == *imm4.calcDate(Year(2005)).begin()); //Rule is disabled try{ laborDayRule.setEnabledFlag(false); laborDayRule.calcDate(year); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called on disabled rule"); } laborDayRule.setEnabledFlag(true); //Rule start date year > calc year try{ laborDayRule.calcDate(Year(2009)); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called for year before rule is in effect"); } //Rule calc year > rule end date year try{ laborDayRule.setEndEffectiveDate(20121231); laborDayRule.calcDate(Year(2030)); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called for year after rule is in effect"); } }
/** *\en * \brief Returns the number of days from this date to target (which is negative * if target is earlier than this date). *\_en * \brief Возвращает количество дней до указанной даты от даты, представленной объектом. * * Возвращаемое значение может быть отрицательным, если указанная дата находится в прошлом по * отношению к дате, представленной объектом. *\_ru */ int aDateService::DaysTo ( const QDate& target ) const { QDate currentDate( Year(), Month(), Day() ); return currentDate.daysTo( target ) ; }
/** *\en *\_en *\ru * \brief Возвращает представление даты в объекте сласса QDate. *\_ru */ QDate aDateService::ToDate () const { QDate result( Year(), Month(), Day() ); return result; };
/** * name: CompareDays * class: MAnnivDate * desc: compare the current date with the given one in st * param: mt - MTime to compare with * return: number of days the mt differs from the class value **/ INT MAnnivDate::CompareDays(MTime mt) const { mt.Year(Year()); return DayOfYear() - mt.DayOfYear(); }
Bibliographic FieldBuilder::buildField(const KeyValuePair& kvp) { String key = kvp.getKey(); Bibliographic field = Bibliographic(kvp); if (key == "author") { field = (Author)field; return field; } else if (key == "doi") { field = Doi(); } else if (key == "issn") { field = Issn(); } else if (key == "journal") { field = Journal(); } else if (key == "month") { field = Month(); } else if (key == "number") { field = Number(); } else if (key == "pages") { field = Pages(); } else if (key == "title") { field = Title(); } else if (key == "url") { field = Url(); } else if (key == "urldate") { field = UrlDate(); } else if (key == "volume") { field = Volume(); } else if (key == "year") { field = Year(); } else { field = Bibliographic(); field.setKey(kvp.getKey()); } field.setValue(kvp.getValue()); return field; }