NetSurf
time.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file utils/time.h
21 * \brief Interface to time operations.
22 */
23
24#ifndef _NETSURF_UTILS_TIME_H_
25#define _NETSURF_UTILS_TIME_H_
26
27#include <time.h>
28
29/**
30 * Write the time in seconds since epoch to a buffer.
31 *
32 * This is provided as strftime is not generally portable.
33 *
34 * @param str The destination buffer.
35 * @param size The length of the destination buffer.
36 * @param timep The pointer to the time to write.
37 * @return The length of the string written.
38 */
39int nsc_sntimet(char *str, size_t size, time_t *timep);
40
41/**
42 * Parse time in seconds since epoc.
43 *
44 * This is provided as strptime is not generally portable.
45 *
46 * @param str The source buffer.
47 * @param size The length of the source buffer.
48 * @param timep Pointer to result.
49 * @return NSERROR_OK on success or error code on faliure.
50 */
51nserror nsc_snptimet(const char *str, size_t size, time_t *timep);
52
53
54/**
55 * Converts a date string to a number of seconds since epoch
56 *
57 * returns the number of seconds since the Epoch, January 1st 1970
58 * 00:00:00 in the UTC time zone, for the date and time that the
59 * \a str parameter specifies.
60 *
61 * datetime strings passed must be in one of the formats specified in:
62 * - RFC 822 (updated in RFC 1123) using time zone name or time zone delta
63 * - RFC 850 (obsoleted by RFC 1036)
64 * - ANSI C's asctime() format.
65 *
66 * @param[in] str The datetime string to parse
67 * @param[in] size The length of the source string
68 * @param[out] timep Pointer to result on success unmodified on error.
69 * @return NSERROR_OK on success and timep updated else
70 * NSERROR_INVALID if the string parsing failed otherwise a suitable
71 * error code
72 */
73nserror nsc_strntimet(const char *str, size_t size, time_t *timep);
74
75/**
76 * Create an RFC 1123 compliant date string from a Unix timestamp
77 *
78 * \param t The timestamp to consider
79 * \return Pointer to buffer containing string - invalidated by next call.
80 */
81const char *rfc1123_date(time_t t);
82
83#endif
nserror
Enumeration of error codes.
Definition: errors.h:29
Interface to time operations.
int nsc_sntimet(char *str, size_t size, time_t *timep)
Write the time in seconds since epoch to a buffer.
Definition: time.c:126
nserror nsc_strntimet(const char *str, size_t size, time_t *timep)
Converts a date string to a number of seconds since epoch.
Definition: time.c:980
nserror nsc_snptimet(const char *str, size_t size, time_t *timep)
Parse time in seconds since epoc.
Definition: time.c:147
const char * rfc1123_date(time_t t)
Create an RFC 1123 compliant date string from a Unix timestamp.
Definition: time.c:110