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

Add date format settings for D.M.YYYY, DD.MM.YYYY MM/DD/YYYY and YYYY-MM-DD #1482

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
const PRIV_WEBHOOKS = 'webhooks';
const PRIV_BLOCKED_PERIODS = 'blocked_periods';

const DATE_FORMAT_DMY = 'DMY';
const DATE_FORMAT_MDY = 'MDY';
const DATE_FORMAT_YMD = 'YMD';
const DATE_FORMAT_DMY = 'DD.MM.YYYY';
const DATE_FORMAT_MDY = 'MM/DD/YYYY';
const DATE_FORMAT_YMD = 'YYYY-MM-DD';

const TIME_FORMAT_REGULAR = 'regular';
const TIME_FORMAT_MILITARY = 'military';
Expand Down
7 changes: 4 additions & 3 deletions application/helpers/date_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function get_date_format(): string
$date_format = setting('date_format');

return match ($date_format) {
'DMY' => 'd/m/Y',
'MDY' => 'm/d/Y',
'YMD' => 'Y/m/d',
'D.M.YYYY' => 'j.n.Y',
'DD.MM.YYYY' => 'd.m.Y',
'MM/DD/YYYY' => 'm/d/Y',
'YYYY-MM-DD' => 'Y-m-d',
default => throw new RuntimeException('Invalid date format value: ' . $date_format),
};
}
Expand Down
84 changes: 42 additions & 42 deletions application/migrations/004_add_date_format_setting.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <[email protected]>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.1.0
* ---------------------------------------------------------------------------- */

class Migration_Add_date_format_setting extends EA_Migration
{
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
if (!$this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) {
$this->db->insert('settings', [
'name' => 'date_format',
'value' => 'DMY',
]);
}
}

/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
if ($this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) {
$this->db->delete('settings', ['name' => 'date_format']);
}
}
}
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <[email protected]>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.1.0
* ---------------------------------------------------------------------------- */
class Migration_Add_date_format_setting extends EA_Migration
{
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
if (!$this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) {
$this->db->insert('settings', [
'name' => 'date_format',
'value' => 'DMY',
]);
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
if ($this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) {
$this->db->delete('settings', ['name' => 'date_format']);
}
}
}
37 changes: 37 additions & 0 deletions application/migrations/059_new_date_format_setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <[email protected]>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.1.0
* ---------------------------------------------------------------------------- */

class Migration_Add_date_format_setting extends EA_Migration
{
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->db->update('settings', ['value' => 'DD.MM.YYYY'], ['name' => 'date_format']);
}

/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
if ($this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) {
$this->db->delete('settings', ['name' => 'date_format']);
}
}
}
54 changes: 47 additions & 7 deletions application/views/pages/general_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class="form-control">
<?= lang('theme') ?>
</label>

<select id="theme" data-field="theme" class="form-control">
<select id="theme" data-field="theme" class="form-select">
<?php foreach (vars('available_themes') as $available_theme): ?>
<option value="<?= $available_theme ?>">
<?= ucfirst($available_theme) ?>
Expand All @@ -147,10 +147,11 @@ class="form-control">
<label class="form-label" for="date-format">
<?= lang('date_format') ?>
</label>
<select class="form-control" id="date-format" data-field="date_format">
<option value="DMY">DMY</option>
<option value="MDY">MDY</option>
<option value="YMD">YMD</option>
<select class="form-select" id="date-format" data-field="date_format">
<option value="D.M.YYYY">D.M.YYYY</option>
<option value="DD.MM.YYYY">DD.MM.YYYY</option>
<option value="MM/DD/YYYY">MM/DD/YYYY</option>
<option value="YYYY-MM-DD">YYYY-MM-DD</option>
</select>
<div class="form-text text-muted">
<small>
Expand All @@ -162,7 +163,7 @@ class="form-control">
<label class="form-label" for="time-format">
<?= lang('time_format') ?>
</label>
<select class="form-control" id="time-format" data-field="time_format">
<select class="form-select" id="time-format" data-field="time_format">
<option value="<?= TIME_FORMAT_REGULAR ?>">H:MM AM/PM</option>
<option value="<?= TIME_FORMAT_MILITARY ?>">HH:MM</option>
</select>
Expand All @@ -176,7 +177,7 @@ class="form-control">
<label class="form-label" for="first-weekday">
<?= lang('first_weekday') ?>
</label>
<select class="form-control" id="first-weekday" data-field="first_weekday">
<select class="form-select" id="first-weekday" data-field="first_weekday">
<option value="sunday"><?= lang('sunday') ?></option>
<option value="monday"><?= lang('monday') ?></option>
<option value="tuesday"><?= lang('tuesday') ?></option>
Expand All @@ -191,8 +192,47 @@ class="form-control">
</small>
</div>
</div>

