new pisilinux web sites

This commit is contained in:
Erkan IŞIK
2026-07-01 16:44:17 +03:00
commit b58488b586
21740 changed files with 2066209 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Singleton;
class DT
{
/**
* Protected class
*
* @var string
*/
protected $class;
/**
* Protected data
*
* @var mixed
*/
protected $data;
/**
* Magic Call
*
* @param string $method
* @param string $parameters
*
* @return $this
*/
public function __call($method, $parameters)
{
$this->data = $this->class->$method($this->data, ...$parameters);
return $this;
}
/**
* Get ZN\DateTime\Date class
*
* @param string $data
*
* @return DT
*/
public function date(string $data, $class = 'Date')
{
$this->class = Singleton::class('ZN\DateTime\\' . $class);
$this->data = $data;
return $this;
}
/**
* Get ZN\DateTime\Time class
*
* @param string $data
*
* @return DT
*/
public function time(string $data)
{
return $this->date($data, 'Time');
}
/**
* Apply changes
*
* @return mixed
*/
public function get(?string $output = NULL)
{
if( $output !== NULL )
{
return $this->class->convert($this->data, $output);
}
return $this->data ?? false;
}
}
+315
View File
@@ -0,0 +1,315 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Lang;
class Date extends DateTimeCommon implements DateTimeCommonInterface
{
/**
* Protected is days
*
* @var array
*/
protected $isDays =
[
'isSunday',
'isMonday',
'isTuesday',
'isWednesday',
'isThursday',
'isFriday',
'isSaturday'
];
/**
* Protected is months
*
* @var array
*/
protected $isMonths =
[
'isJanuary',
'isFebruary',
'isMarch',
'isApril',
'isMay',
'isJune',
'isJuly',
'isAugust',
'isSeptember',
'isOctober',
'isNovember',
'isDecember'
];
/**
* Magic call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
if( $method[0] === 'l' )
{
$method = substr($method, 1); $langParam = end($parameters);
$this->lang = isset($this->config['date'][$langParam]) ? $langParam : Lang::get();
$return = $this->$method(...$parameters);
$this->lang = NULL;
return $return;
}
$parts = $this->splitUpperCase($method);
$methodType = $parts[0] ?? NULL;
if( in_array($method, $this->isDays) )
{
return $this->isDay($method, $parameters[0] ?? NULL);
}
elseif( in_array($method, $this->isMonths) )
{
return $this->isMonth($method, $parameters[0] ?? NULL);
}
elseif( in_array($methodType, ['next', 'prev']) )
{
return $this->$methodType($parameters[0] ?? NULL, ($type = strtolower($parts[1] ?? '')) . ($parts[2] ?? NULL), $type);
}
return parent::__call($method, $parameters);
}
/**
* Day count
*
* @param string $date = NULL
*
* @return int
*/
public function dayCount(?string $date = NULL) : int
{
$date = $date ?? $this->now();
return cal_days_in_month(CAL_GREGORIAN, (int) $this->convert($date, 'm'), (int) $this->convert('Y'));
}
/**
* Gets year quarter
*
* @param string $date = NULL
*
* @return string
*/
public function quarter(?string $date = NULL)
{
return ceil($this->convert($date ?? $this->now(), 'n') / 3);
}
/**
* Gets current datetime.
*
* @return string
*/
public function now()
{
return date('Y-m-d H:i:s');
}
/**
* Date check
*
* @param string $date
*
* @return bool
*/
public function check(string $date) : bool
{
$dateEx = explode('/', $this->convert($date, '{year}/{monthNumber}/{dayNumber}'));
$validDate = implode('/', $dateEx);
if( $date !== $validDate && $validDate === '1970/1/1' )
{
return false;
}
return checkdate($dateEx[1] ?? NULL, $dateEx[2] ?? NULL, $dateEx[0] ?? NULL);
}
/**
* Gives the active date information.
*
* @param string $clock = '%H:%M:%S'
*
* @return string
*/
public function current(string $date = 'd.m.Y') : string
{
return $this->returnDatetime($date);
}
/**
* Gives the active date information.
*
* @param string $clock = '%H:%M:%S'
*
* @return string
*/
public function default(string $date = '{year}/{monthNumber0}/{dayNumber0}') : string
{
return $this->returnDatetime($date);
}
/**
* Converts date information.
*
* @param string $date
* @param string $format = '%d-%B-%Y %A, %H:%M:%S'
*
* @return string
*/
public function convert(string $date, string $format = 'd-m-Y H:i:s') : string
{
return $this->returnDatetime($format, strtotime($date));
}
/**
* Generates standard date and time information.
*
* @return string
*/
public function standart() : string
{
return $this->returnDatetime("d F Y l, H:i:s");
}
/**
* Is past
*
* @string $date
*
* @return bool
*/
public function isPast(string $date) : bool
{
return $this->compare($date, '<', $this->set('Y/m/d'));
}
/**
* Checks whether the date is the weekend.
*
* 5.7.6[added]
*
* @param string $date
*
* @return bool
*/
public function isWeekend(?string $date = NULL) : bool
{
$weekDayNumber = $this->convert($date ?? $this->default(), '{weekDayNumber}');
return in_array($weekDayNumber, [6, 7]);
}
/**
* Give it today.
*
* @return string
*/
public function today(?string $date = NULL, $type = 'dayName') : string
{
$type = '{'.$type.'}';
if( $date === NULL )
{
return $this->set($type);
}
return $this->convert($date, $type);
}
/**
* Give it today day number.
*
* @return string
*/
public function todayNumber(?string $date = NULL) : string
{
return $this->today($date, 'dayNumber');
}
/**
* Get yesterday.
*
* 5.7.6[added]
*
* @param string $date = NULL
*
* @return string
*/
public function yesterday(?string $date = NULL) : string
{
return $this->prev($date, 'day');
}
/**
* Get yesterday.
*
* 5.7.6[added]
*
* @param string $date = NULL
*
* @return string
*/
public function tomorrow(?string $date = NULL) : string
{
return $this->next($date, 'day');
}
/**
* Protected next
*/
protected function next(?string $date = NULL, $type = 'day', $unit = 'day', $signal = '+') : string
{
$calculate = $this->calculate($date ?? $this->default(), $signal . '1' . $unit, 'Y/m/d');
return $this->convert($calculate, '{'.$type.'}');
}
/**
* Protected prev
*/
protected function prev(?string $date = NULL, $type = 'day' , $unit = 'day') : string
{
return $this->next($date, $type, $unit, '-');
}
/**
* Protected is day for call method
*/
protected function isDay($method, $date)
{
return $this->today($date) === ltrim($method, 'is');
}
/**
* Protected is day for call method
*/
protected function isMonth($method, $date)
{
return $this->convert($date ?? $this->default(), '{month}') === ltrim($method, 'is');
}
}
@@ -0,0 +1,325 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\IS;
use ZN\Config;
use ZN\Datatype;
use ZN\Helpers\Rounder;
use ZN\Helpers\Converter;
class DateTimeCommon
{
/**
* Keeps Class Name
*
* @var string
*/
protected $className = 'ZN\DateTime\Date';
/**
* Keeps datetime config.
*
* @var array
*/
protected $config;
/**
* Keeps datetime lang.
*
* @var array
*/
protected $lang;
/**
* Magic Constructor
*/
public function __construct()
{
$this->config = Config::default('ZN\DateTime\DateTimeDefaultConfiguration')
::get('Expressions');
}
/**
* Protected split upper case
*/
protected function splitUpperCase($method)
{
return Datatype::splitUpperCase($method);
}
/**
* Magic call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
$parts = $this->splitUpperCase($method);
$methodType = $parts[0] ?? NULL;
$expression = strtolower($parts[1] ?? '') ?? NULL;
if( $methodType === 'diff' )
{
return $this->different($parameters[0], $parameters[1] ?? NULL, $expression, strtolower($parameters[2] ?? $parts[2] ?? ''));
}
elseif( in_array($methodType, ['add', 'remove']) )
{
return $this->$methodType($parameters[0] ?? NULL, $parameters[1] ?? 1, $expression);
}
elseif( $methodType === 'current' )
{
return $this->set('{'.ltrim($method, $methodType).'}');
}
return false; // @codeCoverageIgnore
}
/**
* Sets locale
*
* 5.7.6[added]
*
* @param string $parameters
*
* @return this
*/
public function locale(...$parameters)
{
setlocale(LC_ALL, ...$parameters);
return $this;
}
/**
* Sets zone
*
* 5.7.6[added]
*
* @param string $timezone
*
* @return this
*/
public function zone(string $timezone)
{
# Sets the timezone.
if( IS::timeZone($timezone) )
{
date_default_timezone_set($timezone);
return $this;
}
throw new Exception\InvalidTimezoneException(NULL, $timezone);
}
/**
* Compare dates
*
* @param string $value1
* @param string $condition
* @param string $value2
*
* @return bool
*/
public function compare(string $value1, string $condition, string $value2) : bool
{
$value1 = $this->toNumeric($value1);
$value2 = $this->toNumeric($value2);
return version_compare($value1, $value2, $condition);
}
/**
* Turns historical data into numeric data.
*
* @param string $dateFormat
* @param int $now = NULL
*
* @return int
*/
public function toNumeric(string $dateFormat, ?int $now = NULL) : int
{
if( $now === NULL )
{
$now = time();
}
return strtotime($this->returnDatetime($dateFormat), $now);
}
/**
* Converts time data to readable form.
*
* @param int $time
* @param string $dateFormat = 'Y-m-d H:i:s'
*
* @return string
*/
public function toReadable(int $time, string $dateFormat = 'Y-m-d H:i:s') : string
{
return $this->returnDatetime($dateFormat, $time);
}
/**
* Calculates between dates.
*
* @param string $input
* @param string $calculate
* @param string $output = 'Y-m-d'
*
* @return string
*/
public function calculate(string $input, string $calculate, string $output = 'Y-m-d', ?string $type = NULL) : string
{
if( ! preg_match('/^[0-9]/', $input) )
{
$input = $this->returnDatetime($input);
}
# 5.3.5[added]
if( get_called_class() === 'ZN\DateTime\Time' && $output === 'Y-m-d' )
{
$output = 'H:i:s';
}
# 8.0.3[added]
else if( in_array($type, ['hour', 'minute', 'second']) )
{
$output = 'Y-m-d H:i:s';
}
return $this->returnDatetime($output, strtotime($calculate, strtotime($input)));
}
/**
* Sets the date and time.
*
* @param string $exp
*
* @return string
*/
public function set(string $exp) : string
{
return $this->returnDatetime($exp);
}
/**
* Protected Convert
*/
protected function convertPattern($change)
{
$chars = Properties::$setDateFormatChars;
$chars['{century-}|{cen-}'] = $century = substr(date('Y'), 0, 2);
$chars['{century}|{cen}'] = $century + 1;
$chars = Datatype::multikey($chars);
return str_ireplace(array_keys($chars), array_values($chars), $change ?? '');
}
/**
* Protected Date Time
*/
protected function returnDatetime($format, $timestamp = NULL)
{
$classicFormat = $this->convertPattern($format);
$timestamp = $timestamp ?? time();
if( $this->lang )
{
$chars = str_split($classicFormat);
$dateFunction = function($type, $char, $timestamp)
{
return str_ireplace($this->config['date']['en'][$type], $this->config['date'][$this->lang][$type], date($char, $timestamp));
};
$newDate = '';
foreach( $chars as $char )
{
switch( $char )
{
case 'M': $newDate .= $dateFunction('shortMonths' , $char, $timestamp); break;
case 'D': $newDate .= $dateFunction('shortWeekdays', $char, $timestamp); break;
case 'F': $newDate .= $dateFunction('months' , $char, $timestamp); break;
case 'l': $newDate .= $dateFunction('weekdays' , $char, $timestamp); break;
default : $newDate .= in_array($char, Properties::$setDateFormatChars) ? date($char, $timestamp) : $char;
}
}
return $newDate;
}
return date($classicFormat, $timestamp);
}
/**
* Protected add day
*/
protected function add(?string $datetime = NULL, int $count = 1, $type = 'day', $signal = '+') : string
{
if( ! $this->check((string) $datetime) && is_numeric($datetime) && $count = 1 )
{
$count = $datetime;
$datetime = $this->default();
}
return $this->calculate($datetime ?? $this->default(), $signal . $count . $type, 'Y-m-d', $type);
}
/**
* Protected remove day
*/
protected function remove(?string $datetime = NULL, int $count = 1, $type = 'day') : string
{
return $this->add($datetime, $count, $type, '-');
}
/**
* Protected different
*/
protected function different($date1, $date2, $output, $round = NULL) : Float
{
if( $date2 === NULL )
{
$date2 = $date1;
$date1 = $this->default();
}
$return = Converter::time($this->toNumeric($date2) - $this->toNumeric($date1), 'second', $output);
if( ! empty($round) )
{
return $this->round($round, $return);
}
return $return;
}
/**
* Protected round
*/
protected function round($round, $return)
{
if( in_array($round, ['up', 'down', 'average']) )
{
return Rounder::$round($return);
}
return Rounder::average($return); // @codeCoverageIgnore
}
}
@@ -0,0 +1,122 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface DateTimeCommonInterface
{
/**
* Sets timezone
*
* 5.7.6[added]
*
* @param string $timezone
*
* @return this
*/
public function zone(string $timezone);
/**
* Sets locale
*
* 5.7.6[added]
*
* @param string $parameters
*
* @return this
*/
public function locale(...$parameters);
/**
* Is past
*
* @string $datetime
*
* @return bool
*/
public function isPast(string $datetime) : bool;
/**
* Compare dates
*
* @param string $value1
* @param string $condition
* @param string $value2
*
* @return bool
*/
public function compare(string $value1, string $condition, string $value2) : bool;
/**
* Turns historical data into numeric data.
*
* @param string $dateFormat
* @param int $now = NULL
*
* @return int
*/
public function toNumeric(string $dateFormat, ?int $now = NULL) : int;
/**
* Converts time data to readable form.
*
* @param int $time
* @param string $dateFormat = 'Y-m-d H:i:s'
*
* @return string
*/
public function toReadable(int $time, string $dateFormat = 'Y-m-d H:i:s') : string;
/**
* Calculates between dates.
*
* @param string $input
* @param string $calculate
* @param string $output = 'Y-m-d'
* @param string $type = NULL
*
* @return string
*/
public function calculate(string $input, string $calculate, string $output = 'Y-m-d', ?string $type = NULL) : string;
/**
* Sets the date and time.
*
* @param string $exp
*
* @return string
*/
public function set(string $exp) : string;
/**
* Gives the active time information.
*
* @param string $clock
*
* @return string
*/
public function current(string $clock) : string;
/**
* Converts date information.
*
* @param string $date
* @param string $format
*
* @return string
*/
public function convert(string $date, string $format) : string;
/**
* Generates standard date and time information.
*
* @return string
*/
public function standart() : string;
}
@@ -0,0 +1,45 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
/**
* Default Configuration
*
* Enabled when the configuration file can not be accessed.
*/
class DateTimeDefaultConfiguration
{
/*
|--------------------------------------------------------------------------
| Date Languages
|--------------------------------------------------------------------------
|
| Language equivalents for the Date class, depending on the language.
|
*/
protected $date =
[
'tr' =>
[
'months' => ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
'shortMonths' => ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara'],
'weekdays' => ['Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'],
'shortWeekdays' => ['Paz', 'Pts', 'Sal', 'Çar', 'Per', 'Cum', 'Cts']
],
'en' =>
[
'months' => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
'shortMonths' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
'weekdays' => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
'shortWeekdays' => ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
]
];
}
@@ -0,0 +1,21 @@
<?php namespace ZN\DateTime\Exception;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Exception;
class InvalidDateException extends Exception
{
const lang =
[
'tr' => '% bilgisi geçerli bir [tarih/zaman] değildir!',
'en' => '% information is not a valid [date/time]!'
];
}
@@ -0,0 +1,21 @@
<?php namespace ZN\DateTime\Exception;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Exception;
class InvalidTimezoneException extends Exception
{
const lang =
[
'tr' => '% bilgisi geçerli bir zaman bölgesi değildir!',
'en' => '% information is not a valid time zone!'
];
}
+52
View File
@@ -0,0 +1,52 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Properties
{
/**
* Sets date format chars.
*
* @var array
*/
public static $setDateFormatChars =
[
'{day-}|{shortDayName}|{shortDay}|{SD}' => 'D',
'{day}|{dayName}|{D}' => 'l',
'{dayInWeek}|{weekDayNumber}|{weekDayNum}|{WDN}' => 'N',
'{dayInMonth}|{dayNum0}|{dayNumber0}|{DN0}' => 'd',
'{dayInMonth-}|{dayNum}|{dayNumber}|{DN}' => 'j',
'{dayInYear}|{yearDayNumber0}|{yearDayNum0}|{YDN0}' => 'z',
'{dayInYear-}|{yearDayNumber}|{yearDayNum}|{YDN}' => 'z',
'{dayCountInMonth}|{totalDays}|{TD}' => 't',
'{weekInYear}|{weekNumber}|{weekNum}|{WN}' => 'W',
'{month-}|{shortMonthName}|{sortMonth}|{SM}' => 'M',
'{month}|{monthName}|{month}|{mon}|{M}' => 'F',
'{monthInYear}|{monthNumber0}|{monNum0}|{MN0}' => 'm',
'{monthInYear-}|{monthNumber}|{monNum}|{MN}' => 'n',
'{century}|{cen}' => 'auto',
'{century-}|{cen-}' => 'auto',
'{year-}|{shortYear}|{SY}' => 'y',
'{year}|{Y}' => 'Y',
'{isLeapYear}|{ILY}' => 'L',
'{hour}|{hour024}|{H024}' => 'H',
'{hour-}|{hour24}|{H24}' => 'G',
'{clock}|{hour012}|{H012}' => 'h',
'{clock-}|{hour12}|{H12}' => 'g',
'{minute}|{minute0}|{min}|{min0}' => 'i',
'{second}|{second0}|{sec}|{sec0}' => 's',
'{am}|{AMPM}' => 'A',
'{am-}|{ampm}' => 'a',
'{msecond}|{microSecond}|{micSec}|{MS}' => 'u',
'{iso}' => 'c',
'{rfc}' => 'r',
'{unix}' => 'U'
];
}
+124
View File
@@ -0,0 +1,124 @@
<?php namespace ZN\DateTime;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Time extends DateTimeCommon implements DateTimeCommonInterface
{
/**
* Magic call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
$parts = $this->splitUpperCase($method);
$methodType = $parts[0] ?? NULL;
if( in_array($methodType, ['next', 'prev']) )
{
return $this->$methodType($parameters[0] ?? NULL, ltrim($method, $methodType));
}
return parent::__call($method, $parameters);
}
/**
* Date check
*
* @param string $time
*
* @return bool
*/
public function check(string $time) : bool
{
return (new Date)->check($time);
}
/**
* Is past
*
* @string $time
*
* @return bool
*/
public function isPast(string $time) : bool
{
return $this->compare($time, '<', $this->set('{hour}:{minute}:{second}'));
}
/**
* Gives the active time information.
*
* @param string $clock = '%H:%M:%S'
*
* @return string
*/
public function current(string $clock = 'H:i:s') : string
{
return $this->returnDatetime($clock);
}
/**
* Gives the active date information.
*
* @param string $clock = '%H:%M:%S'
*
* @return string
*/
public function default(string $time = '{hour}:{minute}:{second}') : string
{
return $this->returnDatetime($time);
}
/**
* Converts date information.
*
* @param string $date
* @param string $format = '%d-%B-%Y %A, %H:%M:%S'
*
* @return string
*/
public function convert(string $date, string $format = 'd-m-Y H:i:s') : string
{
return $this->returnDatetime($format, strtotime($date));
}
/**
* Generates standard date and time information.
*
* @return string
*/
public function standart() : string
{
return (new Date)->standart();
}
/**
* Protected next
*/
protected function next(?string $time = NULL, $type = 'hour', $signal = '+') : string
{
$calculate = $this->calculate($time ?? $this->default(), $signal . '1' . $type);
return $this->convert($calculate, '{'.$type.'}');
}
/**
* Protected prev
*/
protected function prev(?string $time = NULL, $type = 'hour') : string
{
return $this->next($time, $type, '-');
}
}