Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar flips Date and Month around #986

Closed
OssiPesonen opened this issue Sep 1, 2019 · 2 comments
Closed

Calendar flips Date and Month around #986

OssiPesonen opened this issue Sep 1, 2019 · 2 comments
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Milestone

Comments

@OssiPesonen
Copy link

OssiPesonen commented Sep 1, 2019

Bug Report

For reasons unknown our web app, which is using Fomantic UI, keeps flipping the month and date around when the input value is set to format 'j.n.Y H:i' and calendar formatter to day.month..year.

This only happens on Chromium browsers, Chrome, Opera... Not certain if it is locale specific (I am using Finnish)

For clarification, I am using PHP date() function format. j = day, n = month, Y = year if someone does not understand.

Steps to reproduce

  1. Set input value as php date j.n.Y H:i
  2. Open view with Google Chrome which then formats the value and calls (at the bottom of the page), $('input').calendar()
  3. Input (UI) shows n.j.Y H.i even though dev tools report j.n.Y H:i. This can only happen when date is below 13th making it eligible to pass as a month. When form is submitted the wrong format gets passed forward.

The calendar is formatted as such:

$('#time').calendar({
    type: 'datetime',
    today: true,
    ampm: false,
    firstDayOfWeek: 1,
    text: {
      days: ['S', 'M', 'T', 'K', 'T', 'P', 'L'],
      months: ['Tammikuu', 'Helmikuu', 'Maaliskuu', 'Huhtikuu', 'Toukokuu', 'Kesäkuu', 'Heinäkuu', 'Elokuu', 'Syyskuu', 'Lokakuu', 'Marraskuu', 'Joulukuu'],
      monthsShort: ['Tam', 'Hel', 'Maa', 'Huh', 'Tou', 'Kes', 'Hei', 'Elo', 'Syy', 'Lok', 'Mar', 'Jou'],
      today: 'Tänään',
      now: 'Nyt',
      am: 'AM',
      pm: 'PM'
    },
    monthFirst: false,
    formatter: {
        date: function (date, settings) {
            if (!date) return '';
            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();
            return day + '.' + month + '.' + year;
        }
    }
});

The input field (Laravel blade view) is printed as so:

<input type="text" placeholder="{{ __("Aika") }}" name="time" value="{{ !empty($obj->time) ? date('j.n.Y H:i', strtotime($obj->time)) : '' }}">

Expected result

Input (UI) field should contain the time format as j.n.Y H:i

Actual result

Input shows date in format n.j.Y H:i

Testcase

https://jsfiddle.net/eow4Lqg5/

Open with Google Chrome or Opera. Date is set to 1st of September 2019 12:00 (01.09.2019)

Screenshot (when possible)

Input (UI) field:
image

Dev-tools reported 'value':
image

Version

2.7.6

@lubber-de lubber-de added state/awaiting-investigation Anything which needs more investigation lang/javascript Anything involving JavaScript labels Sep 1, 2019
@prudho
Copy link
Contributor

prudho commented Sep 4, 2019

Please take a look at his PR #995, it may be helpful for your issue.

@lubber-de
Copy link
Member

lubber-de commented Sep 5, 2019

As @prudho said, i can confirm it is fixed by #1004
See your adjusted jsfiddle here https://jsfiddle.net/p04xfcnv/

@lubber-de lubber-de added this to the 2.8.0 milestone Sep 5, 2019
@lubber-de lubber-de added type/bug Any issue which is a bug or PR which fixes a bug and removed state/awaiting-investigation Anything which needs more investigation labels Sep 5, 2019
y0hami pushed a commit that referenced this issue Sep 6, 2019
This PR aim to fix (or at least drastically reduce) the broken date format when it's typed through keyboard. It's a bit hacky, since it only reverse supposed days and month when the setting monthFirst is defined to true, but I think this little piece of code will cover 98% of cases.

Closes #829 #986
@y0hami y0hami added the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Sep 6, 2019
@y0hami y0hami closed this as completed Nov 14, 2019
@y0hami y0hami removed the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Projects
None yet
Development

No branches or pull requests

4 participants