//! Returns a negative duration_type duration_type get_neg_offset(const date_type& d) const { ymd_type ymd(d.year_month_day()); if (origDayOfMonth_ == 0) { origDayOfMonth_ = ymd.day; day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); if (endOfMonthDay == ymd.day) { origDayOfMonth_ = -1; //force the value to the end of month } } typedef date_time::wrapping_int2<short,1,12> wrap_int2; typedef typename wrap_int2::int_type int_type; wrap_int2 wi(ymd.month); //calc the year wrap around, add() returns 0 or 1 if wrapped int_type year = wi.subtract(static_cast<int_type>(f_)); year = static_cast<int_type>(year + ymd.year); //calculate resulting year //find the last day for the new month day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); //original was the end of month -- force to last day of month if (origDayOfMonth_ == -1) { return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; } day_type dayOfMonth = origDayOfMonth_; if (dayOfMonth > resultingEndOfMonthDay) { dayOfMonth = resultingEndOfMonthDay; } return date_type(year, wi.as_int(), dayOfMonth) - d; }
void init_scalar_smc(struct lu_phy_attr *lu) { int h, m, sec; int day, month, year; smc_pm.name = "mhVTL - Scalar emulation"; smc_pm.library_has_map = TRUE; smc_pm.library_has_barcode_reader = TRUE; smc_pm.library_has_playground = FALSE; smc_pm.dvcid_serial_only = FALSE; smc_pm.start_picker = 0x0001; smc_pm.start_map = 0x0010; smc_pm.start_drive = 0x0100; smc_pm.start_storage = 0x1000; smc_pm.lu = lu; smc_personality_module_register(&smc_pm); init_slot_info(lu); /* Reference Quantum 6-00423013 SCSI Reference - Rev A */ ymd(&year, &month, &day, &h, &m, &sec); /* Controller firmware build date */ sprintf((char *)&lu->inquiry[36], "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, h, m, sec); lu->inquiry[55] = 0x01; /* Contains barcode scanner : BarC */ init_smc_log_pages(lu); init_smc_mode_pages(lu); }
DateTime DateTime::start_of_minute() const { g_assert(is_set()); int year=0, month=0, day=0; ymd(year, month, day); return DateTime(m_tz.get(), year, month, day, hour(), minute(), 0); }
I q::date2q(char const* dateStr) throw(std::string) { assert(dateStr != NULL); int year = 0, month = 0, mday = 0; static char const* FMTs[] = { "%4d.%2d.%2d", "%4d-%2d-%2d", "%4d/%2d/%2d" }; for (int i = 0; i < _countof(FMTs); ++i) { # ifdef _MSC_VER int const result = ::sscanf_s(dateStr, FMTs[i], &year, &month, &mday); # else int const result = std::sscanf(dateStr, FMTs[i], &year, &month, &mday); # endif if (result == 3) { return ymd(year, month, mday); } } throw std::string("invalid date string"); }
int main() { using year = std::chrono::year; using month = std::chrono::month; using month_day_last = std::chrono::month_day_last; using year_month_day_last = std::chrono::year_month_day_last; ASSERT_NOEXCEPT( std::declval<const year_month_day_last>().month()); ASSERT_SAME_TYPE(month, decltype(std::declval<const year_month_day_last>().month())); for (unsigned i = 1; i <= 50; ++i) { year_month_day_last ymd(year{1234}, month_day_last{month{i}}); assert( static_cast<unsigned>(ymd.month()) == i); } }
int main() { using year = std::chrono::year; using month = std::chrono::month; using weekday_indexed = std::chrono::weekday_indexed; using year_month_weekday = std::chrono::year_month_weekday; ASSERT_NOEXCEPT( std::declval<const year_month_weekday>().month()); ASSERT_SAME_TYPE(month, decltype(std::declval<const year_month_weekday>().month())); static_assert( year_month_weekday{}.month() == month{}, ""); for (unsigned i = 1; i <= 50; ++i) { year_month_weekday ymd(year{1234}, month{i}, weekday_indexed{}); assert( static_cast<unsigned>(ymd.month()) == i); } }
/* As per IBM LTO5 SCSI Programmers Guide.. * Filling in compile time/date & dummy 'platform' string */ static void update_vpd_ult_c0(struct lu_phy_attr *lu) { uint8_t *data; struct vpd *vpd_p; int h, m, s; int day, month, year; vpd_p = lu->lu_vpd[PCODE_OFFSET(0xc0)]; data = vpd_p->data; ymd(&year, &month, &day, &h, &m, &s); data[1] = 0xc0; data[3] = 0x27; sprintf((char *)&data[16], "%02d%02d%02d", h, m, s); sprintf((char *)&data[23], "%04d%02d%02d", year, month, day); sprintf((char *)&data[31], "mhvtl_fl_f"); }
/* As per IBM LTO5 SCSI Programmers Guide.. * Filling in compile time/date & dummy 'platform' string */ static void update_vpd_dlt_c0(struct lu_phy_attr *lu) { uint8_t *data; struct vpd *vpd_p; int h, m, s; int day, month, year; vpd_p = lu->lu_vpd[PCODE_OFFSET(0xc0)]; data = vpd_p->data; month = 0; ymd(&year, &month, &day, &h, &m, &s); data[1] = 0xc0; data[3] = 0x28; /* Controller firmware build date */ sprintf((char *)&data[20], "%02d-%02d-%04d %02d:%02d:%02d", day, month, year, h, m, s); }
Gregorian::Gregorian(int year, int month, int day) { ymd_t ymd(year,month,day); check_valid_date(ymd); set_mjd_from_ymd(ymd); }
ZI ds(S s){DATE_STRUCT*d=(DATE_STRUCT*)s;R ymd(d->year,d->month,d->day);} ZS dtb(S s,I n){for(;n--&&s[n]==' ';);R sn(s,n+1);}