1 // Copyright (c) 2014-2020 Thomas Fussell
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all 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,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE
20 //
21 // @license: http://www.opensource.org/licenses/mit-license.php
22 // @author: see AUTHORS file
23 
24 #pragma once
25 
26 #include <string>
27 
28 #include <xlnt/xlnt_config.hpp>
29 
30 namespace xlnt {
31 
32 /// <summary>
33 /// A time is a specific time of the day specified in terms of an hour,
34 /// minute, second, and microsecond (0-999999).
35 /// It can also be initialized as a fraction of a day using time::from_number.
36 /// </summary>
37 struct XLNT_API time
38 {
39     /// <summary>
40     /// Return the current time according to the system time.
41     /// </summary>
42     static time now();
43 
44     /// <summary>
45     /// Return a time from a number representing a fraction of a day.
46     /// The integer part of number will be ignored.
47     /// 0.5 would return time(12, 0, 0, 0) or noon, halfway through the day.
48     /// </summary>
49     static time from_number(double number);
50 
51     /// <summary>
52     /// Constructs a time object from an optional hour, minute, second, and microsecond.
53     /// </summary>
54     explicit time(int hour_ = 0, int minute_ = 0, int second_ = 0, int microsecond_ = 0);
55 
56     /// <summary>
57     /// Constructs a time object from a string representing the time.
58     /// </summary>
59     explicit time(const std::string &time_string);
60 
61     /// <summary>
62     /// Returns a numeric representation of the time in the range 0-1 where the value
63     /// is equal to the fraction of the day elapsed.
64     /// </summary>
65     double to_number() const;
66 
67     /// <summary>
68     /// Returns true if this time is equivalent to comparand.
69     /// </summary>
70     bool operator==(const time &comparand) const;
71 
72     /// <summary>
73     /// The hour
74     /// </summary>
75     int hour;
76 
77     /// <summary>
78     /// The minute
79     /// </summary>
80     int minute;
81 
82     /// <summary>
83     /// The second
84     /// </summary>
85     int second;
86 
87     /// <summary>
88     /// The microsecond
89     /// </summary>
90     int microsecond;
91 };
92 
93 } // namespace xlnt
94