@@ -34,6 +34,8 @@ import {
3434
3535import { IMonthValue , InternalModuleValue , ITimeValue , WeekStartNum } from '../interfaces' ;
3636
37+ export const sanitizeDate = ( date : Date ) => new Date ( date . valueOf ( ) + date . getTimezoneOffset ( ) * 60 * 1000 ) ;
38+
3739/**
3840 * it will try to parse date based on pattern and parts of the text value
3941 */
@@ -59,9 +61,7 @@ export const resetDateTime = (value: Date | string): Date => {
5961/**
6062 * Convert string value to date based on provided pattern
6163 */
62- export const parseDate = ( date : string , pattern : string ) : Date => {
63- return parse ( date , pattern , new Date ( ) ) ;
64- } ;
64+ export const parseDate = ( date : string , pattern : string ) : Date => parse ( date , pattern , new Date ( ) ) ;
6565
6666/**
6767 * Check if provided date(s) is valid
@@ -114,9 +114,8 @@ export const setDateMonthOrYear = (date: Date | null, month?: number | null, yea
114114 return dateCopy ;
115115} ;
116116
117- const getTimeFormat = ( is24 : boolean , seconds : boolean ) : string => {
118- return is24 ? `HH:mm${ seconds ? ':ss' : '' } ` : `hh:mm${ seconds ? ':ss' : '' } aa` ;
119- } ;
117+ const getTimeFormat = ( is24 : boolean , seconds : boolean ) : string =>
118+ is24 ? `HH:mm${ seconds ? ':ss' : '' } ` : `hh:mm${ seconds ? ':ss' : '' } aa` ;
120119
121120export const getDefaultPattern = (
122121 pattern : string | null ,
@@ -142,19 +141,18 @@ export const getDefaultPattern = (
142141 * Extract time value from the date for time picker
143142 */
144143export const getTimeVal = ( date ?: Date ) : ITimeValue => {
144+ const dateValue = date || new Date ( ) ;
145145 return {
146- hours : getHours ( date || new Date ( ) ) ,
147- minutes : getMinutes ( date || new Date ( ) ) ,
148- seconds : getSeconds ( date || new Date ( ) ) ,
146+ hours : getHours ( dateValue ) ,
147+ minutes : getMinutes ( dateValue ) ,
148+ seconds : getSeconds ( dateValue ) ,
149149 } ;
150150} ;
151151
152152/**
153153 * Extract month value from the date for month picker
154154 */
155- export const getMonthVal = ( date : Date ) : IMonthValue => {
156- return { month : getMonth ( date ) , year : getYear ( date ) } ;
157- } ;
155+ export const getMonthVal = ( date : Date ) : IMonthValue => ( { month : getMonth ( date ) , year : getYear ( date ) } ) ;
158156
159157/**
160158 * Map internal date value to the value that will be passed to v-model external on time picker
@@ -169,9 +167,7 @@ export const getTImeForExternal = (date: Date | Date[]): ITimeValue | ITimeValue
169167/**
170168 * Map internal date vale to the value that will be passed to v-model external on month picker
171169 */
172- export const getMonthForExternal = ( date : Date ) : IMonthValue => {
173- return getMonthVal ( date ) ;
174- } ;
170+ export const getMonthForExternal = ( date : Date ) : IMonthValue => getMonthVal ( date ) ;
175171
176172/**
177173 * Format date values for the input field based on provided pattern
@@ -187,16 +183,12 @@ export const formatDate = (value: Date | Date[], pattern: string): string => {
187183/**
188184 * Get month value from the provided date
189185 */
190- export const getDateMonth = ( date : Date ) : number => {
191- return getMonth ( date ) ;
192- } ;
186+ export const getDateMonth = ( date : Date ) : number => getMonth ( date ) ;
193187
194188/**
195189 * Get year value from the provided date
196190 */
197- export const getDateYear = ( date : Date ) : number => {
198- return getYear ( date ) ;
199- } ;
191+ export const getDateYear = ( date : Date ) : number => getYear ( date ) ;
200192
201193/**
202194 * Check if the given date is after the provided date
@@ -231,23 +223,17 @@ export const isDateEqual = (date: Date | string | null, dateToCompare: Date | st
231223/**
232224 * Return the ISO week number for the given date
233225 */
234- export const getWeekNumber = ( date : Date ) : number => {
235- return getISOWeek ( new Date ( date ) ) ;
236- } ;
226+ export const getWeekNumber = ( date : Date ) : number => getISOWeek ( new Date ( date ) ) ;
237227
238228/**
239229 * Get hours from given date, if none, will return current hours
240230 */
241- export const getDateHours = ( date ?: Date ) : number => {
242- return getHours ( date || new Date ( ) ) ;
243- } ;
231+ export const getDateHours = ( date ?: Date ) : number => getHours ( date || new Date ( ) ) ;
244232
245233/**
246234 * Get minutes from the given date, if none, will return current minutes
247235 */
248- export const getDateMinutes = ( date ?: Date ) : number => {
249- return getMinutes ( date || new Date ( ) ) ;
250- } ;
236+ export const getDateMinutes = ( date ?: Date ) : number => getMinutes ( date || new Date ( ) ) ;
251237
252238export const getDateSeconds = ( date ?: Date ) : number => {
253239 return getSeconds ( date || new Date ( ) ) ;
@@ -256,45 +242,37 @@ export const getDateSeconds = (date?: Date): number => {
256242/**
257243 * Add n amount of days to a given date
258244 */
259- export const getAddedDays = ( date : Date , days : number ) : Date => {
260- return addDays ( date , days ) ;
261- } ;
245+ export const getAddedDays = ( date : Date , days : number ) : Date => addDays ( date , days ) ;
262246
263247/**
264248 * Add specific amount of hours to the previous hours
265249 */
266- export const addDateHours = ( hours : number , toAdd : number ) : number => {
267- return getHours ( addHours ( setHours ( new Date ( ) , hours ) , toAdd ) ) ;
268- } ;
250+ export const addDateHours = ( hours : number , toAdd : number ) : number =>
251+ getHours ( addHours ( setHours ( new Date ( ) , hours ) , toAdd ) ) ;
269252
270253/**
271254 * Subtract specific amount of hours to the previous hours
272255 */
273- export const subDateHours = ( hours : number , toSub : number ) : number => {
274- return getHours ( subHours ( setHours ( new Date ( ) , hours ) , toSub ) ) ;
275- } ;
256+ export const subDateHours = ( hours : number , toSub : number ) : number =>
257+ getHours ( subHours ( setHours ( new Date ( ) , hours ) , toSub ) ) ;
276258
277259/**
278260 * Add specific amount of minutes to the previous minutes
279261 */
280- export const addDateMinutes = ( minutes : number , toAdd : number ) : number => {
281- return getMinutes ( addMinutes ( setMinutes ( new Date ( ) , minutes ) , toAdd ) ) ;
282- } ;
262+ export const addDateMinutes = ( minutes : number , toAdd : number ) : number =>
263+ getMinutes ( addMinutes ( setMinutes ( new Date ( ) , minutes ) , toAdd ) ) ;
283264
284265/**
285266 * Subtract specific amount of minutes to the previous minutes
286267 */
287- export const subDateMinutes = ( minutes : number , toSub : number ) : number => {
288- return getMinutes ( subMinutes ( setMinutes ( new Date ( ) , minutes ) , toSub ) ) ;
289- } ;
268+ export const subDateMinutes = ( minutes : number , toSub : number ) : number =>
269+ getMinutes ( subMinutes ( setMinutes ( new Date ( ) , minutes ) , toSub ) ) ;
290270
291- export const addDateSeconds = ( seconds : number , toAdd : number ) : number => {
292- return getSeconds ( addSeconds ( setSeconds ( new Date ( ) , seconds ) , toAdd ) ) ;
293- } ;
271+ export const addDateSeconds = ( seconds : number , toAdd : number ) : number =>
272+ getSeconds ( addSeconds ( setSeconds ( new Date ( ) , seconds ) , toAdd ) ) ;
294273
295- export const subDateSeconds = ( seconds : number , toSub : number ) : number => {
296- return getSeconds ( subSeconds ( setSeconds ( new Date ( ) , seconds ) , toSub ) ) ;
297- } ;
274+ export const subDateSeconds = ( seconds : number , toSub : number ) : number =>
275+ getSeconds ( subSeconds ( setSeconds ( new Date ( ) , seconds ) , toSub ) ) ;
298276
299277export const getPreviousMonthYear = ( month : number , year : number ) : { month : number ; year : number } => {
300278 const date = subMonths ( setYear ( setMonth ( new Date ( ) , month ) , year ) , 1 ) ;
@@ -308,17 +286,12 @@ export const getNextYearMonth = (month: number, year: number): { month: number;
308286
309287export const addMonthsToDate = ( date : Date | string , amount = 1 ) : Date => addMonths ( new Date ( date ) , amount ) ;
310288
311- export const getWeekDay = ( date : string | Date ) : number => {
312- return getDay ( new Date ( date ) ) ;
313- } ;
289+ export const getWeekDay = ( date : string | Date ) : number => getDay ( new Date ( date ) ) ;
314290
315- export const getStartOfTheWeek = ( date : Date , start : WeekStartNum ) : Date => {
316- return startOfWeek ( date , { weekStartsOn : start } ) ;
317- } ;
291+ export const getStartOfTheWeek = ( date : Date , start : WeekStartNum ) : Date => startOfWeek ( date , { weekStartsOn : start } ) ;
318292
319- const setTimeValue = ( date : Date ) : Date => {
320- return set ( new Date ( ) , { hours : getHours ( date ) , minutes : getMinutes ( date ) , seconds : getSeconds ( date ) } ) ;
321- } ;
293+ const setTimeValue = ( date : Date ) : Date =>
294+ set ( new Date ( ) , { hours : getHours ( date ) , minutes : getMinutes ( date ) , seconds : getSeconds ( date ) } ) ;
322295
323296const getMinMaxTime = ( time : ITimeValue ) : Date => {
324297 return set ( new Date ( ) , {
0 commit comments