changes: Bump to 3.8.1
[platform/upstream/evolution-data-server.git] / libedataserver / e-time-utils.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Time utility functions
4  *
5  * Author:
6  *   Damon Chaplin (damon@ximian.com)
7  *
8  * (C) 2001 Ximian, Inc.
9  */
10
11 #if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
12 #error "Only <libedataserver/libedataserver.h> should be included directly."
13 #endif
14
15 #ifndef E_TIME_UTILS_H
16 #define E_TIME_UTILS_H
17
18 #include <time.h>
19 #include <glib.h>
20
21 G_BEGIN_DECLS
22
23 /**
24  * ETimeParseStatus:
25  * @E_TIME_PARSE_OK: The time string was parsed successfully.
26  * @E_TIME_PARSE_NONE: The time string was empty.
27  * @E_TIME_PARSE_INVALID: The time string was not formatted correctly.
28  **/
29 typedef enum {
30         E_TIME_PARSE_OK,
31         E_TIME_PARSE_NONE,
32         E_TIME_PARSE_INVALID
33 } ETimeParseStatus;
34
35 /* Tries to parse a string containing a date and time. */
36 ETimeParseStatus
37                 e_time_parse_date_and_time      (const gchar *value,
38                                                  struct tm *result);
39
40 /* Tries to parse a string containing a date. */
41 ETimeParseStatus
42                 e_time_parse_date               (const gchar *value,
43                                                  struct tm *result);
44
45 /* Same behavior as the functions above with two_digit_year set to NULL. */
46 ETimeParseStatus
47                 e_time_parse_date_and_time_ex   (const gchar *value,
48                                                  struct tm *result,
49                                                  gboolean *two_digit_year);
50 ETimeParseStatus
51                 e_time_parse_date_ex            (const gchar *value,
52                                                  struct tm *result,
53                                                  gboolean *two_digit_year);
54
55 /* Tries to parse a string containing a time. */
56 ETimeParseStatus
57                 e_time_parse_time               (const gchar *value,
58                                                  struct tm *result);
59
60 /* Turns a struct tm into a string like "Wed  3/12/00 12:00:00 AM". */
61 void            e_time_format_date_and_time     (struct tm *date_tm,
62                                                  gboolean use_24_hour_format,
63                                                  gboolean show_midnight,
64                                                  gboolean show_zero_seconds,
65                                                  gchar *buffer,
66                                                  gint buffer_size);
67
68 /* Formats a time from a struct tm, e.g. "01:59 PM". */
69 void            e_time_format_time              (struct tm *date_tm,
70                                                  gboolean use_24_hour_format,
71                                                  gboolean show_zero_seconds,
72                                                  gchar *buffer,
73                                                  gint buffer_size);
74
75 /* Like mktime(3), but assumes UTC instead of local timezone. */
76 time_t          e_mktime_utc                    (struct tm *tm);
77
78 /* Like localtime_r(3), but also returns an offset in minutes after UTC.
79  * (Calling gmtime with tt + offset would generate the same tm) */
80 void            e_localtime_with_offset         (time_t tt,
81                                                  struct tm *tm,
82                                                  gint *offset);
83
84 /* Returns format like %x, but always exchange all 'y' to 'Y'
85  * (force 4 digit year in format).
86  * Caller is responsible to g_free returned pointer. */
87 gchar *         e_time_get_d_fmt_with_4digit_year
88                                                 (void);
89
90 G_END_DECLS
91
92 #endif /* E_TIME_UTILS_H */