| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  | const oneMinute = 1000 * 60;  // MilliseConds in a Minute
 | 
					
						
							|  |  |  | const oneHour = oneMinute * 60;  // The milliseconds of one hour
 | 
					
						
							|  |  |  | const oneDay = oneHour * 24; // The Number of MilliseConds A Day
 | 
					
						
							|  |  |  | const oneWeek = oneDay * 7; // The milliseconds per week
 | 
					
						
							|  |  |  | const oneMonth = oneDay * 30; // The milliseconds of a month
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Decrease according to the number of days | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param days to reduce the number of days to be reduced | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.minusDays = function (days) { | 
					
						
							|  |  |  |     return this.minusMillis(oneDay * days); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Increase according to the number of days | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param days The number of days to be increased | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.plusDays = function (days) { | 
					
						
							|  |  |  |     return this.plusMillis(oneDay * days); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * A few | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param hours to be reduced | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.minusHours = function (hours) { | 
					
						
							|  |  |  |     return this.minusMillis(oneHour * hours); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Increase hourly | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param hours to increase the number of hours | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.plusHours = function (hours) { | 
					
						
							|  |  |  |     return this.plusMillis(oneHour * hours); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Make reduction in minutes | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param minutes to reduce the number of minutes | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.minusMinutes = function (minutes) { | 
					
						
							|  |  |  |     return this.minusMillis(oneMinute * minutes); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Add in minutes | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param minutes to increase the number of minutes | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.plusMinutes = function (minutes) { | 
					
						
							|  |  |  |     return this.plusMillis(oneMinute * minutes); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Decrease in milliseconds | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param millis to reduce the milliseconds | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.minusMillis = function(millis) { | 
					
						
							|  |  |  |     let time = this.getTime() - millis; | 
					
						
							|  |  |  |     let newDate = new Date(); | 
					
						
							|  |  |  |     newDate.setTime(time); | 
					
						
							|  |  |  |     return newDate; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Add in milliseconds to increase | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param millis to increase the milliseconds to increase | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.plusMillis = function(millis) { | 
					
						
							|  |  |  |     let time = this.getTime() + millis; | 
					
						
							|  |  |  |     let newDate = new Date(); | 
					
						
							|  |  |  |     newDate.setTime(time); | 
					
						
							|  |  |  |     return newDate; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Setting time is 00: 00: 00.000 on the day | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.setMinTime = function () { | 
					
						
							|  |  |  |     this.setHours(0); | 
					
						
							|  |  |  |     this.setMinutes(0); | 
					
						
							|  |  |  |     this.setSeconds(0); | 
					
						
							|  |  |  |     this.setMilliseconds(0); | 
					
						
							|  |  |  |     return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Setting time is 23: 59: 59.999 on the same day | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.setMaxTime = function () { | 
					
						
							|  |  |  |     this.setHours(23); | 
					
						
							|  |  |  |     this.setMinutes(59); | 
					
						
							|  |  |  |     this.setSeconds(59); | 
					
						
							|  |  |  |     this.setMilliseconds(999); | 
					
						
							|  |  |  |     return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Formatting date | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.formatDate = function () { | 
					
						
							|  |  |  |     return this.getFullYear() + "-" + addZero(this.getMonth() + 1) + "-" + addZero(this.getDate()); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Format time | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.formatTime = function () { | 
					
						
							|  |  |  |     return addZero(this.getHours()) + ":" + addZero(this.getMinutes()) + ":" + addZero(this.getSeconds()); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * Formatting date plus time | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |  * @param split Date and time separation symbols, default is a space | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | Date.prototype.formatDateTime = function (split = ' ') { | 
					
						
							|  |  |  |     return this.formatDate() + split + this.formatTime(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DateUtil { | 
					
						
							| 
									
										
										
										
											2023-05-13 13:52:13 +00:00
										 |  |  |     // String string to date object
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     static parseDate(str) { | 
					
						
							|  |  |  |         return new Date(str.replace(/-/g, '/')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static formatMillis(millis) { | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |         return moment(millis).format('YYYY-M-D H:m:s'); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static firstDayOfMonth() { | 
					
						
							|  |  |  |         const date = new Date(); | 
					
						
							|  |  |  |         date.setDate(1); | 
					
						
							|  |  |  |         date.setMinTime(); | 
					
						
							|  |  |  |         return date; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  | } |