Debian Codegraph @

js/src/builtin/temporal/PlainTime.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef builtin_temporal_PlainTime_h
8 #define builtin_temporal_PlainTime_h
9
10 #include "mozilla/Casting.h"
11
12 #include <stdint.h>
13
14 #include "builtin/temporal/TemporalTypes.h"
15 #include "js/TypeDecls.h"
16 #include "js/Value.h"
17 #include "vm/NativeObject.h"
18
19 namespace js {
20 struct ClassSpec;
21 }
22
23 namespace js::temporal {
24
25 class PlainTimeObject : public NativeObject {
26 public:
27 static const JSClass class_;
28 static const JSClass& protoClass_;
29
30 static constexpr uint32_t PACKED_TIME_SLOT = 0;
31 static constexpr uint32_t SLOT_COUNT = 1;
32
33 /**
34 * Extract the time fields from this PlainTime object.
35 */
36 Time time() const {
37 auto packed = PackedTime{mozilla::BitwiseCast<uint64_t>(
38 getFixedSlot(PACKED_TIME_SLOT).toDouble())};
39 return PackedTime::unpack(packed);
40 }
41
42 private:
43 static const ClassSpec classSpec_;
44 };
45
46 class Increment;
47 enum class TemporalOverflow;
48 enum class TemporalRoundingMode;
49 enum class TemporalUnit;
50
51 #ifdef DEBUG
52 /**
53 * IsValidTime ( hour, minute, second, millisecond, microsecond, nanosecond )
54 */
55 bool IsValidTime(const Time& time);
56
57 /**
58 * IsValidTime ( hour, minute, second, millisecond, microsecond, nanosecond )
59 */
60 bool IsValidTime(double hour, double minute, double second, double millisecond,
61 double microsecond, double nanosecond);
62 #endif
63
64 /**
65 * IsValidTime ( hour, minute, second, millisecond, microsecond, nanosecond )
66 */
67 bool ThrowIfInvalidTime(JSContext* cx, double hour, double minute,
68 double second, double millisecond, double microsecond,
69 double nanosecond);
70
71 /**
72 * CreateTemporalTime ( time [ , newTarget ] )
73 */
74 PlainTimeObject* CreateTemporalTime(JSContext* cx, const Time& time);
75
76 /**
77 * ToTemporalTime ( item [ , overflow ] )
78 */
79 bool ToTemporalTime(JSContext* cx, JS::Handle<JS::Value> item, Time* result);
80
81 struct TimeRecord final {
82 int64_t days = 0;
83 Time time;
84 };
85
86 /**
87 * AddTime ( time, timeDuration )
88 */
89 TimeRecord AddTime(const Time& time, const TimeDuration& duration);
90
91 /**
92 * DifferenceTime ( time1, time2 )
93 */
94 TimeDuration DifferenceTime(const Time& time1, const Time& time2);
95
96 struct TemporalTimeLike final {
97 double hour = 0;
98 double minute = 0;
99 double second = 0;
100 double millisecond = 0;
101 double microsecond = 0;
102 double nanosecond = 0;
103 };
104
105 /**
106 * RegulateTime ( hour, minute, second, millisecond, microsecond, nanosecond,
107 * overflow )
108 */
109 bool RegulateTime(JSContext* cx, const TemporalTimeLike& time,
110 TemporalOverflow overflow, Time* result);
111
112 /**
113 * CompareTimeRecord ( time1, time2 )
114 */
115 int32_t CompareTimeRecord(const Time& one, const Time& two);
116
117 /**
118 * BalanceTime ( hour, minute, second, millisecond, microsecond, nanosecond )
119 */
120 TimeRecord BalanceTime(const Time& time, int64_t nanoseconds);
121
122 /**
123 * RoundTime ( time, increment, unit, roundingMode )
124 */
125 TimeRecord RoundTime(const Time& time, Increment increment, TemporalUnit unit,
126 TemporalRoundingMode roundingMode);
127
128 } /* namespace js::temporal */
129
130 #endif /* builtin_temporal_PlainTime_h */