Updated Examples and Recipes (markdown)

HowardHinnant
2015-08-01 20:54:23 -04:00
parent 4134a6731a
commit 8f1860b593

@@ -104,7 +104,7 @@ std::cout << t.tm_year << "-" << t.tm_mon << "-" << t.tm_day << " ";
### Normalizing `y/m/d` when it is `!ok()` ### Normalizing `y/m/d` when it is `!ok()`
(by [Howard Hinnant](https://github.com/HowardHinnant)) (by [Howard Hinnant](https://github.com/HowardHinnant))
The following function will "normalize" a `year_month_day`, much like `mktime` normalizes a `tm`. This function is not part of the library, but is offered as an example if you find your self needing things like this: The following function will "normalize" a `year_month_day`, much like `mktime` normalizes a `tm`. This function is not part of the library, but is offered as an example if you find yourself needing things like this:
date::year_month_day date::year_month_day
normalize(date::year_month_day ymd) normalize(date::year_month_day ymd)
@@ -115,7 +115,7 @@ The following function will "normalize" a `year_month_day`, much like `mktime` n
return ymd; return ymd;
} }
The first line simply adds 0 months to the `ymd`. If `ymd.month()` is 0, with will subtract one from the `year` and set the month to `Dec`. If `ymd.month()` is greater than 12, the year will be incremented as many times as appropriate, and the month will be brought within the proper range. This operation will do nothing if `ymd.month().ok()` is already true. The first line simply adds 0 months to the `ymd`. If `ymd.month()` is 0, this will subtract one from the `year` and set the month to `Dec`. If `ymd.month()` is greater than 12, the year will be incremented as many times as appropriate, and the month will be brought within the proper range. This operation will do nothing if `ymd.month().ok()` is already true.
The second line will "normalize" the day field. The second line requires that the month field is already normalized. For example `2015_y/dec/32` will become `2016_y/jan/1`. If the day field is already in range, there will be no change. The second line will "normalize" the day field. The second line requires that the month field is already normalized. For example `2015_y/dec/32` will become `2016_y/jan/1`. If the day field is already in range, there will be no change.