void DateTime::format(std::string& str, const std::string& fmt, int timeZoneDifferential) { std::string::const_iterator it = fmt.begin(); std::string::const_iterator end = fmt.end(); while (it != end) { if (*it == '%') { if (++it != end) { switch (*it) { case 'w': str.append(WEEKDAY_NAMES[dayOfWeek()], 0, 3); break; case 'W': str.append(WEEKDAY_NAMES[dayOfWeek()]); break; case 'b': str.append(MONTH_NAMES[month() - 1], 0, 3); break; case 'B': str.append(MONTH_NAMES[month() - 1]); break; case 'd': NumberFormatter::append0(str, (int32_t)day(), 2); break; case 'e': NumberFormatter::append(str, (int32_t)day()); break; case 'f': NumberFormatter::append(str, (int32_t)day(), 2); break; case 'm': NumberFormatter::append0(str, (int32_t)month(), 2); break; case 'n': NumberFormatter::append(str, (int32_t)month()); break; case 'o': NumberFormatter::append(str, (int32_t)month(), 2); break; case 'y': NumberFormatter::append0(str, (int32_t)year() % 100, 2); break; case 'Y': NumberFormatter::append0(str, (int32_t)year(), 4); break; case 'H': NumberFormatter::append0(str, (int32_t)hour(), 2); break; case 'h': NumberFormatter::append0(str, (int32_t)hourAMPM(), 2); break; case 'a': str.append(isAM() ? "am" : "pm"); break; case 'A': str.append(isAM() ? "AM" : "PM"); break; case 'M': NumberFormatter::append0(str, (int32_t)minute(), 2); break; case 'S': NumberFormatter::append0(str, (int32_t)second(), 2); break; case 'i': NumberFormatter::append0(str, (int32_t)millisecond(), 3); break; case 'c': NumberFormatter::append(str, (int32_t)millisecond()/100); break; case 'F': NumberFormatter::append0(str, (int32_t)millisecond()*1000 + microsecond(), 6); break; case 'z': tzdISO(str, timeZoneDifferential); break; case 'Z': tzdRFC(str, timeZoneDifferential); break; default: str += *it; } ++it; } } else str += *it++; } }
/** * @return 1 if the configuration file has changed since last check, 0 otherwise */ int dynamic_configuration_changed() { long long * last_change = dynamic_configuration_get_last_change(); long long new_change; struct stat stats; if(*last_change == 0) *last_change = millisecond_clock(); if(stat(dynamic_configuration_get_path(), &stats) != 0) return 0; new_change = millisecond(&stats); if(new_change <= *last_change) return 0; *last_change = new_change; return 1; }
void speed_test() { { meter m(100); second s(10); speed sp = m / s; assert(sp.value() == 10); } { millimeter mm (100000); second s(10); speed sp = mm / millisecond(s); speed sp2 = meter(mm) / s; assert(sp.value() == 10); assert(sp2.value() == 10); } cout << "speed test:\t\t Pass" << endl; }
const Timespan::Unit Timespan::Unit::second () { return (Value(1000) * millisecond().ticks()); }