1//
2// DateTimeFormat.h
3//
4// Library: Foundation
5// Package: DateTime
6// Module: DateTimeFormat
7//
8// Definition of the DateTimeFormat class.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_DateTimeFormat_INCLUDED
18#define Foundation_DateTimeFormat_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include <unordered_set>
23
24
25namespace Poco {
26
27
28class RegularExpression;
29
30
31class Foundation_API DateTimeFormat
32 /// Definition of date/time formats and various
33 /// constants used by DateTimeFormatter and DateTimeParser.
34{
35public:
36
37 // predefined date formats
38 static const std::string ISO8601_FORMAT;
39 /// The date/time format defined in the ISO 8601 standard.
40 ///
41 /// Examples:
42 /// 2005-01-01T12:00:00+01:00
43 /// 2005-01-01T11:00:00Z
44
45 static const std::string ISO8601_REGEX;
46
47 static const std::string ISO8601_FRAC_FORMAT;
48 /// The date/time format defined in the ISO 8601 standard,
49 /// with fractional seconds.
50 ///
51 /// Examples:
52 /// 2005-01-01T12:00:00.000000+01:00
53 /// 2005-01-01T11:00:00.000000Z
54
55 static const std::string RFC822_FORMAT;
56 /// The date/time format defined in RFC 822 (obsoleted by RFC 1123).
57 ///
58 /// Examples:
59 /// Sat, 1 Jan 05 12:00:00 +0100
60 /// Sat, 1 Jan 05 11:00:00 GMT
61
62 static const std::string RFC822_REGEX;
63
64 static const std::string RFC1123_FORMAT;
65 /// The date/time format defined in RFC 1123 (obsoletes RFC 822).
66 ///
67 /// Examples:
68 /// Sat, 1 Jan 2005 12:00:00 +0100
69 /// Sat, 1 Jan 2005 11:00:00 GMT
70
71 static const std::string RFC1123_REGEX;
72
73 static const std::string HTTP_FORMAT;
74 /// The date/time format defined in the HTTP specification (RFC 2616),
75 /// which is basically a variant of RFC 1036 with a zero-padded day field.
76 ///
77 /// Examples:
78 /// Sat, 01 Jan 2005 12:00:00 +0100
79 /// Sat, 01 Jan 2005 11:00:00 GMT
80
81 static const std::string HTTP_REGEX;
82
83 static const std::string RFC850_FORMAT;
84 /// The date/time format defined in RFC 850 (obsoleted by RFC 1036).
85 ///
86 /// Examples:
87 /// Saturday, 1-Jan-05 12:00:00 +0100
88 /// Saturday, 1-Jan-05 11:00:00 GMT
89
90 static const std::string RFC850_REGEX;
91
92 static const std::string RFC1036_FORMAT;
93 /// The date/time format defined in RFC 1036 (obsoletes RFC 850).
94 ///
95 /// Examples:
96 /// Saturday, 1 Jan 05 12:00:00 +0100
97 /// Saturday, 1 Jan 05 11:00:00 GMT
98
99 static const std::string RFC1036_REGEX;
100
101 static const std::string ASCTIME_FORMAT;
102 /// The date/time format produced by the ANSI C asctime() function.
103 ///
104 /// Example:
105 /// Sat Jan 1 12:00:00 2005
106
107 static const std::string ASCTIME_REGEX;
108
109 static const std::string SORTABLE_FORMAT;
110 /// A simple, sortable date/time format.
111 ///
112 /// Example:
113 /// 2005-01-01 12:00:00
114
115 static const std::string SORTABLE_REGEX;
116
117 // names used by formatter and parser
118 static const std::string WEEKDAY_NAMES[7];
119 /// English names of week days (Sunday, Monday, Tuesday, ...).
120
121 static const std::string MONTH_NAMES[12];
122 /// English names of months (January, February, ...).
123
124 static bool hasFormat(const std::string& fmt);
125 /// Returns true if fmt is a known standard format.
126
127 static bool isValid(const std::string& dateTime);
128 /// Returns true if dateTime validates against at least one supported format.
129
130 typedef std::unordered_set<const std::string*> RegexList;
131 static RegexList REGEX_LIST;
132
133private:
134 typedef std::unordered_set<std::string> Formatlist;
135 static Formatlist FORMAT_LIST;
136};
137
138
139} // namespace Poco
140
141
142#endif // Foundation_DateTimeFormat_INCLUDED
143