@@ -81,19 +81,19 @@ var abp = abp || {};
8181 if ( resource ) {
8282 return resource ;
8383 }
84-
84+
8585 var legacySource = abp . localization . values [ resourceName ] ;
8686 if ( legacySource ) {
8787 return {
8888 texts : abp . localization . values [ resourceName ] ,
8989 baseResources : [ ]
9090 } ;
9191 }
92-
93- abp . log . warn ( 'Could not find localization source: ' + resourceName ) ;
92+
93+ abp . log . warn ( 'Could not find localization source: ' + resourceName ) ;
9494 return null ;
9595 } ;
96-
96+
9797 abp . localization . internal . localize = function ( key , sourceName ) {
9898 var resource = abp . localization . internal . getResource ( sourceName ) ;
9999 if ( ! resource ) {
@@ -104,7 +104,7 @@ var abp = abp || {};
104104 }
105105
106106 var value = resource . texts [ key ] ;
107- if ( value === undefined ) {
107+ if ( value === undefined ) {
108108 for ( var i = 0 ; i < resource . baseResources . length ; i ++ ) {
109109 var basedArguments = Array . prototype . slice . call ( arguments , 0 ) ;
110110 basedArguments [ 1 ] = resource . baseResources [ i ] ;
@@ -114,7 +114,7 @@ var abp = abp || {};
114114 return result ;
115115 }
116116 }
117-
117+
118118 return {
119119 value : key ,
120120 found : false
@@ -135,7 +135,7 @@ var abp = abp || {};
135135 if ( sourceName === '_' ) { //A convention to suppress the localization
136136 return key ;
137137 }
138-
138+
139139 if ( sourceName ) {
140140 return abp . localization . internal . localize . apply ( this , arguments ) . value ;
141141 }
@@ -750,7 +750,11 @@ var abp = abp || {};
750750
751751 abp . clock . supportsMultipleTimezone = function ( ) {
752752 return abp . clock . kind === 'Utc' ;
753- } ;
753+ }
754+
755+ abp . clock . timeZone = function ( ) {
756+ return abp . setting . get ( 'Abp.Timing.TimeZone' ) || abp . clock . browserTimeZone ( ) ;
757+ }
754758
755759 // Normalize Date object or date string to standard string format that will be sent to server
756760 abp . clock . normalizeToString = function ( date ) {
@@ -763,32 +767,42 @@ var abp = abp || {};
763767 return date ;
764768 }
765769
766- if ( abp . clock . kind === 'Utc' ) {
767- return dateObj . toISOString ( ) ;
768- }
769-
770770 function padZero ( num ) {
771771 return num < 10 ? '0' + num : num ;
772772 }
773773
774- function padMilliseconds ( num ) {
775- if ( num < 10 ) return '00' + num ;
776- if ( num < 100 ) return '0' + num ;
777- return num ;
774+ var addZulu = false ;
775+ if ( abp . clock . supportsMultipleTimezone ( ) ) {
776+ var timeZone = abp . clock . timeZone ( ) ;
777+ var now = new Date ( ) ;
778+ var formattedDate = now . toLocaleString ( 'en-US' , { timeZone : timeZone , timeZoneName : 'longOffset' } ) ;
779+ var match = formattedDate . match ( / G M T ( [ + - ] \d + ) / ) ;
780+ var targetOffsetHours = match ? parseInt ( match [ 1 ] , 10 ) : 0 ;
781+ dateObj = new Date ( dateObj . getTime ( ) - ( targetOffsetHours * 60 * 60 * 1000 ) ) ;
782+ addZulu = true ;
778783 }
779-
780- // yyyy-MM-ddTHH :mm:ss.SSS
784+
785+ // yyyy-MM-DDTHH :mm:ss
781786 return dateObj . getFullYear ( ) + '-' +
782- padZero ( dateObj . getMonth ( ) + 1 ) + '-' +
783- padZero ( dateObj . getDate ( ) ) + 'T' +
784- padZero ( dateObj . getHours ( ) ) + ':' +
785- padZero ( dateObj . getMinutes ( ) ) + ':' +
786- padZero ( dateObj . getSeconds ( ) ) + '.' +
787- padMilliseconds ( dateObj . getMilliseconds ( ) ) ;
787+ padZero ( dateObj . getMonth ( ) + 1 ) + '-' +
788+ padZero ( dateObj . getDate ( ) ) + 'T' +
789+ padZero ( dateObj . getHours ( ) ) + ':' +
790+ padZero ( dateObj . getMinutes ( ) ) + ':' +
791+ padZero ( dateObj . getSeconds ( ) ) + ( addZulu ? 'Z' : '' ) ;
792+ } ;
793+
794+ // Default options for toLocaleString
795+ abp . clock . toLocaleStringOptions = abp . clock . toLocaleStringOptions || {
796+ "year" : "numeric" ,
797+ "month" : "long" ,
798+ "day" : "numeric" ,
799+ "hour" : "numeric" ,
800+ "minute" : "numeric" ,
801+ "second" : "numeric"
788802 } ;
789803
790804 // Normalize date string to locale date string that will be displayed to user
791- abp . clock . normalizeToLocaleString = function ( dateString ) {
805+ abp . clock . normalizeToLocaleString = function ( dateString , options ) {
792806 if ( ! dateString ) {
793807 return dateString ;
794808 }
@@ -797,11 +811,36 @@ var abp = abp || {};
797811 if ( isNaN ( date ) ) {
798812 return dateString ;
799813 }
800-
801- //TODO: Get timezone setting and pass it to toLocaleString
802- return date . toLocaleString ( ) ;
814+
815+ var culture = abp . localization . currentCulture . cultureName ;
816+ options = options || abp . clock . toLocaleStringOptions ;
817+ if ( abp . clock . supportsMultipleTimezone ( ) ) {
818+ var timezone = abp . clock . timeZone ( ) ;
819+ if ( timezone ) {
820+ return date . toLocaleString ( culture , Object . assign ( { } , options , { timeZone : timezone } ) ) ;
821+ }
822+ }
823+ return date . toLocaleString ( culture , options ) ;
803824 }
804825
826+ abp . clock . browserTimeZone = function ( ) {
827+ return Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
828+ }
829+
830+ abp . clock . trySetBrowserTimeZoneToCookie = true ;
831+
832+ abp . clock . setBrowserTimeZoneToCookie = function ( ) {
833+ if ( ! abp . clock . trySetBrowserTimeZoneToCookie || ! abp . clock . supportsMultipleTimezone ( ) ) {
834+ return ;
835+ }
836+
837+ abp . utils . setCookieValue ( '__timezone' , abp . clock . browserTimeZone ( ) , new Date ( new Date ( ) . setFullYear ( new Date ( ) . getFullYear ( ) + 1 ) ) , '/' ) ;
838+ }
839+
840+ abp . event . on ( 'abp.configurationInitialized' , function ( ) {
841+ abp . clock . setBrowserTimeZoneToCookie ( ) ;
842+ } ) ;
843+
805844 /* FEATURES *************************************************/
806845
807846 abp . features = abp . features || { } ;
0 commit comments