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#include <string>
20#include <iosfwd>
21
22struct date_t
23{
24 // For the benefit of the --date option.
25 date_t() : d("") {}
26 bool valid() const { return d != ""; }
27
28 // Return the local system's idea of the current date.
29 static date_t now();
30
31 // Return the date corresponding to an unsigned 64-bit count of seconds
32 // since the Unix epoch (1970-01-01T00:00:00).
33 static date_t from_unix_epoch(u64);
34
35 // Return the date corresponding to a string. Presently this recognizes
36 // only ISO 8601 "basic" and "extended" time formats.
37 static date_t from_string(std::string const &);
38
39 // Write out date as a string.
40 std::string const & as_iso_8601_extended() const;
41
42private:
43 // For what we do with dates, it is most convenient to store them as
44 // strings in the ISO 8601 extended time format.
45 std::string d;
46
47 // used by the above factory functions
48 date_t(std::string const & s) : d(s) {};
49};
50
51std::ostream & operator<< (std::ostream & o, date_t const & d);
52template <> void dump(date_t const & d, std::string & s);
53
54#endif // dates.hh
55
56// Local Variables:
57// mode: C++
58// fill-column: 76
59// c-file-style: "gnu"
60// indent-tabs-mode: nil
61// End:
62// 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