void time_next_week(a_time *t) { time_whms(t, 6, 23, 59, 59); time_incr(t, 1); #if CHECK if (0 != time_tm(t)->tm_wday) BUG(); if (0 != time_tm(t)->tm_hour) BUG(); if (0 != time_tm(t)->tm_min) BUG(); if (0 != time_tm(t)->tm_sec) BUG(); #endif }
void time_incr_days(a_time *t, int days) { /* * Adjust t by N days, taking into account DST. */ if (0 == days) return; a_time old = time_clone(t); int old_hour = time_tm(&old)->tm_hour; time_incr(t, days * 3600 * 24); int new_hour = time_tm(t)->tm_hour; if (new_hour <= 1 && 22 <= old_hour) time_incr(t, -3600 * 2); /* DST oops, go back a bit */ else if (22 <= new_hour && old_hour <= 2) time_incr(t, 3600 * 2); /* DST oops, go forward a bit */ time_hms(t, time_tm(&old)->tm_hour, time_tm(&old)->tm_min, time_tm(&old)->tm_sec); }
int main(int argc, char **argv) { Scene *s; get_args(argc, argv); init_sdl(); s = scene_read(); gpsetdoublebuffer(1); plot_init("anim", s, bflag); while (!time_done(timeoff)) { plot_scene(s); scene_free(s); s = scene_eval(); time_incr(1); } gpwait(-1); plot_close(); }
void time_next_day(a_time *t) { /* * Most days are 3600 * 24 seconds, but some have +/- 1 leap second * and others have +/- 3600 because of DST. */ #if CHECK int tm_wday = time_tm(t)->tm_wday; #endif if (!time_hms(t, 23, 59, 59) && !time_hms(t, 23, 59, 58)) BUG(); while (time_tm(t)->tm_sec != 0) time_incr(t, 1); #if CHECK if (0 != time_tm(t)->tm_hour) BUG(); if (0 != time_tm(t)->tm_min) BUG(); if ((tm_wday + 1) % 7 != time_tm(t)->tm_wday) BUG(); #endif }
static bool time_wday(a_time *t, int wday) { /* * Find the day in the same week as t that has wday. If the day is * earlier in the week, set t to the last second of the target day. * If the day is later in the week, set to to the first second of * the target day. This preserves the "nearest match" behavior * described in time_ymdhms. Avoid overshooting into another week * by incrementing conservatively. This is not a simple 24 because * of DST and leap seconds. */ int tm_wday = time_tm(t)->tm_wday; if (tm_wday == wday) return true; time_incr(t, 3600 * (24 - 1) * (wday - tm_wday)); if (time_tm(t)->tm_wday == wday) return tm_wday < wday ? time_hms(t, 0, 0, 0) : time_hms(t, 23, 59, 59); return time_wday(t, wday); }
bool time_ymdhms(a_time *t, int year, int mon, int mday, int hour, int min, int sec) { /* * Some times occur twice, such as 2am in fall in PST. Prefer the * time nearest to t that is at least as large as t. * * Apologies to Australia's Lord Howe Island, which uses a half-hour * shift, and which is not handled in this code. */ if (time_is_ymdhms(t, year, mon, mday, hour, min, sec)) return true; struct tm target_tm = *time_tm(t); target_tm.tm_year = year - 1900; target_tm.tm_mon = mon - 1; target_tm.tm_mday = mday; target_tm.tm_hour = hour; target_tm.tm_min = min; target_tm.tm_sec = sec; target_tm.tm_sec = sec; target_tm.tm_isdst = -1; a_time target; time_t tt = mktime(&target_tm); if (-1 == tt) return false; time_init(&target, tt); bool target_is_future = 0 < time_diff(&target, t) ? true : false; int dst_check_offset = target_is_future ? -3600 : 3600; a_time dst_check = time_clone(&target); time_incr(&dst_check, dst_check_offset); if (time_is_ymdhms(&dst_check, year, mon, mday, hour, min, sec) && 0 <= time_diff(&dst_check, t)) { time_copy(&target, &dst_check); } time_copy(t, &target); return true; }
static void _proc_msg(int new_fd, char *msg, slurm_addr_t cli_addr) { /* Locks: Read job and node data */ slurmctld_lock_t job_read_lock = { NO_LOCK, READ_LOCK, READ_LOCK, NO_LOCK, NO_LOCK }; /* Locks: Write job */ slurmctld_lock_t job_write_lock = { NO_LOCK, WRITE_LOCK, NO_LOCK, NO_LOCK, NO_LOCK }; /* Locks: Write job, write node, read partition */ slurmctld_lock_t job_write_lock2 = { NO_LOCK, WRITE_LOCK, WRITE_LOCK, READ_LOCK, READ_LOCK }; /* Locks: Write node data */ slurmctld_lock_t node_write_lock = { NO_LOCK, NO_LOCK, WRITE_LOCK, NO_LOCK, READ_LOCK }; char *cmd_ptr, *resp = NULL, *msg_decrypted = NULL; uid_t cmd_uid; uint32_t protocol_version = 0; if (!msg) { info("slurmctld/nonstop: NULL message received"); resp = xstrdup("Error:\"NULL message received\""); goto send_resp; } msg_decrypted = _decrypt(msg, &cmd_uid); if (!msg_decrypted) { info("slurmctld/nonstop: Message decrypt failure"); resp = xstrdup("Error:\"Message decrypt failure\""); goto send_resp; } if (nonstop_debug > 0) info("slurmctld/nonstop: msg decrypted:%s", msg_decrypted); cmd_ptr = msg_decrypted; /* 123456789012345678901234567890 */ if (xstrncmp(cmd_ptr, version_string, 13) == 0) { cmd_ptr = strchr(cmd_ptr + 13, ':'); if (cmd_ptr) { cmd_ptr++; protocol_version = SLURM_PROTOCOL_VERSION; } } if (protocol_version == 0) { info("slurmctld/nonstop: Message version invalid"); resp = xstrdup("Error:\"Message version invalid\""); goto send_resp; } if (xstrncmp(cmd_ptr, "CALLBACK:JOBID:", 15) == 0) { resp = register_callback(cmd_ptr, cmd_uid, cli_addr, protocol_version); } else if (xstrncmp(cmd_ptr, "DRAIN:NODES:", 12) == 0) { lock_slurmctld(node_write_lock); resp = drain_nodes_user(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(node_write_lock); } else if (xstrncmp(cmd_ptr, "DROP_NODE:JOBID:", 15) == 0) { lock_slurmctld(job_write_lock2); resp = drop_node(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock2); } else if (xstrncmp(cmd_ptr, "GET_FAIL_NODES:JOBID:", 21) == 0) { lock_slurmctld(job_read_lock); resp = fail_nodes(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_read_lock); } else if (xstrncmp(cmd_ptr, "REPLACE_NODE:JOBID:", 19) == 0) { lock_slurmctld(job_write_lock2); resp = replace_node(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock2); } else if (xstrncmp(cmd_ptr, "SHOW_CONFIG", 11) == 0) { resp = show_config(cmd_ptr, cmd_uid, protocol_version); } else if (xstrncmp(cmd_ptr, "SHOW_JOB:JOBID:", 15) == 0) { resp = show_job(cmd_ptr, cmd_uid, protocol_version); } else if (xstrncmp(cmd_ptr, "TIME_INCR:JOBID:", 16) == 0) { lock_slurmctld(job_write_lock); resp = time_incr(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock); } else { info("slurmctld/nonstop: Invalid command: %s", cmd_ptr); xstrfmtcat(resp, "%s ECMD", SLURM_VERSION_STRING); } send_resp: if (nonstop_debug > 0) info("slurmctld/nonstop: msg send:%s", resp); _send_reply(new_fd, resp); xfree(resp); if (msg_decrypted) free(msg_decrypted); return; }
a_time time_plus(const a_time *t, int sec) { a_time ret = time_clone(t); time_incr(&ret, sec); return ret; }