Luna/apps/date.cpp

25 lines
657 B
C++
Raw Normal View History

#include <os/ArgumentParser.h>
#include <os/File.h>
2023-03-24 20:48:43 +00:00
#include <stddef.h>
#include <stdlib.h>
2023-03-24 20:48:43 +00:00
#include <time.h>
Result<int> luna_main(int argc, char** argv)
2023-03-24 20:48:43 +00:00
{
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, "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); }
2023-03-24 20:48:43 +00:00
os::print("%s", ctime(&now));
return 0;
2023-03-24 20:48:43 +00:00
}