import moment from 'moment' ; import { LocaleType } from '../types' ; export function addDays ( date , days ) { const result = new Date ( date ) ; result . setDate ( result . getDate ( ) + days ) ; return result ; } export function isValidDate ( date ) { return ( Object . prototype . toString . call ( date ) === '[object Date]' && ! isNaN ( date . getTime ( ) ) ) ; } export function isSameDate ( one , other ) { return ( one . getDate ( ) === other . getDate ( ) && one . getMonth ( ) === other . getMonth ( ) && one . getFullYear ( ) === other . getFullYear ( ) ) ; } export function getMonthIndex ( firstMonth , date , months , numberOfMonths ) { const _firstMonth = moment ( firstMonth ) ; const lastMonth = _firstMonth . clone ( ) . add ( numberOfMonths , 'months' ) ; if ( date >= _firstMonth . toDate ( ) && date <= lastMonth . endOf ( 'month' ) . toDate ( ) ) { const monthIndex = moment ( date ) . diff ( _firstMonth , 'months' ) ; if ( monthIndex >= 0 && monthIndex <= months . length ) { return monthIndex ; } } return null ; } export function getMonthNames ( locale ? ) { switch ( locale ) { case 'es' : return [ 'Enero' , 'Febrero' , 'Marzo' , 'Abril' , 'Mayo' , 'Junio' , 'Julio' , 'Agosto' , 'Septiembre' , 'Octubre' , 'Noviembre' , 'Diciembre' , ] ; case 'en' : return [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' , ] ; case 'fr' : return [ 'Janvier' , 'Février' , 'Mars' , 'Avril' , 'Mai' , 'Juin' , 'Juillet' , 'Août' , 'Septembre' , 'Octobre' , 'Novembre' , 'Décembre' , ] ; case 'br' : return [ 'Janeiro' , 'Fevereiro' , 'Março' , 'Abril' , 'Maio' , 'Junho' , 'Julho' , 'Agosto' , 'Setembro' , 'Outubro' , 'Novembro' , 'Dezembro' , ] ; case 'zh' : return [ '一月' , '二月' , '三月' , '四月' , '五月' , '六月' , '七月' , '八月' , '九月' , '十月' , '十一月' , '十二月' , ] ; default : return [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' , ] ; } }