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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* GNOME Logs - View and search logs
* Copyright (C) 2015 Ekaterina Gerasimova
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gl-util.h"
static void
util_timestamp_to_display (void)
{
gsize i;
GDateTime *now;
static const struct
{
guint64 microsecs;
GlUtilClockFormat format;
const gchar *time;
} times[] =
{
/* Test three cases for each format (same day, same year, different
year */
{ G_GUINT64_CONSTANT (1423486800000000), GL_UTIL_CLOCK_FORMAT_12HR,
" 1:00 PM" },
{ G_GUINT64_CONSTANT (1423402200000000), GL_UTIL_CLOCK_FORMAT_12HR,
"Feb 8 1:30 PM" },
{ G_GUINT64_CONSTANT (1391952600000000), GL_UTIL_CLOCK_FORMAT_12HR,
"Feb 9 2014 1:30 PM" },
{ G_GUINT64_CONSTANT (1423486800000000), GL_UTIL_CLOCK_FORMAT_24HR,
"13:00" },
{ G_GUINT64_CONSTANT (1423402200000000), GL_UTIL_CLOCK_FORMAT_24HR,
"Feb 8 13:30" },
{ G_GUINT64_CONSTANT (1391952600000000), GL_UTIL_CLOCK_FORMAT_24HR,
"Feb 9 2014 13:30" }
};
now = g_date_time_new_utc (2015, 2, 9, 13, 30, 42);
for (i = 0; i < G_N_ELEMENTS (times); i++)
{
gchar *compare;
compare = gl_util_timestamp_to_display (times[i].microsecs, now,
times[i].format, FALSE);
g_assert_cmpstr (compare, ==, times[i].time);
g_free (compare);
}
g_date_time_unref (now);
}
int
main (int argc, char** argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/util/timestamp_to_display", util_timestamp_to_display);
return g_test_run ();
}
|