1313 * limitations under the License.
1414 */
1515
16+ import { DateFormats , TimeFormats } from "../shared/scripting_utils.js" ;
1617import { GlobalConstants } from "./constants.js" ;
1718
1819class AForm {
@@ -21,23 +22,6 @@ class AForm {
2122 this . _app = app ;
2223 this . _util = util ;
2324 this . _color = color ;
24- this . _dateFormats = [
25- "m/d" ,
26- "m/d/yy" ,
27- "mm/dd/yy" ,
28- "mm/yy" ,
29- "d-mmm" ,
30- "d-mmm-yy" ,
31- "dd-mmm-yy" ,
32- "yy-mm-dd" ,
33- "mmm-yy" ,
34- "mmmm-yy" ,
35- "mmm d, yyyy" ,
36- "mmmm d, yyyy" ,
37- "m/d/yy h:MM tt" ,
38- "m/d/yy HH:MM" ,
39- ] ;
40- this . _timeFormats = [ "HH:MM" , "h:MM tt" , "HH:MM:ss" , "h:MM:ss tt" ] ;
4125
4226 // The e-mail address regex below originates from:
4327 // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
@@ -52,17 +36,14 @@ class AForm {
5236 return event . target ? `[ ${ event . target . name } ]` : "" ;
5337 }
5438
55- _parseDate ( cFormat , cDate , strict = false ) {
39+ _parseDate ( cFormat , cDate ) {
5640 let date = null ;
5741 try {
58- date = this . _util . _scand ( cFormat , cDate , strict ) ;
42+ date = this . _util . _scand ( cFormat , cDate , /* strict = */ false ) ;
5943 } catch { }
6044 if ( date ) {
6145 return date ;
6246 }
63- if ( strict ) {
64- return null ;
65- }
6647
6748 date = Date . parse ( cDate ) ;
6849 return isNaN ( date ) ? null : new Date ( date ) ;
@@ -277,9 +258,7 @@ class AForm {
277258 }
278259
279260 AFDate_Format ( pdf ) {
280- if ( pdf >= 0 && pdf < this . _dateFormats . length ) {
281- this . AFDate_FormatEx ( this . _dateFormats [ pdf ] ) ;
282- }
261+ this . AFDate_FormatEx ( DateFormats [ pdf ] ?? pdf ) ;
283262 }
284263
285264 AFDate_KeystrokeEx ( cFormat ) {
@@ -293,7 +272,7 @@ class AForm {
293272 return ;
294273 }
295274
296- if ( this . _parseDate ( cFormat , value , /* strict = */ true ) === null ) {
275+ if ( this . _parseDate ( cFormat , value ) === null ) {
297276 const invalid = GlobalConstants . IDS_INVALID_DATE ;
298277 const invalid2 = GlobalConstants . IDS_INVALID_DATE2 ;
299278 const err = `${ invalid } ${ this . _mkTargetName (
@@ -305,8 +284,8 @@ class AForm {
305284 }
306285
307286 AFDate_Keystroke ( pdf ) {
308- if ( pdf >= 0 && pdf < this . _dateFormats . length ) {
309- this . AFDate_KeystrokeEx ( this . _dateFormats [ pdf ] ) ;
287+ if ( pdf >= 0 && pdf < DateFormats . length ) {
288+ this . AFDate_KeystrokeEx ( DateFormats [ pdf ] ) ;
310289 }
311290 }
312291
@@ -617,18 +596,16 @@ class AForm {
617596 }
618597
619598 AFTime_Format ( pdf ) {
620- if ( pdf >= 0 && pdf < this . _timeFormats . length ) {
621- this . AFDate_FormatEx ( this . _timeFormats [ pdf ] ) ;
622- }
599+ this . AFDate_FormatEx ( TimeFormats [ pdf ] ?? pdf ) ;
623600 }
624601
625602 AFTime_KeystrokeEx ( cFormat ) {
626603 this . AFDate_KeystrokeEx ( cFormat ) ;
627604 }
628605
629606 AFTime_Keystroke ( pdf ) {
630- if ( pdf >= 0 && pdf < this . _timeFormats . length ) {
631- this . AFDate_KeystrokeEx ( this . _timeFormats [ pdf ] ) ;
607+ if ( pdf >= 0 && pdf < TimeFormats . length ) {
608+ this . AFDate_KeystrokeEx ( TimeFormats [ pdf ] ) ;
632609 }
633610 }
634611
0 commit comments