@@ -29,16 +29,6 @@ var moment = Moment.load();
29
29
var VALID_UNITS = [ 'year' , 'month' , 'week' , 'day' , 'hour' , 'minute' , 'second' ,
30
30
'millisecond' ] ;
31
31
32
- /**
33
- * The epoch date used by Google Sheets.
34
- */
35
- var SHEETS_EPOCH = '12/30/1899 0:00:00' ;
36
-
37
- /**
38
- * The number of seconds in a day.
39
- */
40
- var SECONDS_PER_DAY = 86400 ;
41
-
42
32
/**
43
33
* Runs when the add-on is installed.
44
34
*/
@@ -65,7 +55,7 @@ function use() {
65
55
var title = 'Date Custom Functions' ;
66
56
var message = 'The functions DATEADD and DATESUBTRACT are now available in ' +
67
57
'this spreadsheet. More information is available in the function help ' +
68
- 'box that appears when you start using them in a forumula .' ;
58
+ 'box that appears when you start using them in a formula .' ;
69
59
var ui = SpreadsheetApp . getUi ( ) ;
70
60
ui . alert ( title , message , ui . ButtonSet . OK ) ;
71
61
}
@@ -82,7 +72,6 @@ function use() {
82
72
* @customFunction
83
73
*/
84
74
function DATEADD ( date , unit , amount ) {
85
- date = normalizeDate ( date ) ;
86
75
validateParameters ( date , unit , amount ) ;
87
76
return moment ( date ) . add ( unit , amount ) . toDate ( ) ;
88
77
}
@@ -99,30 +88,13 @@ function DATEADD(date, unit, amount) {
99
88
* @customFunction
100
89
*/
101
90
function DATESUBTRACT ( date , unit , amount ) {
102
- date = normalizeDate ( date ) ;
103
91
validateParameters ( date , unit , amount ) ;
104
92
return moment ( date ) . subtract ( unit , amount ) . toDate ( ) ;
105
93
}
106
94
107
- /**
108
- * Normalizes a date value from Google Sheets, as they can sometimes be passed
109
- * as number values.
110
- * @param {? } date The date value.
111
- * @return {Date } The normalized date value.
112
- */
113
- function normalizeDate ( date ) {
114
- if ( typeof date == 'number' ) {
115
- var days = Math . floor ( date ) ;
116
- var seconds = ( date - days ) * SECONDS_PER_DAY ;
117
- date = moment ( SHEETS_EPOCH ) . add ( days , 'days' )
118
- . add ( seconds , 'seconds' ) . toDate ( ) ;
119
- }
120
- return date ;
121
- }
122
-
123
95
/**
124
96
* Validates that the date, unit, and amount supplied are compatible with
125
- * Momnent , throwing an exception if any of the parameters are invalid.
97
+ * Moment , throwing an exception if any of the parameters are invalid.
126
98
* @param {Date } date The date to add to or subtract from.
127
99
* @param {string } unit The unit of time to add/subtract.
128
100
* @param {number } amount The amount of the specified unit to add/subtract.
0 commit comments