Skip to content

Commit 05f2d96

Browse files
authored
Merge pull request #116 from wmde/timeValueGetters
Remove unused getters from TimeValue
2 parents 1f9e9ee + 7040bee commit 05f2d96

File tree

1 file changed

+20
-84
lines changed

1 file changed

+20
-84
lines changed

src/values/TimeValue.js

Lines changed: 20 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,24 @@ var PARENT = dv.DataValue;
4848
* @throws {Error} if `timestamp` is not a valid YMD-ordered timestamp string resembling ISO 8601.
4949
*/
5050
var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timestamp, options ) {
51-
this._time = {};
52-
5351
try {
5452
var matches = /^([-+]?\d+)-(\d+)-(\d+)T(?:(\d+):(\d+)(?::(\d+))?Z?)?$/.exec( timestamp );
5553

5654
// Strip additional leading zeros from the year, but keep 4 digits.
57-
this._time.year = matches[1].replace( /\b0+(?=\d{4})/, '' );
58-
this._time.month = parseInt( matches[2], 10 );
59-
this._time.day = parseInt( matches[3], 10 );
60-
this._time.hour = parseInt( matches[4] || 0, 10 );
61-
this._time.minute = parseInt( matches[5] || 0, 10 );
62-
this._time.second = parseInt( matches[6] || 0, 10 );
55+
var year = matches[1].replace( /\b0+(?=\d{4})/, '' ),
56+
month = parseInt( matches[2], 10 ),
57+
day = parseInt( matches[3], 10 ),
58+
hour = parseInt( matches[4] || 0, 10 ),
59+
minute = parseInt( matches[5] || 0, 10 ),
60+
second = parseInt( matches[6] || 0, 10 );
61+
62+
this.timestamp = ( year.charAt( 0 ) === '-' ? '-' : '+' )
63+
+ pad( year, 4 ) + '-'
64+
+ pad( month, 2 ) + '-'
65+
+ pad( day, 2 ) + 'T'
66+
+ pad( hour, 2 ) + ':'
67+
+ pad( minute, 2 ) + ':'
68+
+ pad( second, 2 ) + 'Z';
6369
} catch( e ) {
6470
throw new Error( 'Unable to process timestamp "' + timestamp + '"' );
6571
}
@@ -79,10 +85,10 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timesta
7985
} );
8086
}, {
8187
/**
82-
* @property {Object}
88+
* @property {string}
8389
* @private
8490
*/
85-
_time: null,
91+
timestamp: null,
8692

8793
/**
8894
* @property {Object}
@@ -130,7 +136,9 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timesta
130136
* @return {string}
131137
*/
132138
getSortKey: function() {
133-
return this._getTimestamp( true );
139+
return this.timestamp.replace( /^([+-])(\d+)/, function ( $0, sign, year ) {
140+
return sign + pad( year, 16 );
141+
} );
134142
},
135143

136144
/**
@@ -142,60 +150,6 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timesta
142150
return this.toJSON();
143151
},
144152

145-
/**
146-
* @since 0.7
147-
*
148-
* @return {string}
149-
*/
150-
getYear: function() {
151-
return this._time.year;
152-
},
153-
154-
/**
155-
* @since 0.7
156-
*
157-
* @return {number}
158-
*/
159-
getMonth: function() {
160-
return this._time.month;
161-
},
162-
163-
/**
164-
* @since 0.7
165-
*
166-
* @return {number}
167-
*/
168-
getDay: function() {
169-
return this._time.day;
170-
},
171-
172-
/**
173-
* @since 0.7
174-
*
175-
* @return {number}
176-
*/
177-
getHour: function() {
178-
return this._time.hour;
179-
},
180-
181-
/**
182-
* @since 0.7
183-
*
184-
* @return {number}
185-
*/
186-
getMinute: function() {
187-
return this._time.minute;
188-
},
189-
190-
/**
191-
* @since 0.7
192-
*
193-
* @return {number}
194-
*/
195-
getSecond: function() {
196-
return this._time.second;
197-
},
198-
199153
/**
200154
* @inheritdoc
201155
*/
@@ -217,24 +171,6 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timesta
217171
return match;
218172
},
219173

220-
/**
221-
* @private
222-
*
223-
* @param {boolean} [padYear=false] True if the year should be padded to the maximum length of
224-
* 16 digits, false for the default padding to 4 digits.
225-
*
226-
* @return {string} A YMD-ordered timestamp string resembling ISO 8601.
227-
*/
228-
_getTimestamp: function( padYear ) {
229-
return ( this._time.year.charAt( 0 ) === '-' ? '-' : '+' )
230-
+ pad( this._time.year, padYear ? 16 : 4 ) + '-'
231-
+ pad( this._time.month, 2 ) + '-'
232-
+ pad( this._time.day, 2 ) + 'T'
233-
+ pad( this._time.hour, 2 ) + ':'
234-
+ pad( this._time.minute, 2 ) + ':'
235-
+ pad( this._time.second, 2 ) + 'Z';
236-
},
237-
238174
/**
239175
* @inheritdoc
240176
*
@@ -246,7 +182,7 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( timesta
246182
before: this._options.before,
247183
calendarmodel: this._options.calendarModel,
248184
precision: this._options.precision,
249-
time: this._getTimestamp(),
185+
time: this.timestamp,
250186
timezone: this._options.timezone
251187
};
252188
}

0 commit comments

Comments
 (0)