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
6412efb6
Commit
6412efb6
authored
Aug 19, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time/ISO8601: allow omitting the time of day
parent
995783bb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
4 deletions
+29
-4
NEWS
NEWS
+1
-0
ISO8601.cxx
src/time/ISO8601.cxx
+22
-4
TestISO8601.cxx
test/TestISO8601.cxx
+6
-0
No files found.
NEWS
View file @
6412efb6
...
...
@@ -3,6 +3,7 @@ ver 0.22 (not yet released)
- "findadd"/"searchadd"/"searchaddpl" support the "sort" and
"window" parameters
- add command "readpicture" to download embedded pictures
- relax the ISO 8601 parser: allow omitting the time of day
* tags
- new tags "Grouping" (for ID3 "TIT1") and "Work"
* input
...
...
src/time/ISO8601.cxx
View file @
6412efb6
...
...
@@ -70,14 +70,32 @@ ParseISO8601(const char *s)
throw
std
::
runtime_error
(
"Time parsing not implemented on Windows"
);
#else
struct
tm
tm
{};
const
char
*
end
=
strptime
(
s
,
"%FT%TZ"
,
&
tm
);
if
(
end
==
nullptr
||
*
end
!=
0
)
throw
std
::
runtime_error
(
"Failed to parse time stamp"
);
std
::
chrono
::
system_clock
::
duration
precision
=
std
::
chrono
::
seconds
(
1
);
/* parse the date */
const
char
*
end
=
strptime
(
s
,
"%F"
,
&
tm
);
if
(
end
==
nullptr
)
throw
std
::
runtime_error
(
"Failed to parse date"
);
s
=
end
;
std
::
chrono
::
system_clock
::
duration
precision
=
std
::
chrono
::
hours
(
24
);
/* parse the time of day */
if
(
*
s
==
'T'
)
{
++
s
;
end
=
strptime
(
s
,
"%TZ"
,
&
tm
);
if
(
end
==
nullptr
)
throw
std
::
runtime_error
(
"Failed to parse time of day"
);
s
=
end
;
precision
=
std
::
chrono
::
seconds
(
1
);
}
auto
tp
=
TimeGm
(
tm
);
if
(
*
s
!=
0
)
throw
std
::
runtime_error
(
"Garbage at end of time stamp"
);
return
std
::
make_pair
(
tp
,
precision
);
#endif
/* !_WIN32 */
}
test/TestISO8601.cxx
View file @
6412efb6
...
...
@@ -45,6 +45,12 @@ static constexpr struct {
{
"2019-02-04T16:46:41Z"
,
1549298801
,
std
::
chrono
::
seconds
(
1
)
},
{
"2018-12-31T23:59:59Z"
,
1546300799
,
std
::
chrono
::
seconds
(
1
)
},
{
"2019-01-01T00:00:00Z"
,
1546300800
,
std
::
chrono
::
seconds
(
1
)
},
/* only date */
{
"1970-01-01"
,
0
,
std
::
chrono
::
hours
(
24
)
},
{
"2019-02-04"
,
1549238400
,
std
::
chrono
::
hours
(
24
)
},
{
"2018-12-31"
,
1546214400
,
std
::
chrono
::
hours
(
24
)
},
{
"2019-01-01"
,
1546300800
,
std
::
chrono
::
hours
(
24
)
},
};
TEST
(
ISO8601
,
Parse
)
...
...
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