1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
15 * All rights reserved.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "text_object.h"
34 void scan_time(struct text_object *obj, const char *arg)
36 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
39 void scan_tztime(struct text_object *obj, const char *arg)
41 char buf1[256], buf2[256], *fmt, *tz;
45 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
55 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
56 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
59 void print_time(struct text_object *obj, char *p, int p_max_size)
61 time_t t = time(NULL);
62 struct tm *tm = localtime(&t);
64 setlocale(LC_TIME, "");
65 strftime(p, p_max_size, obj->data.s, tm);
68 void print_utime(struct text_object *obj, char *p, int p_max_size)
70 time_t t = time(NULL);
71 struct tm *tm = gmtime(&t);
73 setlocale(LC_TIME, "");
74 strftime(p, p_max_size, obj->data.s, tm);
77 void print_tztime(struct text_object *obj, char *p, int p_max_size)
83 if (obj->data.tztime.tz) {
85 setenv("TZ", obj->data.tztime.tz, 1);
91 setlocale(LC_TIME, "");
92 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
94 setenv("TZ", oldTZ, 1);
99 // Needless to free oldTZ since getenv gives ptr to static data
102 void free_time(struct text_object *obj)
110 void free_tztime(struct text_object *obj)
112 if (obj->data.tztime.tz) {
113 free(obj->data.tztime.tz);
114 obj->data.tztime.tz = NULL;
116 if (obj->data.tztime.fmt) {
117 free(obj->data.tztime.fmt);
118 obj->data.tztime.fmt = NULL;