| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  | /* global describe expect it */ | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | import moment from 'moment-timezone'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { dayCount } from './date-utils'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PST = 'America/Los_Angeles'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  | describe('date utils', () => { | 
					
						
							|  |  |  |   describe('dayCount', () => { | 
					
						
							|  |  |  |     it('should return 1 day given epochs of the same day', () => { | 
					
						
							|  |  |  |       expect( | 
					
						
							|  |  |  |         dayCount([ | 
					
						
							|  |  |  |           moment.utc('8/3/2015 3:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |           moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |       ).toEqual(1); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     it('should return 1 day given same epochs', () => { | 
					
						
							|  |  |  |       expect( | 
					
						
							|  |  |  |         dayCount([ | 
					
						
							|  |  |  |           moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |           moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |       ).toEqual(1); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 10:38:10 +00:00
										 |  |  |     it('should return 2 days when there is a 24 hours difference', () => { | 
					
						
							|  |  |  |       expect( | 
					
						
							|  |  |  |         dayCount([ | 
					
						
							|  |  |  |           moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |           moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |       ).toEqual(2); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     it( | 
					
						
							|  |  |  |       'should return 2 days when the diff is less than 24h but ' + | 
					
						
							|  |  |  |         'different in UTC', | 
					
						
							| 
									
										
										
										
											2018-12-03 10:38:10 +00:00
										 |  |  |       () => { | 
					
						
							|  |  |  |         expect( | 
					
						
							|  |  |  |           dayCount([ | 
					
						
							|  |  |  |             moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |             moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |           ]) | 
					
						
							|  |  |  |         ).toEqual(2); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     it( | 
					
						
							|  |  |  |       'should return 1 day when the diff is less than 24h ' + | 
					
						
							|  |  |  |         'and days are different in UTC, but given PST', | 
					
						
							| 
									
										
										
										
											2018-12-03 10:38:10 +00:00
										 |  |  |       () => { | 
					
						
							|  |  |  |         expect( | 
					
						
							|  |  |  |           dayCount( | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |               moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |               moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             PST | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ).toEqual(1); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 10:38:10 +00:00
										 |  |  |     it('should return correct count when there is very big period', () => { | 
					
						
							|  |  |  |       expect( | 
					
						
							|  |  |  |         dayCount([ | 
					
						
							|  |  |  |           moment.utc('10/27/2015 1:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |           moment.utc('5/12/1982 1:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |       ).toEqual(12222); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     it( | 
					
						
							|  |  |  |       'should return 2 days when there is a 24 hours difference ' + | 
					
						
							|  |  |  |         'between dates given `undefined` timezone', | 
					
						
							| 
									
										
										
										
											2018-12-03 10:38:10 +00:00
										 |  |  |       () => { | 
					
						
							|  |  |  |         expect( | 
					
						
							|  |  |  |           dayCount([ | 
					
						
							|  |  |  |             moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(), | 
					
						
							|  |  |  |             moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf() | 
					
						
							|  |  |  |           ]) | 
					
						
							|  |  |  |         ).toEqual(2); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-11-30 14:24:16 +00:00
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-09-23 15:38:49 -07:00
										 |  |  | }); |