<div class="mb-3">
<label class="form-label" for="default-language">
<?= lang('default_language') ?>
<span class="text-danger" hidden>*</span>
</label>
<select id="default-language" class="form-select required" data-field="default_language">
<?php foreach (vars('available_languages') as $available_language): ?>
<option value="<?= $available_language ?>">
<?= ucfirst($available_language) ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-text text-muted">
<small>
<?= lang('default_language_hint') ?>
</small>
</div>
</div>

<div class="mb-3">
<label class="form-label" for="default-timezone">
<?= lang('default_timezone') ?>
<span class="text-danger" hidden>*</span>
</label>
<?php component('timezone_dropdown', [
'attributes' =>
'id="default-timezone" data-field="default_timezone" class="form-control required"',
'grouped_timezones' => vars('grouped_timezones'),
]); ?>
</div>
<div class="form-text text-muted">
<small>
<?= lang('default_timezone_hint') ?>
</small>
</div>

</div>
</div>

<?php slot('after_primary_fields'); ?>
</fieldset>
</form>
</div>
Expand Down
9 changes: 5 additions & 4 deletions assets/js/utils/calendar_default_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,12 +1444,13 @@ App.Utils.CalendarDefaultView = (function () {
let columnFormat = {};

switch (vars('date_format')) {
case 'DMY':
columnFormat = 'ddd D/M';
case 'D.M.YYYY':
case 'DD.MM.YYYY':
columnFormat = 'ddd D.M';
break;

case 'MDY':
case 'YMD':
case 'MM/DD/YYYY':
case 'YYYY-MM-DD':
columnFormat = 'ddd M/D';
break;

Expand Down
9 changes: 5 additions & 4 deletions assets/js/utils/calendar_table_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,13 @@ App.Utils.CalendarTableView = (function () {
let columnFormat = '';

switch (vars('date_format')) {
case 'DMY':
columnFormat = 'ddd D/M';
case 'D.M.YYYY':
case 'DD.MM.YYYY':
columnFormat = 'ddd D.M';
break;

case 'MDY':
case 'YMD':
case 'MM/DD/YYYY':
case 'YYYY-MM-DD':
columnFormat = 'ddd M/D';
break;

Expand Down
19 changes: 7 additions & 12 deletions assets/js/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ window.App.Utils.Date = (function () {
* Format a YYYY-MM-DD HH:mm:ss date string.
*
* @param {String|Date} dateValue The date string to be formatted.
* @param {String} [dateFormatType] The date format type value ("DMY", "MDY" or "YMD").
* @param {String} [dateFormatType] The date format type value ("D.M.YYYY", "DD.MM.YYYY", "MM/DD/YYYY" or "YYYY-MM-DD").
* @param {String} [timeFormatType] The time format type value ("regular", "military").
* @param {Boolean} [withHours] Whether to add hours to the returned string.

* @return {String} Returns the formatted string.
*/
function format(dateValue, dateFormatType = 'YMD', timeFormatType = 'regular', withHours = false) {
function format(dateValue, dateFormatType = 'YYYY-MM-DD', timeFormatType = 'regular', withHours = false) {
const dateMoment = moment(dateValue);

if (!dateMoment.isValid()) {
Expand All @@ -35,16 +35,11 @@ window.App.Utils.Date = (function () {
let dateFormat;

switch (dateFormatType) {
case 'DMY':
dateFormat = 'DD/MM/YYYY';
break;

case 'MDY':
dateFormat = 'MM/DD/YYYY';
break;

case 'YMD':
dateFormat = 'YYYY/MM/DD';
case 'D.M.YYYY':
case 'DD.MM.YYYY':
case 'MM/DD/YYYY':
case 'YYYY-MM-DD':
dateFormat = dateFormatType;
break;

default:
Expand Down
12 changes: 7 additions & 5 deletions assets/js/utils/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ window.App.Utils.UI = (function () {
*/
function getDateFormat() {
switch (vars('date_format')) {
case 'DMY':
return 'd/m/Y';
case 'MDY':
case 'D.M.YYYY':
return 'j.n.Y';
case 'DD.MM.YYYY':
return 'd.m.Y';
case 'MM/DD/YYYY':
return 'm/d/Y';
case 'YMD':
return 'Y/m/d';
case 'YYYY-MM-DD':
return 'Y-m-d';
default:
throw new Error('Invalid date format value.');
}
Expand Down