mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-29 01:52:24 +03:00
Add the date_helper.php to the project
This commit is contained in:
parent
fc231fe11f
commit
270c261a58
2 changed files with 142 additions and 0 deletions
|
@ -69,6 +69,7 @@ $autoload['helper'] = [
|
|||
'array',
|
||||
'asset',
|
||||
'config',
|
||||
'date',
|
||||
'debug',
|
||||
'env',
|
||||
'file',
|
||||
|
|
141
application/helpers/date_helper.php
Normal file
141
application/helpers/date_helper.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
if ( ! function_exists('get_date_format'))
|
||||
{
|
||||
/**
|
||||
* Get the date format based on the current settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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',
|
||||
default => throw new RuntimeException('Invalid date format value: ' . $date_format),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('get_time_format'))
|
||||
{
|
||||
/**
|
||||
* Get the time format based on the current settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_time_format(): string
|
||||
{
|
||||
$time_format = setting('time_format');
|
||||
|
||||
return match ($time_format)
|
||||
{
|
||||
'military' => 'H:i',
|
||||
'regular' => 'g:i a',
|
||||
default => throw new RuntimeException('Invalid time format value: ' . $time_format),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('get_date_time_format'))
|
||||
{
|
||||
/**
|
||||
* Get the date-time format based on the current settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_date_time_format(): string
|
||||
{
|
||||
return get_date_format() . ' ' . get_time_format();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! function_exists('format_date'))
|
||||
{
|
||||
/**
|
||||
* Format a date string based on the current app settings.
|
||||
*
|
||||
* @param DateTimeInterface|string $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function format_date(DateTimeInterface|string $value): string
|
||||
{
|
||||
$value_date_time = $value;
|
||||
|
||||
if (is_string($value_date_time))
|
||||
{
|
||||
$value_date_time = new DateTime($value);
|
||||
}
|
||||
|
||||
return $value_date_time->format(get_date_format());
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('format_time'))
|
||||
{
|
||||
/**
|
||||
* Format a time string based on the current app settings.
|
||||
*
|
||||
* @param DateTimeInterface|string $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function format_date(DateTimeInterface|string $value): string
|
||||
{
|
||||
$value_date_time = $value;
|
||||
|
||||
if (is_string($value_date_time))
|
||||
{
|
||||
$value_date_time = new DateTime($value);
|
||||
}
|
||||
|
||||
return $value_date_time->format(get_time_format());
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('format_date_time'))
|
||||
{
|
||||
/**
|
||||
* Format a time string based on the current app settings.
|
||||
*
|
||||
* @param DateTimeInterface|string $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function format_date_time(DateTimeInterface|string $value): string
|
||||
{
|
||||
$value_date_time = $value;
|
||||
|
||||
if (is_string($value_date_time))
|
||||
{
|
||||
$value_date_time = new DateTime($value);
|
||||
}
|
||||
|
||||
return $value_date_time->format(get_date_time_format());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue