Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
0c28d8dc
Commit
0c28d8dc
authored
Nov 23, 2020
by
Max Kellermann
Committed by
Max Kellermann
Nov 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time/ISO8601: support YYYY-MM (without day of month)
parent
764eaadd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
2 deletions
+24
-2
ISO8601.cxx
src/time/ISO8601.cxx
+18
-1
ISO8601.hxx
src/time/ISO8601.hxx
+1
-1
TestISO8601.cxx
test/time/TestISO8601.cxx
+5
-0
No files found.
src/time/ISO8601.cxx
View file @
0c28d8dc
/*
* Copyright 2007-20
19 Content Management AG
* Copyright 2007-20
20 CM4all GmbH
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
...
...
@@ -32,6 +32,7 @@
#include "ISO8601.hxx"
#include "Convert.hxx"
#include "Math.hxx"
#include "util/StringBuffer.hxx"
#include <cassert>
...
...
@@ -169,6 +170,13 @@ ParseTimeOfDay(const char *s, struct tm &tm,
return
end
;
}
static
bool
StrptimeFull
(
const
char
*
s
,
const
char
*
fmt
,
struct
tm
*
tm
)
noexcept
{
const
char
*
end
=
strptime
(
s
,
fmt
,
tm
);
return
end
!=
nullptr
&&
*
end
==
0
;
}
#endif
std
::
pair
<
std
::
chrono
::
system_clock
::
time_point
,
...
...
@@ -184,6 +192,15 @@ ParseISO8601(const char *s)
#else
struct
tm
tm
{};
if
(
StrptimeFull
(
s
,
"%Y-%m"
,
&
tm
))
{
/* full month */
tm
.
tm_mday
=
1
;
const
auto
start
=
TimeGm
(
tm
);
EndOfMonth
(
tm
);
const
auto
end
=
TimeGm
(
tm
);
return
{
start
,
end
-
start
};
}
/* parse the date */
const
char
*
end
=
strptime
(
s
,
"%F"
,
&
tm
);
if
(
end
==
nullptr
)
{
...
...
src/time/ISO8601.hxx
View file @
0c28d8dc
/*
* Copyright 2007-20
19 Content Management AG
* Copyright 2007-20
20 CM4all GmbH
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
...
...
test/time/TestISO8601.cxx
View file @
0c28d8dc
...
...
@@ -46,6 +46,11 @@ static constexpr struct {
{
"2018-12-31T23:59:59Z"
,
1546300799
,
std
::
chrono
::
seconds
(
1
)
},
{
"2019-01-01T00:00:00Z"
,
1546300800
,
std
::
chrono
::
seconds
(
1
)
},
/* full month */
{
"1970-01"
,
0
,
std
::
chrono
::
hours
(
24
*
31
)
},
{
"2019-02"
,
1548979200
,
std
::
chrono
::
hours
(
24
*
28
)
},
{
"2019-01"
,
1546300800
,
std
::
chrono
::
hours
(
24
*
31
)
},
/* only date */
{
"1970-01-01"
,
0
,
std
::
chrono
::
hours
(
24
)
},
{
"2019-02-04"
,
1549238400
,
std
::
chrono
::
hours
(
24
)
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment