1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#include <time.h>
14#include <stdio.h>
15
16/*! @file
17    @brief Supports printing the current time in a human readable form
18*/
19
20char *weekdays[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
21char *months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
22
23/*! @brief Returns the day as a string */
24char * day_to_string(int day)
25{
26    return weekdays[day - 1];
27}
28
29/*! @brief Returns the month as a string */
30char * month_to_string(int month)
31{
32    return months[month];
33}
34
35/*! @brief Formats the time string */
36char * refos_print_time (struct tm *tm)
37{
38    static char buf[47];
39    snprintf(buf, 47, "%s, %s%3d %.2d:%.2d:%.2d %d\n",
40		    day_to_string(tm->tm_wday),
41		    month_to_string(tm->tm_mon),
42		    tm->tm_mday, tm->tm_hour,
43            tm->tm_min, tm->tm_sec,
44            1900 + tm->tm_year);
45    return buf;
46}
47