summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/elapsedtime.c30
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;
+}