📄 add_longtime.c
字号:
/*===========================================================================*//* DMC Interim | add_longtime | utility *//*===========================================================================*//* Name: add_longtime Purpose: add a time increment in seconds to time in struct input_time fmt Usage: struct input_time add_longtime (); struct input_time time; struct input_time newtime; long delta; newtime = add_longtime (time, delta); Input: time = original time in struct input_time form delta = increment>0 in seconds to be added to original time Output: newtime = output time in struct input_time form Externals: none Warnings: none Errors: none Called by: anything Calls to: none Algorithm: convert the input hour, minute, second, fracsec to seconds; add total to delta; convert result to days, hours, minutes, seconds, and fractional seconds, allowing for change of year. Notes: The time structure looks like: struct input_time { unsigned short int year; unsigned short int day; char hour; char minute; char second; unsigned short int fracsec; }; Problems: Ignores leap seconds Debug: level D_MIN - level D_MED - level D_MAX - print out start and finish notices References: none Language: ANSI standard C Author: Kevin MacKenzie 01 mar 1989 Revisions: */#include "output.h"#define isaleap(year) (((year%100 != 0) && (year%4 == 0)) || (year%400 == 0))struct input_time add_longtime (time, delta)struct input_time time;register long delta;{ struct input_time newtime; /* result */ unsigned short int lenyr; /* length of year in days */ char i; if (Debug > D_MAX) fprintf (D_OUT, "[add_longtime] Started.\n"); /* convert input day time to seconds and add to delta */ delta += (time.hour*3600) + (time.minute*60) + time.second; /* convert delta to days hh:mm:ss.ffff */ newtime.fracsec = time.fracsec; /* no change */ newtime.day = time.day + (unsigned short int) (delta / 86400); delta %= 86400L; /* seconds per day */ newtime.hour = (char) (delta / 3600L); delta %= 3600L; /* seconds per hour */ newtime.minute = (char) (delta / 60L); delta %= 60L; /* seconds per minute */ newtime.second = (char) delta; newtime.year = time.year; /* no change */ /* if at a year boundary, fixup date, taking leap years into account */ if (newtime.day > 365) { /* at year boundary */ lenyr = (isaleap (time.year)) ? 366 : 365; /* get length of year */ newtime.year += (newtime.day - 1) / lenyr; if ((newtime.day %= lenyr) == 0) newtime.day = lenyr; } if (Debug > D_MAX) fprintf (D_OUT, "[add_longtime] Finished.\n"); return (newtime);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -