Moment.js issue

Moment.js issue

rf1234rf1234 Posts: 3,028Questions: 88Answers: 422

Hi Allan,

similar to the issue I had with format 'L' there is another problem when I trie to use format 'LT'.
LT should be this for German dates: LT: 'HH:mm' and this for English UK dates: LT : 'HH:mm'. Thank god it happens to be the same in this case! For that reason I hard coded it now like this:

{
                label: "Bid Period End Time:",
                name:  "bidEndTime",
                attr: {
                    class: timeMask
                },
                type:  "datetime",
                def:   function () { return endOfDay },
                format:  'HH:mm',
                
            }

I would prefer to use format: 'LT' because I will be in trouble once I'll add an additional language if I do it like above.
If I use format 'LT' a date picker opens instead of the time picker. Probably becaus of the initial 'L'?! Do you have a fix for this please.

Answers

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    So in Moment L means a local date format, but LT means a local time format. Bummer.

    That's not going to be a trivial thing to find unfortunately since I'll need to change how Editor detects the format - its using a simple string detection at the moment, checking to see if L is present.

    I'll look into this and get back to you - probably next week now.

    Allan

  • rf1234rf1234 Posts: 3,028Questions: 88Answers: 422

    Thanks Allan. Take your time! In each locale you find a definition like these two for 'en-gb' and 'de':

    var en_gb = moment.defineLocale('en-gb', {
            months : 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
            monthsShort : 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
            weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
            weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
            weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
            longDateFormat : {
                LT : 'HH:mm',
                LTS : 'HH:mm:ss',
                L : 'DD/MM/YYYY',
                LL : 'D MMMM YYYY',
                LLL : 'D MMMM YYYY HH:mm',
                LLLL : 'dddd, D MMMM YYYY HH:mm'
            }, ....
    
    var de = moment.defineLocale('de', {
            months : 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'),
            monthsShort : 'Jan._Febr._Mrz._Apr._Mai_Jun._Jul._Aug._Sept._Okt._Nov._Dez.'.split('_'),
            monthsParseExact : true,
            weekdays : 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'),
            weekdaysShort : 'So._Mo._Di._Mi._Do._Fr._Sa.'.split('_'),
            weekdaysMin : 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'),
            weekdaysParseExact : true,
            longDateFormat : {
                LT: 'HH:mm',
                LTS: 'HH:mm:ss',
                L : 'DD.MM.YYYY',
                LL : 'D. MMMM YYYY',
                LLL : 'D. MMMM YYYY HH:mm',
                LLLL : 'dddd, D. MMMM YYYY HH:mm'
            }, ...
    

    All those L ... formats would need to work I am afraid ... Hope it's not too much hassle. This is the American default if you have no locale specified:

    var defaultLongDateFormat = {
        LTS  : 'h:mm:ss A',
        LT   : 'h:mm A',
        L    : 'MM/DD/YYYY',
        LL   : 'MMMM D, YYYY',
        LLL  : 'MMMM D, YYYY h:mm A',
        LLLL : 'dddd, MMMM D, YYYY h:mm A'
    };
    
  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    What I really would like is a function in moment that would convert the locale based format to a "standard" formatting string (i.e. a lookup). I had a look through the Moment documentation but couldn't see anything about that. That would make the problem really easy :smile:.

    Allan

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    So the answer is that it would technically be possible to deformat the locale formatting options (L, LT, LL, l, etc) in the same way that Moment does it (it doesn't expose an API method for this externally), but as far as I can see it would mean needing to access some private data, which I don't want to do.

    So looking for a better way I've just used improved regular expressions for the detection.

    A small modification to the part of Editor we changed before is:

            parts: {
                date:    this.c.format.match( /[YMD]|L(?!T)|l/ ) !== null,
                time:    this.c.format.match( /[Hhm]|LT|LTS/ ) !== null,
                seconds: this.c.format.indexOf( /s|LTS/ ) !== -1,
    

    I think in the short term that's possibly as close as I'm going to get. Longer term deformatting it by locale would be preferable.

    Allan

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    Forgot to say - this will be in 1.6.2.

    Allan

This discussion has been closed.