@@ -751,21 +751,11 @@ $.smkDatePicker = function(date) {
751
751
752
752
if ( date !== '' ) {
753
753
// Se obtiene el dia
754
- var day = date . getDate ( ) ;
754
+ var day = ( date . getDate ( ) < 10 ? '0' : '' ) + date . getDate ( ) ;
755
755
// Se obtiene el mes
756
- var month = date . getMonth ( ) + 1 ;
756
+ var month = ( ( date . getMonth ( ) + 1 ) < 10 ? '0' : '' ) + ( date . getMonth ( ) + 1 ) ;
757
757
// Se obtiene el año
758
758
var year = date . getFullYear ( ) ;
759
-
760
- // Si el dia es menor que 10 se agrega 0 al inicio
761
- if ( day < 10 ) {
762
- day = '0' + day ;
763
- }
764
- // Si el mes es menor que 10 se agrega 0 al inicio
765
- if ( month < 10 ) {
766
- month = '0' + month ;
767
- }
768
-
769
759
// Se construye la fecha con el formato para BD yyyy-mm-dd
770
760
result = year + '-' + month + '-' + day ;
771
761
} else {
@@ -802,86 +792,78 @@ $.smkDate = function(options) {
802
792
803
793
var languaje = {
804
794
es : {
805
- shortMonthNames : [ "Ene" , "Feb" , "Mar" , "Abr" , "May" , "Jun" , "Jul" , "Ago" , "Sep" , "Oct" , "Nov" , "Dic" ] ,
795
+ shortMonthNames : [ "Ene" , "Feb" , "Mar" , "Abr" , "May" , "Jun" , "Jul" , "Ago" , "Sep" , "Oct" , "Nov" , "Dic" ] ,
806
796
monthNames : [ "Enero" , "Febrero" , "Marzo" , "Abril" , "Mayo" , "Junio" , "Julio" , "Agosto" , "Septiembre" , "Octubre" , "Noviembre" , "Diciembre" ]
807
797
}
808
798
} ;
809
799
810
- if ( settings . lang != 'es' ) {
811
- languaje = $ . smkDate . Languaje ;
800
+ //Se obtienen los separadores
801
+ var validDate = / \d + | [ a - z A - z ] / g;
802
+ var separator = settings . date . replace ( validDate , '\0' ) . split ( '\0' ) ;
803
+ // Se obtiene las partes de la fecha
804
+ var splitDate = settings . date . match ( validDate ) ;
805
+
806
+ if ( settings . lang == 'es' ) {
807
+ // Se formatea la fecha (yyyy,mm,dd) para poder instanciar el método new Date()
808
+ if ( splitDate [ 0 ] . length == 4 ) {
809
+ // Formato yyyy-mm-dd => yyyy,mm,dd
810
+ settings . date = new Date ( splitDate [ 0 ] , ( splitDate [ 1 ] - 1 ) , splitDate [ 2 ] ) ;
811
+ } else {
812
+ // Formato dd-mm-yyyy => yyyy,mm,dd
813
+ settings . date = new Date ( splitDate [ 2 ] , ( splitDate [ 1 ] - 1 ) , splitDate [ 0 ] ) ;
814
+ }
812
815
} else {
813
- // Se obtienen los separadores
814
- var validDate = / \d + | [ a - z A - z ] / g;
815
- var separator = settings . date . replace ( validDate , '\0' ) . split ( '\0' ) ;
816
- // Se obtiene el formato
817
- var splitDate = settings . date . match ( validDate ) ;
818
- // Se formatea la fecha (format gringo) para poder instanciar el método new Date()
819
- //var splitDate = settings.date.split('-');
816
+ languaje = $ . smkDate . Languaje ;
817
+ // Se formatea la fecha (yyyy,mm,dd) para poder instanciar el método new Date()
820
818
if ( splitDate [ 0 ] . length == 4 ) {
821
- // Formato yyyy-mm-dd => mm-dd-yyyy
822
- settings . date = splitDate [ 1 ] + '-' + splitDate [ 2 ] + '-' + splitDate [ 0 ] ;
819
+ // Formato yyyy-dd-mm => yyyy,mm,dd
820
+ settings . date = new Date ( splitDate [ 0 ] , ( splitDate [ 2 ] - 1 ) , splitDate [ 1 ] ) ;
823
821
} else {
824
- // Formato dd- mm-yyyy => mm-dd-yyyy
825
- settings . date = splitDate [ 1 ] + '-' + splitDate [ 0 ] + '-' + splitDate [ 2 ] ;
822
+ // Formato mm-dd- yyyy => yyyy,mm,dd
823
+ settings . date = new Date ( splitDate [ 2 ] , ( splitDate [ 0 ] - 1 ) , splitDate [ 1 ] ) ;
826
824
}
827
825
}
828
826
829
- var date = new Date ( settings . date ) ;
830
827
var result = '' ;
831
828
832
- if ( date != 'Invalid Date' ) {
833
- // Se obtiene el dia
834
- var day = date . getDate ( ) ;
835
- // Se obtiene el mes
836
- var month = date . getMonth ( ) + 1 ;
837
-
838
- // Si el dia es menor que 10 se agrega 0 al inicio
839
- if ( day < 10 ) {
840
- day = '0' + day ;
841
- }
842
- // Si el mes es menor que 10 se agrega 0 al inicio
843
- if ( month < 10 ) {
844
- month = '0' + month ;
845
- }
829
+ if ( settings . date != 'Invalid Date' ) {
846
830
847
831
// Se crea el array que contiene el día, mes y año
848
832
var arrayDate = {
849
833
// Se obtiene el dia
850
- 'd' : date . getDate ( ) ,
851
- 'dd' : day ,
834
+ 'd' : settings . date . getDate ( ) ,
835
+ 'dd' : ( settings . date . getDate ( ) < 10 ? '0' : '' ) + settings . date . getDate ( ) ,
852
836
// Se obtiene el mes
853
- 'm' : date . getMonth ( ) + 1 , //January is 0!
854
- 'mm' : month ,
837
+ 'm' : settings . date . getMonth ( ) + 1 , //January is 0!
838
+ 'mm' : ( ( settings . date . getMonth ( ) + 1 ) < 10 ? '0' : '' ) + ( settings . date . getMonth ( ) + 1 ) ,
839
+ 'M' : languaje [ settings . lang ] . shortMonthNames [ settings . date . getMonth ( ) ] ,
840
+ 'MM' : languaje [ settings . lang ] . monthNames [ settings . date . getMonth ( ) ] ,
855
841
// Se obtiene el año
856
- 'yyyy' : date . getFullYear ( ) ,
842
+ 'yyyy' : settings . date . getFullYear ( ) ,
857
843
// Se obtiene el año 2 digitos
858
- 'yy' : date . getFullYear ( ) . toString ( ) . substring ( 2 ) ,
844
+ 'yy' : settings . date . getFullYear ( ) . toString ( ) . substring ( 2 ) ,
859
845
// Se obtiene la hora
860
- 'hh' : date . getHours ( ) ,
846
+ 'hh' : settings . date . getHours ( ) ,
861
847
// Se obtienen los minutos
862
- 'mi' : date . getMinutes ( ) ,
848
+ 'mi' : settings . date . getMinutes ( ) ,
863
849
// Se obtienen los segundos
864
- 'ss' : date . getSeconds ( )
850
+ 'ss' : settings . date . getSeconds ( )
865
851
} ;
866
852
867
853
// Se obtienen los separadores
868
- var validParts = / d d ? | D D ? | m m ? | M M ? | y y (?: y y ) ? / g;
869
- var separators = settings . format . replace ( validParts , '\0' ) . split ( '\0' ) ;
870
- // Se obtiene el formato
871
- var parts = settings . format . match ( validParts ) ;
854
+ var validFormat = / d d ? | D D ? | m m ? | M M ? | y y (?: y y ) ? / g;
855
+ var separators = settings . format . replace ( validFormat , '\0' ) . split ( '\0' ) ;
856
+ // Se obtienen las partes del formato
857
+ var splitFormat = settings . format . match ( validFormat ) ;
872
858
873
859
// Se construye la fecha con el formato y los separadores indicados
874
- $ . each ( parts , function ( index , val ) {
875
- if ( val == 'M' ) {
876
- result += separators [ index ] + languaje [ settings . lang ] . shortMonthNames [ date . getMonth ( ) ] ;
877
- } else if ( val == 'MM' ) {
878
- result += separators [ index ] + languaje [ settings . lang ] . monthNames [ date . getMonth ( ) ] ;
879
- } else {
880
- result += separators [ index ] + arrayDate [ val ] ;
881
- }
860
+ $ . each ( splitFormat , function ( key , val ) {
861
+ result += separators [ key ] + arrayDate [ val ] ;
882
862
} ) ;
863
+
883
864
} else {
884
865
result = '' ;
866
+ console . log ( 'Invalid Date' ) ;
885
867
}
886
868
887
869
// Se retorna la fecha formateada
0 commit comments