@@ -65,10 +65,16 @@ describe('ms(string)', function() {
65
65
expect ( ms ( '.5ms' ) ) . to . be ( 0.5 ) ;
66
66
} ) ;
67
67
68
- it ( 'should work with numbers starting with -' , function ( ) {
69
- expect ( ms ( '-5' ) ) . to . be ( - 5 ) ;
70
- expect ( ms ( '-.5ms' ) ) . to . be ( - 0.5 ) ;
71
- expect ( ms ( '-0.5ms' ) ) . to . be ( - 0.5 ) ;
68
+ it ( 'should work with negative integers' , function ( ) {
69
+ expect ( ms ( '-100ms' ) ) . to . be ( - 100 ) ;
70
+ } ) ;
71
+
72
+ it ( 'should work with negative decimals' , function ( ) {
73
+ expect ( ms ( '-1.5h' ) ) . to . be ( - 5400000 ) ;
74
+ } ) ;
75
+
76
+ it ( 'should work with negative decimals starting with "."' , function ( ) {
77
+ expect ( ms ( '-.5h' ) ) . to . be ( - 1800000 ) ;
72
78
} ) ;
73
79
} ) ;
74
80
@@ -108,6 +114,18 @@ describe('ms(long string)', function() {
108
114
it ( 'should work with decimals' , function ( ) {
109
115
expect ( ms ( '1.5 hours' ) ) . to . be ( 5400000 ) ;
110
116
} ) ;
117
+
118
+ it ( 'should work with negative integers' , function ( ) {
119
+ expect ( ms ( '-100 milliseconds' ) ) . to . be ( - 100 ) ;
120
+ } ) ;
121
+
122
+ it ( 'should work with negative decimals' , function ( ) {
123
+ expect ( ms ( '-1.5 hours' ) ) . to . be ( - 5400000 ) ;
124
+ } ) ;
125
+
126
+ it ( 'should work with negative decimals starting with "."' , function ( ) {
127
+ expect ( ms ( '-.5 hr' ) ) . to . be ( - 1800000 ) ;
128
+ } ) ;
111
129
} ) ;
112
130
113
131
// numbers
@@ -121,34 +139,54 @@ describe('ms(number, { long: true })', function() {
121
139
122
140
it ( 'should support milliseconds' , function ( ) {
123
141
expect ( ms ( 500 , { long : true } ) ) . to . be ( '500 ms' ) ;
142
+
143
+ expect ( ms ( - 500 , { long : true } ) ) . to . be ( '-500 ms' ) ;
124
144
} ) ;
125
145
126
146
it ( 'should support seconds' , function ( ) {
127
147
expect ( ms ( 1000 , { long : true } ) ) . to . be ( '1 second' ) ;
128
148
expect ( ms ( 1200 , { long : true } ) ) . to . be ( '1 second' ) ;
129
149
expect ( ms ( 10000 , { long : true } ) ) . to . be ( '10 seconds' ) ;
150
+
151
+ expect ( ms ( - 1000 , { long : true } ) ) . to . be ( '-1 second' ) ;
152
+ expect ( ms ( - 1200 , { long : true } ) ) . to . be ( '-1 second' ) ;
153
+ expect ( ms ( - 10000 , { long : true } ) ) . to . be ( '-10 seconds' ) ;
130
154
} ) ;
131
155
132
156
it ( 'should support minutes' , function ( ) {
133
157
expect ( ms ( 60 * 1000 , { long : true } ) ) . to . be ( '1 minute' ) ;
134
158
expect ( ms ( 60 * 1200 , { long : true } ) ) . to . be ( '1 minute' ) ;
135
159
expect ( ms ( 60 * 10000 , { long : true } ) ) . to . be ( '10 minutes' ) ;
160
+
161
+ expect ( ms ( - 1 * 60 * 1000 , { long : true } ) ) . to . be ( '-1 minute' ) ;
162
+ expect ( ms ( - 1 * 60 * 1200 , { long : true } ) ) . to . be ( '-1 minute' ) ;
163
+ expect ( ms ( - 1 * 60 * 10000 , { long : true } ) ) . to . be ( '-10 minutes' ) ;
136
164
} ) ;
137
165
138
166
it ( 'should support hours' , function ( ) {
139
167
expect ( ms ( 60 * 60 * 1000 , { long : true } ) ) . to . be ( '1 hour' ) ;
140
168
expect ( ms ( 60 * 60 * 1200 , { long : true } ) ) . to . be ( '1 hour' ) ;
141
169
expect ( ms ( 60 * 60 * 10000 , { long : true } ) ) . to . be ( '10 hours' ) ;
170
+
171
+ expect ( ms ( - 1 * 60 * 60 * 1000 , { long : true } ) ) . to . be ( '-1 hour' ) ;
172
+ expect ( ms ( - 1 * 60 * 60 * 1200 , { long : true } ) ) . to . be ( '-1 hour' ) ;
173
+ expect ( ms ( - 1 * 60 * 60 * 10000 , { long : true } ) ) . to . be ( '-10 hours' ) ;
142
174
} ) ;
143
175
144
176
it ( 'should support days' , function ( ) {
145
177
expect ( ms ( 24 * 60 * 60 * 1000 , { long : true } ) ) . to . be ( '1 day' ) ;
146
178
expect ( ms ( 24 * 60 * 60 * 1200 , { long : true } ) ) . to . be ( '1 day' ) ;
147
179
expect ( ms ( 24 * 60 * 60 * 10000 , { long : true } ) ) . to . be ( '10 days' ) ;
180
+
181
+ expect ( ms ( - 1 * 24 * 60 * 60 * 1000 , { long : true } ) ) . to . be ( '-1 day' ) ;
182
+ expect ( ms ( - 1 * 24 * 60 * 60 * 1200 , { long : true } ) ) . to . be ( '-1 day' ) ;
183
+ expect ( ms ( - 1 * 24 * 60 * 60 * 10000 , { long : true } ) ) . to . be ( '-10 days' ) ;
148
184
} ) ;
149
185
150
186
it ( 'should round' , function ( ) {
151
187
expect ( ms ( 234234234 , { long : true } ) ) . to . be ( '3 days' ) ;
188
+
189
+ expect ( ms ( - 234234234 , { long : true } ) ) . to . be ( '-3 days' ) ;
152
190
} ) ;
153
191
} ) ;
154
192
@@ -163,30 +201,46 @@ describe('ms(number)', function() {
163
201
164
202
it ( 'should support milliseconds' , function ( ) {
165
203
expect ( ms ( 500 ) ) . to . be ( '500ms' ) ;
204
+
205
+ expect ( ms ( - 500 ) ) . to . be ( '-500ms' ) ;
166
206
} ) ;
167
207
168
208
it ( 'should support seconds' , function ( ) {
169
209
expect ( ms ( 1000 ) ) . to . be ( '1s' ) ;
170
210
expect ( ms ( 10000 ) ) . to . be ( '10s' ) ;
211
+
212
+ expect ( ms ( - 1000 ) ) . to . be ( '-1s' ) ;
213
+ expect ( ms ( - 10000 ) ) . to . be ( '-10s' ) ;
171
214
} ) ;
172
215
173
216
it ( 'should support minutes' , function ( ) {
174
217
expect ( ms ( 60 * 1000 ) ) . to . be ( '1m' ) ;
175
218
expect ( ms ( 60 * 10000 ) ) . to . be ( '10m' ) ;
219
+
220
+ expect ( ms ( - 1 * 60 * 1000 ) ) . to . be ( '-1m' ) ;
221
+ expect ( ms ( - 1 * 60 * 10000 ) ) . to . be ( '-10m' ) ;
176
222
} ) ;
177
223
178
224
it ( 'should support hours' , function ( ) {
179
225
expect ( ms ( 60 * 60 * 1000 ) ) . to . be ( '1h' ) ;
180
226
expect ( ms ( 60 * 60 * 10000 ) ) . to . be ( '10h' ) ;
227
+
228
+ expect ( ms ( - 1 * 60 * 60 * 1000 ) ) . to . be ( '-1h' ) ;
229
+ expect ( ms ( - 1 * 60 * 60 * 10000 ) ) . to . be ( '-10h' ) ;
181
230
} ) ;
182
231
183
232
it ( 'should support days' , function ( ) {
184
233
expect ( ms ( 24 * 60 * 60 * 1000 ) ) . to . be ( '1d' ) ;
185
234
expect ( ms ( 24 * 60 * 60 * 10000 ) ) . to . be ( '10d' ) ;
235
+
236
+ expect ( ms ( - 1 * 24 * 60 * 60 * 1000 ) ) . to . be ( '-1d' ) ;
237
+ expect ( ms ( - 1 * 24 * 60 * 60 * 10000 ) ) . to . be ( '-10d' ) ;
186
238
} ) ;
187
239
188
240
it ( 'should round' , function ( ) {
189
241
expect ( ms ( 234234234 ) ) . to . be ( '3d' ) ;
242
+
243
+ expect ( ms ( - 234234234 ) ) . to . be ( '-3d' ) ;
190
244
} ) ;
191
245
} ) ;
192
246
0 commit comments