static __tb_inline__ tb_time_t tb_oc_bplist_writer_time_host2apple(tb_time_t time) { tb_tm_t tm = {0}; if (tb_localtime(time, &tm)) { if (tm.year >= 31) tm.year -= 31; time = tb_mktime(&tm); } return time; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ static __tb_inline__ tb_time_t tb_object_bplist_reader_time_apple2host(tb_time_t time) { tb_tm_t tm = {0}; if (tb_localtime(time, &tm)) { if (tm.year < 2000) tm.year += 31; time = tb_mktime(&tm); } return time; }
static tb_bool_t tb_oc_xml_writer_func_date(tb_oc_xml_writer_t* writer, tb_object_ref_t object, tb_size_t level) { // check tb_assert_and_check_return_val(writer && writer->stream, tb_false); // no empty? tb_time_t time = tb_oc_date_time(object); if (time > 0) { // writ beg if (!tb_oc_writer_tab(writer->stream, writer->deflate, level)) return tb_false; if (tb_stream_printf(writer->stream, "<date>") < 0) return tb_false; // writ date tb_tm_t date = {0}; if (tb_localtime(time, &date)) { if (tb_stream_printf(writer->stream, "%04ld-%02ld-%02ld %02ld:%02ld:%02ld" , date.year , date.month , date.mday , date.hour , date.minute , date.second) < 0) return tb_false; } // writ end if (tb_stream_printf(writer->stream, "</date>") < 0) return tb_false; if (!tb_oc_writer_newline(writer->stream, writer->deflate)) return tb_false; } else { // writ if (!tb_oc_writer_tab(writer->stream, writer->deflate, level)) return tb_false; if (tb_stream_printf(writer->stream, "<date/>") < 0) return tb_false; if (!tb_oc_writer_newline(writer->stream, writer->deflate)) return tb_false; } // ok return tb_true; }
static tb_void_t tb_directory_walk_func(tb_char_t const* path, tb_file_info_t const* info, tb_cpointer_t priv) { // check tb_assert_and_check_return(path && info); // the modify time tb_tm_t mtime = {0}; tb_localtime(info->mtime, &mtime); // dump tb_trace_i( "path[%c]: %s, size: %llu, mtime: %04ld-%02ld-%02ld %02ld:%02ld:%02ld" , info->type == TB_FILE_TYPE_DIRECTORY? 'd' : 'f' , path , info->size , mtime.year , mtime.month , mtime.mday , mtime.hour , mtime.minute , mtime.second); }
/* ////////////////////////////////////////////////////////////////////////////////////// * main */ tb_int_t tb_demo_libc_time_main(tb_int_t argc, tb_char_t** argv) { // time tb_time_t now = tb_time(); // the local time tb_tm_t lt = {0}; if (tb_localtime(now, <)) { tb_trace_i("LMT: %04ld-%02ld-%02ld %02ld:%02ld:%02ld, week: %d, time: %lld ?= %lld" , lt.year , lt.month , lt.mday , lt.hour , lt.minute , lt.second , lt.week , tb_mktime(<) , now); } // the gmt time tb_tm_t gt = {0}; if (tb_gmtime(now, >)) { tb_trace_i("GMT: %04ld-%02ld-%02ld %02ld:%02ld:%02ld, week: %d, time: %lld ?= %lld" , gt.year , gt.month , gt.mday , gt.hour , gt.minute , gt.second , gt.week , tb_gmmktime(>) , now); } return 0; }
tb_void_t tb_trace_done_with_args(tb_char_t const* prefix, tb_char_t const* module, tb_char_t const* format, tb_va_list_t args) { // check tb_check_return(format); // enter tb_spinlock_enter_without_profiler(&g_lock); // done do { // check tb_check_break(g_mode); // init tb_char_t* p = g_line; tb_char_t* e = g_line + sizeof(g_line); // print prefix to file if ((g_mode & TB_TRACE_MODE_FILE) && g_file) { // print time to file tb_tm_t lt = {0}; if (p < e && tb_localtime(tb_time(), <)) p += tb_snprintf(p, e - p, "[%04ld-%02ld-%02ld %02ld:%02ld:%02ld]: ", lt.year, lt.month, lt.mday, lt.hour, lt.minute, lt.second); // print self to file if (p < e) p += tb_snprintf(p, e - p, "[%lx]: ", tb_thread_self()); } // append prefix tb_char_t* b = p; if (prefix && p < e) p += tb_snprintf(p, e - p, "[%s]: ", prefix); // append module if (module && p < e) p += tb_snprintf(p, e - p, "[%s]: ", module); // append format if (p < e) p += tb_vsnprintf(p, e - p, format, args); // append end if (p < e) *p = '\0'; e[-1] = '\0'; // print it if (g_mode & TB_TRACE_MODE_PRINT) tb_print(b); // print it to file if ((g_mode & TB_TRACE_MODE_FILE) && g_file) { // done tb_size_t size = p - g_line; tb_size_t writ = 0; while (writ < size) { // writ it tb_long_t real = tb_file_writ(g_file, (tb_byte_t const*)g_line + writ, size - writ); tb_check_break(real > 0); // save size writ += real; } } } while (0); // leave tb_spinlock_leave(&g_lock); }