Luna/apps/date.cpp
apio 0fad179485
All checks were successful
continuous-integration/drone/push Build is passing
apps+libc+libos: Remove _LUNA_SYSTEM_ERROR_EXTENSIONS and reorder headers
libluna/libos headers can now go after errno.h, so there's no reason to keep them separate.
2023-05-02 10:51:53 +02:00

26 lines
693 B
C++

#include <os/ArgumentParser.h>
#include <os/File.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
Result<int> luna_main(int argc, char** argv)
{
StringView date;
os::ArgumentParser parser;
parser.add_description("Display the current (or another) date and time."_sv);
parser.add_system_program_info("date"_sv);
parser.add_value_argument(date, 'd', "date"_sv, true,
"the UNIX timestamp to display instead of the current time"_sv);
parser.parse(argc, argv);
time_t now;
if (date.is_empty()) { now = time(NULL); }
else { now = strtol(date.chars(), nullptr, 10); }
os::print("%s", ctime(&now));
return 0;
}