1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* Time utility functions 3 * 4 * (C) 2001 Ximian, Inc. 5 * 6 * This library is free software: you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 * for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this library. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * Authors: Damon Chaplin (damon@ximian.com) 19 */ 20 21 #if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION) 22 #error "Only <libedataserver/libedataserver.h> should be included directly." 23 #endif 24 25 #ifndef E_TIME_UTILS_H 26 #define E_TIME_UTILS_H 27 28 #include <time.h> 29 #include <glib.h> 30 31 G_BEGIN_DECLS 32 33 /** 34 * ETimeParseStatus: 35 * @E_TIME_PARSE_OK: The time string was parsed successfully. 36 * @E_TIME_PARSE_NONE: The time string was empty. 37 * @E_TIME_PARSE_INVALID: The time string was not formatted correctly. 38 **/ 39 typedef enum { 40 E_TIME_PARSE_OK, 41 E_TIME_PARSE_NONE, 42 E_TIME_PARSE_INVALID 43 } ETimeParseStatus; 44 45 /* Tries to parse a string containing a date and time. */ 46 ETimeParseStatus 47 e_time_parse_date_and_time (const gchar *value, 48 struct tm *result); 49 50 /* Tries to parse a string containing a date. */ 51 ETimeParseStatus 52 e_time_parse_date (const gchar *value, 53 struct tm *result); 54 55 /* Same behavior as the functions above with two_digit_year set to NULL. */ 56 ETimeParseStatus 57 e_time_parse_date_and_time_ex (const gchar *value, 58 struct tm *result, 59 gboolean *two_digit_year); 60 ETimeParseStatus 61 e_time_parse_date_ex (const gchar *value, 62 struct tm *result, 63 gboolean *two_digit_year); 64 65 /* Tries to parse a string containing a time. */ 66 ETimeParseStatus 67 e_time_parse_time (const gchar *value, 68 struct tm *result); 69 70 /* Turns a struct tm into a string like "Wed 3/12/00 12:00:00 AM". */ 71 void e_time_format_date_and_time (struct tm *date_tm, 72 gboolean use_24_hour_format, 73 gboolean show_midnight, 74 gboolean show_zero_seconds, 75 gchar *buffer, 76 gint buffer_size); 77 78 /* Formats a time from a struct tm, e.g. "01:59 PM". */ 79 void e_time_format_time (struct tm *date_tm, 80 gboolean use_24_hour_format, 81 gboolean show_zero_seconds, 82 gchar *buffer, 83 gint buffer_size); 84 85 /* Like mktime(3), but assumes UTC instead of local timezone. */ 86 time_t e_mktime_utc (struct tm *tm); 87 88 /* Like localtime_r(3), but also returns an offset in minutes after UTC. 89 * (Calling gmtime with tt + offset would generate the same tm) */ 90 void e_localtime_with_offset (time_t tt, 91 struct tm *tm, 92 gint *offset); 93 94 /* Returns format like %x, but always exchange all 'y' to 'Y' 95 * (force 4 digit year in format). 96 * Caller is responsible to g_free returned pointer. */ 97 gchar * e_time_get_d_fmt_with_4digit_year 98 (void); 99 100 G_END_DECLS 101 102 #endif /* E_TIME_UTILS_H */ 103