Bug 19816: Implement dateonly for rfc3339 format

This patch implements the dateonly option for the rfc3339. This is
described in the OpenAPI 2.0 specification [1]. The required output
format is described on RFC 3339 [2], as 'full-date'.

[1] https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat
[2] https://tools.ietf.org/html/rfc3339#section-5.6

To test:
- Apply the regression tests patch
- Run:
 k$ prove t/DateUtils.t
=> FAIL: Tests fail because dateonly is not implemented
- Apply this patch
- Run:
 k$ prove t/DateUtils.t
=> SUCCESS: Tests pass!
- Sign off :-D

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit b2dce05ddf)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2019-01-24 14:29:09 -03:00 committed by Martin Renvoize
parent 41115fc79d
commit dcc0478089
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 7 additions and 2 deletions

View File

@ -254,8 +254,13 @@ sub output_pref {
: $dt->strftime("%Y-%m-%d $time");
}
elsif ( $pref =~ m/^rfc3339/ ) {
$date = $dt->strftime('%FT%T%z');
substr($date, -2, 0, ':'); # timezone "HHmm" => "HH:mm"
if (!$dateonly) {
$date = $dt->strftime('%FT%T%z');
substr($date, -2, 0, ':'); # timezone "HHmm" => "HH:mm"
}
else {
$date = $dt->strftime("%Y-%m-%d");
}
}
elsif ( $pref =~ m/^metric/ ) {
$date = $dateonly