Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/date/utcdatetime.js
2868 views
1
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Locale independent date/time class.
17
*
18
*/
19
20
goog.provide('goog.date.UtcDateTime');
21
22
goog.require('goog.date');
23
goog.require('goog.date.Date');
24
goog.require('goog.date.DateTime');
25
goog.require('goog.date.Interval');
26
27
28
29
/**
30
* Class representing a date/time in GMT+0 time zone, without daylight saving.
31
* Defaults to current date and time if none is specified. The get... and the
32
* getUTC... methods are equivalent.
33
*
34
* @param {number|goog.date.DateLike=} opt_year Four digit UTC year or a
35
* date-like object. If not set, the created object will contain the
36
* date determined by goog.now().
37
* @param {number=} opt_month UTC month, 0 = Jan, 11 = Dec.
38
* @param {number=} opt_date UTC date of month, 1 - 31.
39
* @param {number=} opt_hours UTC hours, 0 - 23.
40
* @param {number=} opt_minutes UTC minutes, 0 - 59.
41
* @param {number=} opt_seconds UTC seconds, 0 - 59.
42
* @param {number=} opt_milliseconds UTC milliseconds, 0 - 999.
43
* @constructor
44
* @struct
45
* @extends {goog.date.DateTime}
46
*/
47
goog.date.UtcDateTime = function(
48
opt_year, opt_month, opt_date, opt_hours, opt_minutes, opt_seconds,
49
opt_milliseconds) {
50
var timestamp;
51
if (goog.isNumber(opt_year)) {
52
timestamp = Date.UTC(
53
opt_year, opt_month || 0, opt_date || 1, opt_hours || 0,
54
opt_minutes || 0, opt_seconds || 0, opt_milliseconds || 0);
55
} else {
56
timestamp = opt_year ? opt_year.getTime() : goog.now();
57
}
58
this.date = new Date(timestamp);
59
};
60
goog.inherits(goog.date.UtcDateTime, goog.date.DateTime);
61
62
63
/**
64
* @param {number} timestamp Number of milliseconds since Epoch.
65
* @return {!goog.date.UtcDateTime}
66
*/
67
goog.date.UtcDateTime.fromTimestamp = function(timestamp) {
68
var date = new goog.date.UtcDateTime();
69
date.setTime(timestamp);
70
return date;
71
};
72
73
74
/**
75
* Creates a DateTime from a UTC datetime string expressed in ISO 8601 format.
76
*
77
* @param {string} formatted A date or datetime expressed in ISO 8601 format.
78
* @return {goog.date.UtcDateTime} Parsed date or null if parse fails.
79
*/
80
goog.date.UtcDateTime.fromIsoString = function(formatted) {
81
var ret = new goog.date.UtcDateTime(2000);
82
return goog.date.setIso8601DateTime(ret, formatted) ? ret : null;
83
};
84
85
86
/**
87
* Clones the UtcDateTime object.
88
*
89
* @return {!goog.date.UtcDateTime} A clone of the datetime object.
90
* @override
91
*/
92
goog.date.UtcDateTime.prototype.clone = function() {
93
var date = new goog.date.UtcDateTime(this.date);
94
date.setFirstDayOfWeek(this.getFirstDayOfWeek());
95
date.setFirstWeekCutOffDay(this.getFirstWeekCutOffDay());
96
return date;
97
};
98
99
100
/** @override */
101
goog.date.UtcDateTime.prototype.add = function(interval) {
102
if (interval.years || interval.months) {
103
var yearsMonths = new goog.date.Interval(interval.years, interval.months);
104
goog.date.Date.prototype.add.call(this, yearsMonths);
105
}
106
var daysAndTimeMillis = 1000 *
107
(interval.seconds +
108
60 * (interval.minutes + 60 * (interval.hours + 24 * interval.days)));
109
this.date = new Date(this.date.getTime() + daysAndTimeMillis);
110
};
111
112
113
/** @override */
114
goog.date.UtcDateTime.prototype.getTimezoneOffset = function() {
115
return 0;
116
};
117
118
119
/** @override */
120
goog.date.UtcDateTime.prototype.getFullYear =
121
goog.date.DateTime.prototype.getUTCFullYear;
122
123
124
/** @override */
125
goog.date.UtcDateTime.prototype.getMonth =
126
goog.date.DateTime.prototype.getUTCMonth;
127
128
129
/** @override */
130
goog.date.UtcDateTime.prototype.getDate =
131
goog.date.DateTime.prototype.getUTCDate;
132
133
134
/** @override */
135
goog.date.UtcDateTime.prototype.getHours =
136
goog.date.DateTime.prototype.getUTCHours;
137
138
139
/** @override */
140
goog.date.UtcDateTime.prototype.getMinutes =
141
goog.date.DateTime.prototype.getUTCMinutes;
142
143
144
/** @override */
145
goog.date.UtcDateTime.prototype.getSeconds =
146
goog.date.DateTime.prototype.getUTCSeconds;
147
148
149
/** @override */
150
goog.date.UtcDateTime.prototype.getMilliseconds =
151
goog.date.DateTime.prototype.getUTCMilliseconds;
152
153
154
/** @override */
155
goog.date.UtcDateTime.prototype.getDay = goog.date.DateTime.prototype.getUTCDay;
156
157
158
/** @override */
159
goog.date.UtcDateTime.prototype.setFullYear =
160
goog.date.DateTime.prototype.setUTCFullYear;
161
162
163
/** @override */
164
goog.date.UtcDateTime.prototype.setMonth =
165
goog.date.DateTime.prototype.setUTCMonth;
166
167
168
/** @override */
169
goog.date.UtcDateTime.prototype.setDate =
170
goog.date.DateTime.prototype.setUTCDate;
171
172
173
/** @override */
174
goog.date.UtcDateTime.prototype.setHours =
175
goog.date.DateTime.prototype.setUTCHours;
176
177
178
/** @override */
179
goog.date.UtcDateTime.prototype.setMinutes =
180
goog.date.DateTime.prototype.setUTCMinutes;
181
182
183
/** @override */
184
goog.date.UtcDateTime.prototype.setSeconds =
185
goog.date.DateTime.prototype.setUTCSeconds;
186
187
188
/** @override */
189
goog.date.UtcDateTime.prototype.setMilliseconds =
190
goog.date.DateTime.prototype.setUTCMilliseconds;
191
192