joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.73k stars 3.64k forks source link

Display month without leading zero #27152

Open thanhnv37 opened 4 years ago

thanhnv37 commented 4 years ago

Is your feature request related to a problem? Please describe.

https://docs.joomla.org/Calendar_form_field_type

Could you please add a new date formatting option for representation of the month without leading zero.

Describe the solution you'd like

Additional context

infograf768 commented 4 years ago

The calendar uses the % format in the strings For French: DATE_FORMAT_CALENDAR_DATE="%d-%m-%Y" DATE_FORMAT_CALENDAR_DATETIME="%d-%m-%Y %H:%M:%S"

There is no way to display months without leading zero in this format. See https://www.php.net/manual/en/function.strftime.php for allowed formats.

thanhnv37 commented 4 years ago

Hello @infograf768 Thank you for your answers. But I don't use PHP date format function, I use the Javascript date helper library defined in file below media/system/js/fields/calendar-locales/date/gregorian/date-helper.js

I checked this library and it currently does not support formatting option for displaying month without leading zero.

infograf768 commented 4 years ago

The display format, when translateformat is true, is set in /libraries/joomla/form/fields/calendar.php and it uses the percent format type but indeed this is not where the 0 is added.

The library is adding a 0 when the month is less than 10 line 355 s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12

Which means we have no choice.

we could maybe add there (but I am not sure at all as %n is not an acceptable % date format but a newline) s["%n"] = 1+m; // month, range 1 to 12 which would let use %n as the variable in the lang strings

But, unhappily, %n is already used s["%n"] = "\n"; // a newline character

@dgrammatiko anything we can do?

dgrammatiko commented 4 years ago

I checked this library and it currently does not support formatting option for displaying month without leading zero.

Is that when you're inserting a value in the input or parsing the default value thrown by PHP?

thanhnv37 commented 4 years ago

@dgrammatiko I am developer of Geek ElasticSearch component, it uses Javascript to query and parse data directly from Elasticsearch server.

dgrammatiko commented 4 years ago

@thanhnv37

const entryMonth = date.getMonth()
const passThisMonth = entryMonth() < 10 ? `0${entryMonth}` : `${entryMonth}`
thanhnv37 commented 4 years ago

@dgrammatiko Please read a comment of @infograf768 The date helper script does not support formatting option to display week without leading zero, and I hope that you can support this feature on future releases of Joomla.

Thanks

brianteeman commented 4 years ago

@thanhnv37 As a developer the best and fastest way to support this is for you to submit a pull request