summaryrefslogtreecommitdiff
path: root/vtime.c
diff options
context:
space:
mode:
authorKrow Savcik <krow@savcik.xyz>2025-07-26 12:50:28 +0300
committerKrow Savcik <krow@savcik.xyz>2025-07-26 12:50:28 +0300
commit9f2884c0dcbd7762c8a6a067174c3ca1f304d9c0 (patch)
tree90d21c6864a5b15b28612bf5ee11d8beb539f87c /vtime.c
initial commitHEADmaster
Diffstat (limited to 'vtime.c')
-rw-r--r--vtime.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/vtime.c b/vtime.c
new file mode 100644
index 0000000..782f171
--- /dev/null
+++ b/vtime.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+
+#define VTIME_IMPL
+#include "vtime.h"
+
+void
+help()
+{
+ fprintf(stdout, "vtime [FORMAT]\n\
+\t[YYYY/yy].[mm].dd Sets the date. Can set only the day/month.\n\
+\t Instead of dot(.) coult be any non-numeric character.\n\
+\t+/-[k](d/w/m/y) Add/subtract k units from the date. k is implicitly 1\n\
+\tt[his]/n[ext] Wday\n\
+\tl[ast]/p[rev] Wday Go to next/previous week day. Wday is the week day prefix.\n\
+\tb[egining]\n\ts[tart]\n\tf[irst]\n\
+\te[nd] w[eek]/m[onth]/y[ear] Go to first/last day in week/month/year.\n\
+");
+}
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ time_t now = time(NULL);
+ struct tm out = *(localtime(&now));
+ if (argc == 1) {
+ help();
+ return 0;
+ }
+
+ char *fmt, *pnt;
+ size_t len = 0;
+ for (i = 1; i < argc; i++) {
+ len += 1 + strlen(argv[i]);
+ }
+
+ fmt = calloc(len, sizeof(*fmt));
+ if (fmt == NULL) {
+
+ fprintf(stderr, "Failed malloc\n");
+ return 1;
+ }
+
+ for (i = 1, pnt = fmt; i < argc; i++) {
+ pnt = stpcpy(pnt, argv[i]);
+ if (i != argc-1)
+ *(pnt++) = ' ';
+ }
+
+ if (vtime(&out, fmt, 0)) {
+ fprintf(stderr, "Wrong format\n");
+ return 1;
+ }
+ fprintf(stdout, "%s", asctime(&out));
+ return 0;
+}