mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 08:31:03 +08:00
Fix and test format %y
This commit is contained in:
parent
a5450e9d02
commit
8a3aeb566b
2
date.h
2
date.h
@ -4676,7 +4676,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
|
|||||||
}
|
}
|
||||||
else if (modified == CharT{})
|
else if (modified == CharT{})
|
||||||
{
|
{
|
||||||
y %= 100;
|
y = std::abs(y) % 100;
|
||||||
if (y < 10)
|
if (y < 10)
|
||||||
os << CharT{'0'};
|
os << CharT{'0'};
|
||||||
os << y;
|
os << y;
|
||||||
|
@ -26,14 +26,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
using fortnights = std::chrono::duration<date::weeks::rep,
|
|
||||||
std::ratio_multiply<std::ratio<2>,
|
|
||||||
date::weeks::period>>;
|
|
||||||
|
|
||||||
using microfortnights = std::chrono::duration<std::int64_t,
|
|
||||||
std::ratio_multiply<fortnights::period,
|
|
||||||
std::micro>>;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
121
test/date_test/format/two_dight_year.pass.cpp
Normal file
121
test/date_test/format/two_dight_year.pass.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
// The MIT License (MIT)
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016 Howard Hinnant
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include "date.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
using namespace date;
|
||||||
|
using namespace std::chrono;
|
||||||
|
std::ostringstream os;
|
||||||
|
os << format("%y", sys_days{jun/1/20001});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/20000});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/19999});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/2001});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/2000});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/1999});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/101});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/100});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/99});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/1});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/0});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-1});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-99});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-100});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-101});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-1999});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-2000});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-2001});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-19999});
|
||||||
|
assert(os.str() == "99");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-20000});
|
||||||
|
assert(os.str() == "00");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/-20001});
|
||||||
|
assert(os.str() == "01");
|
||||||
|
|
||||||
|
os.str("");
|
||||||
|
os << format("%y", sys_days{jun/1/year::min()});
|
||||||
|
assert(os.str() == "68");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user