aboutsummaryrefslogtreecommitdiff
path: root/date.c
blob: 522fda5a723bbf8222ccd9952a65eb094bdd7809 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* SPDX-License-Identifier: BSD-3-Clause */
/*
 * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
 * Copyright (C) 2022 Leah Rowe <leah@libreboot.org>
 */
#include <time.h>
#include <stdio.h>
#include <errno.h>

#define REQ_ERRPRINT
#include "common.h"

#ifdef FASESBOX
int date_main(int argc, char *argv[]) {
#else
int main(int argc, char *argv[]) {
#endif
	time_t epoch = time(NULL);
	struct tm* date = localtime(&epoch);
	char date_s[31];
	const char *format;
	if (argc == 2 && argv[1][0] == '+') {
		argv[1]++;
		format = argv[1];
	}
	else {
		format = "%a %b %e %H:%M:%S %Z %Y";
	}
	strftime(date_s, 31, format, date);
	printf("%s\n", date_s);
	return errprint(argv[0], NULL, errno);
}