summaryrefslogtreecommitdiff
path: root/src/modules/time.c
blob: 272c8f803d2f9d0da7be58e481ba38e389ef1943 (plain)
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
33
34
35
36
37
38
39
40
41
#include "time.h"

#include <stdlib.h>
#include <time.h>

#define VALUE_SIZE 32

struct time {
    char value[VALUE_SIZE];
};


struct time *
time_new()
{
    struct time * t = malloc(sizeof(struct time));
    return t;
}

void
time_free(struct time * t)
{
    free(t);
}

void
time_update(struct time * t)
{
    time_t timer;
    struct tm * tm;

    time(&timer);
    tm = localtime(&timer);
    strftime(t->value, VALUE_SIZE, "%F [%a] %T", tm);
}

const char *
time_get_val(struct time * t)
{
    return t->value;
}