monotone

monotone Mtn Source Tree

Root/dates.hh

1// Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef DATES_HH
11#define DATES_HH
12
13// This file provides a straightforward wrapper class around the standard
14// C time functions. Note that all operations are done in UTC, *not* the
15// user's time zone.
16
17#include "numeric_vocab.hh"
18#include "sanity.hh"
19
20struct date_t
21{
22 // For the benefit of the --date option.
23 date_t() : d("") {}
24 bool valid() const { return d != ""; }
25
26 // Return the local system's idea of the current date.
27 static date_t now();
28
29 // Return the date corresponding to an unsigned 64-bit count of seconds
30 // since the Unix epoch (1970-01-01T00:00:00).
31 static date_t from_unix_epoch(u64);
32
33 // Return the date corresponding to a string. Presently this recognizes
34 // only ISO 8601 "basic" and "extended" time formats.
35 static date_t from_string(std::string const &);
36
37 // Write out date as a string.
38 std::string const & as_iso_8601_extended() const;
39
40private:
41 // For what we do with dates, it is most convenient to store them as
42 // strings in the ISO 8601 extended time format.
43 std::string d;
44
45 // used by the above factory functions
46 date_t(std::string const & s) : d(s) {};
47};
48
49std::ostream & operator<< (std::ostream & o, date_t const & d);
50template <> void dump(date_t const & d, std::string & s);
51
52#endif // dates.hh
53
54// Local Variables:
55// mode: C++
56// fill-column: 76
57// c-file-style: "gnu"
58// indent-tabs-mode: nil
59// End:
60// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status