diff options
author | epoch <epoch@hack.thebackupbox.net> | 2021-03-13 18:48:36 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2021-03-13 18:48:36 +0000 |
commit | 54443ed19eeeb63f787a6fd709cd99c423e8e854 (patch) | |
tree | 585311544242068f58d1146f60325fb47a0e63f1 | |
parent | d5f9021ccae4daa678ce73d3a4aa5ef9010cb0e5 (diff) | |
download | misc-54443ed19eeeb63f787a6fd709cd99c423e8e854.tar.gz misc-54443ed19eeeb63f787a6fd709cd99c423e8e854.zip |
added -s|--short to elapsedtime
-rw-r--r-- | src/bin/elapsedtime.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/bin/elapsedtime.c b/src/bin/elapsedtime.c new file mode 100644 index 0000000..42c2b5e --- /dev/null +++ b/src/bin/elapsedtime.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc,char *argv[]) { + char c;//comma? + long long ll; + short s=0; + if(argc < 2) { + printf("usage: elapsedtime [-s|--short] seconds\n"); + return 1; + } + argv++; + if(!strcmp(*argv,"-s") || !strcmp(*argv,"--short")) { + s=1; + argv++; + } + char *f=strchr(*argv,'.'); + ll=atoll(*argv); + if(s) { + printf("%lld:%lld%s\n",ll / 60 % 60,ll % 60,f?f:""); + return 0; + } + if(ll / 31557600 ) { if(c) printf(", ");c=1;printf("%lld year%s", ll / 31557600, ll / 31557600 == 1 ? "" : "s"); } + if(ll % 31557600 / 86400) { if(c) printf(", ");c=1;printf("%lld day%s", ll % 31557600 / 86400, ll % 31557600 / 86400 == 1 ? "" : "s"); } + if(ll / 3600 % 24) { if(c) printf(", ");c=1;printf("%lld hour%s", ll / 3600 % 24, ll / 3600 % 24 == 1 ? "" : "s"); } + if(ll / 60 % 60) { if(c) printf(", ");c=1;printf("%lld minute%s",ll / 60 % 60, ll / 60 % 60 == 1 ? "" : "s"); } + if(ll % 60) { if(c) printf(", ");c=1;printf("%lld%s second%s",ll % 60,f?f:"", ll % 60 == 1 && !f ? "" : "s"); } + putchar('\n'); + return 0; +} |