Updated Examples and Recipes (markdown)

Emile Cormier
2015-07-30 16:02:17 -03:00
parent 125f2f0583
commit b78c13b23f

@@ -2,14 +2,34 @@
- [Obtaining a `time_point` from `y/m/d h:m:s` components](#time_point_to_components)
- [Obtaining `y/m/d h:m:s` components from a `time_point`](#components_to_time_point)
===
***
<a name="time_point_to_components"></a>
### Obtaining a `time_point` from `y/m/d h:m:s` components
See http://stackoverflow.com/questions/31711782.
Write me
```c++
using namespace std::chrono;
using namespace date;
// Component values (as obtained from an UI form, for example)
int y=2015, m=7, d=30, h=12, min=34, s=56;
system_clock::time_point = day_point(year(y)/m/d) + hours(h) + minutes(min) + seconds(s);
```
<a name="components_to_time_point">
### Obtaining `y/m/d h:m:s` components from a `time_point`
Write me
```c++
using namespace date;
auto daypoint = floor<days>(time);
auto ymd = year_month_day(daypoint); // calendar date
auto tod = make_time(time - daypoint); // Yields time_of_day type
// Obtain individual components as integers
auto y = int(ymd.year());
auto m = unsigned(ymd.month());
auto d = unsigned(ymd.day());
auto h = tod.hours().count();
auto min = tod.minutes().count();
auto s = tod.seconds().count();
```