Skip to content

Commit

Permalink
Merge pull request #1326.
Browse files Browse the repository at this point in the history
Simpler output for periods.
  • Loading branch information
lballabio authored Mar 15, 2022
2 parents 8a832f6 + 857fd1c commit 1f70a67
Showing 1 changed file with 4 additions and 38 deletions.
42 changes: 4 additions & 38 deletions ql/time/period.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,30 +396,13 @@ namespace QuantLib {
std::ostream& operator<<(std::ostream& out,
const long_period_holder& holder) {
Integer n = holder.p.length();
Integer m = 0;
switch (holder.p.units()) {
case Days:
if (n>=7) {
m = n/7;
out << m << (m == 1 ? " week " : " weeks ");
n = n%7;
}
if (n != 0 || m == 0)
return out << n << (n == 1 ? " day" : " days");
else
return out;
return out << n << (n == 1 ? " day" : " days");
case Weeks:
return out << n << (n == 1 ? " week" : " weeks");
case Months:
if (n>=12) {
m = n/12;
out << m << (m == 1 ? " year " : " years ");
n = n%12;
}
if (n != 0 || m == 0)
return out << n << (n == 1 ? " month" : " months");
else
return out;
return out << n << (n == 1 ? " month" : " months");
case Years:
return out << n << (n == 1 ? " year" : " years");
default:
Expand All @@ -430,30 +413,13 @@ namespace QuantLib {
std::ostream& operator<<(std::ostream& out,
const short_period_holder& holder) {
Integer n = holder.p.length();
Integer m = 0;
switch (holder.p.units()) {
case Days:
if (n>=7) {
m = n/7;
out << m << "W";
n = n%7;
}
if (n != 0 || m == 0)
return out << n << "D";
else
return out;
return out << n << "D";
case Weeks:
return out << n << "W";
case Months:
if (n>=12) {
m = n/12;
out << n/12 << "Y";
n = n%12;
}
if (n != 0 || m == 0)
return out << n << "M";
else
return out;
return out << n << "M";
case Years:
return out << n << "Y";
default:
Expand Down

0 comments on commit 1f70a67

Please sign in to comment.