Luna/apps/date.cpp
apio e6645ed607
StringView+apps: Add a _sv literal suffix to not confuse function overloads
C++ was being naughty and implicitly casting our fallback const char* to a boolean.
2023-03-29 22:10:01 +02:00

22 lines
436 B
C++

#include <os/ArgumentParser.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char** argv)
{
StringView date;
ArgumentParser parser;
parser.add_value_argument(date, 'd', "date"_sv, false);
parser.parse(argc, argv);
time_t now;
if (date.is_empty()) { now = time(NULL); }
else { now = strtol(date.chars(), nullptr, 10); }
fputs(ctime(&now), stdout);
}