ASAP  1.0.0
A C++ header-only library for creating, displaying, iterating and manipulating dates
period.h
1 /* * Copyright (C) 2018 Leonardo Guilherme Lucena de Freitas
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy of
4  * this software and associated documentation files (the "Software"), to deal in
5  * the Software without restriction, including without limitation the rights to
6  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7  * the Software, and to permit persons to whom the Software is furnished to do so,
8  * subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all
11  * copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef ASAP_RANGE_H
22 #define ASAP_RANGE_H
23 
24 #include "datetime.h"
25 #include "operators.h"
26 
27 namespace asap {
28  class period;
29  namespace detail { template <uint64_t T> class accessor; }
30 
31  class period {
32  public:
33  explicit period(const asap::datetime & a = asap::datetime(), const asap::datetime & b = asap::datetime());
34  const asap::datetime & from() const;
35  void from(const asap::datetime & begin);
36 
37  const asap::datetime & to() const;
38  void to(const asap::datetime & end);
39 
45  template<typename T> T difference() const;
46 
51  asap::seconds difference() const;
52 
53  template<uint64_t stepconv>
54  asap::detail::accessor<stepconv> every(const asap::duration<stepconv> & d) const;
55 
56  private:
57  asap::datetime begin_;
58  asap::datetime end_;
59  };
60 }
61 
62 #endif //ASAP_RANGE_H
asap::detail::accessor< stepconv > every(const asap::duration< stepconv > &d) const
Returns an accessor that can be used to iterate between the beginning and the end dates...
const asap::datetime & from() const
Returns an asap::datetime instance marking the beginning of the period.
period(const asap::datetime &a=asap::datetime(), const asap::datetime &b=asap::datetime())
Creates a new peeriod starting at a and ending at b.
The asap::datetime class exposes methods to create, manipulate and print dates.
Definition: datetime.h:29
const asap::datetime & to() const
Returns an asap::datetime instance marking the end of the period.
The asap::duration class exposes methods to create, manipulate and print durations.
Definition: duration.h:28
The asap::period class is a bound period, with starting and ending dates. Its purpose is to provide d...
Definition: period.h:31
Definition: asap.h:38
T difference() const
Calculates the difference between the start and the end.