PHP 클래스 jDateTime, jDateTime

Copyright (c) 2012 Sallar Kaboli http://sallar.me The MIT License (MIT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 2- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Original Jalali to Gregorian (and vice versa) convertor: Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi List of supported timezones can be found here: http://www.php.net/manual/en/timezones.php
또한 보기: DateTime
저자: Sallar Kaboli ([email protected])
저자: Omid Pilevar ([email protected])
파일 보기 프로젝트 열기: sallar/jdatetime 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( $convert = null, $jalali = null, $timezone = null ) jDateTime::Constructor
checkdate ( $month, $day, $year, $jalali = null ) : boolean jDateTime::Checkdate
convertFormatToFormat ( string $jalaliFormat, string $georgianFormat, string $timeString, null | DateTimeZone | string $timezone = null ) : string Convert a formatted string from Georgian Calendar to Jalali Calendar.
date ( $format, $stamp = false, $convert = null, $jalali = null, $timezone = null ) : string jDateTime::Date
gDate ( $format, $stamp = false, $timezone = null ) : string jDateTime::gDate
getdate ( $timestamp = null ) : An jDateTime::getdate
mktime ( $hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null ) : integer jDateTime::Mktime
strftime ( $format, $stamp = false, $convert = null, $jalali = null, $timezone = null ) : string jDateTime::Strftime
toGregorian ( $j_y, $j_m, $j_d ) Jalali to Gregorian Conversion Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi
toJalali ( $g_y, $g_m, $g_d ) Gregorian to Jalali Conversion Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi

비공개 메소드들

메소드 설명
convertNumbers ( $matches ) Converts latin numbers to farsi script
div ( $a, $b ) Division
filterArray ( $needle, $heystack, $always = [] ) Filters out an array
getDayNames ( $day, $shorten = false, $len = 1, $numeric = false ) Returns correct names for week days
getMonthNames ( $month, $shorten = false, $len = 3 ) Returns correct names for months
substr ( $str, $start, $len ) Substring helper

메소드 상세

__construct() 공개 메소드

Pass these parameteres when creating a new instance of this Class, and they will be used as defaults. e.g $obj = new jDateTime(false, true, 'Asia/Tehran'); To use system defaults pass null for each one or just create the object without any parameters.
저자: Sallar Kaboli
public __construct ( $convert = null, $jalali = null, $timezone = null )
$convert bool Converts numbers to Farsi
$jalali bool Converts date to Jalali
$timezone string Timezone string

checkdate() 공개 정적인 메소드

Checks the validity of the date formed by the arguments. A date is considered valid if each parameter is properly defined. works like php's built in checkdate() function. Leap years are taken into consideration. e.g: $obj->checkdate(10, 21, 1390); // Return true $obj->checkdate(9, 31, 1390); // Return false You can force gregorian checkdate if system default is jalali and you need to check based on gregorian date $check = $obj->checkdate(12, 31, 2011, false);
저자: Omid Pilevar
public static checkdate ( $month, $day, $year, $jalali = null ) : boolean
$month int The month is between 1 and 12 inclusive.
$day int The day is within the allowed number of days for the given month.
$year int The year is between 1 and 32767 inclusive.
$jalali bool (Optional) pass false if you want to input gregorian time
리턴 boolean

convertFormatToFormat() 공개 정적인 메소드

This will be useful to directly convert time strings coming from databases. Example: Suppose this comes from database $a = '2016-02-14 14:20:38'; $date = \jDateTime::convertFormatToFormat('Y-m-d H:i:s', 'Y-m-d H:i:s', $a); $date will now be '۱۳۹۴-۱۱-۲۵ ۱۴:۲۰:۳۸'
저자: Vahid Fazlollahzade
public static convertFormatToFormat ( string $jalaliFormat, string $georgianFormat, string $timeString, null | DateTimeZone | string $timezone = null ) : string
$jalaliFormat string Return format. Same as static::date(...)
$georgianFormat string The format of $timeString. See php.net/date
$timeString string The time itself, formatted as $georgianFormat
$timezone null | DateTimeZone | string The timezone. Same as static::date(...)
리턴 string

date() 공개 정적인 메소드

Formats and returns given timestamp just like php's built in date() function. e.g: $obj->date("Y-m-d H:i", time()); $obj->date("Y-m-d", time(), false, false, 'America/New_York');
저자: Sallar Kaboli
public static date ( $format, $stamp = false, $convert = null, $jalali = null, $timezone = null ) : string
$format string Acceps format string based on: php.net/date
$stamp int Unix Timestamp (Epoch Time)
$convert bool (Optional) forces convert action. pass null to use system default
$jalali bool (Optional) forces jalali conversion. pass null to use system default
$timezone string (Optional) forces a different timezone. pass null to use system default
리턴 string Formatted input

gDate() 공개 정적인 메소드

Same as jDateTime::Date method but this one works as a helper and returns Gregorian Date in case someone doesn't like to pass all those false arguments to Date method. e.g. $obj->gDate("Y-m-d") //Outputs: 2011-05-05 $obj->date("Y-m-d", false, false, false); //Outputs: 2011-05-05 Both return the exact same result.
저자: Sallar Kaboli
public static gDate ( $format, $stamp = false, $timezone = null ) : string
$format string Acceps format string based on: php.net/date
$stamp int Unix Timestamp (Epoch Time)
$timezone string (Optional) forces a different timezone. pass null to use system default
리턴 string Formatted input

getdate() 공개 정적인 메소드

Like php built-in function, returns an associative array containing the date information of a timestamp, or the current local time if no timestamp is given. .
저자: Meysam Pour Ganji
public static getdate ( $timestamp = null ) : An
$timestamp int The timestamp that whould convert to date information array, if NULL passed, current timestamp will be processed.
리턴 An associative array of information related to the timestamp. For see elements of the returned associative array see {@link http://php.net/manual/en/function.getdate.php#refsect1-function.getdate-returnvalues}.

mktime() 공개 정적인 메소드

Creates a Unix Timestamp (Epoch Time) based on given parameters works like php's built in mktime() function. e.g: $time = $obj->mktime(0,0,0,2,10,1368); $obj->date("Y-m-d", $time); //Format and Display $obj->date("Y-m-d", $time, false, false); //Display in Gregorian ! You can force gregorian mktime if system default is jalali and you need to create a timestamp based on gregorian date $time2 = $obj->mktime(0,0,0,12,23,1989, false);
저자: Sallar Kaboli
public static mktime ( $hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null ) : integer
$hour int Hour based on 24 hour system
$minute int Minutes
$second int Seconds
$month int Month Number
$day int Day Number
$year int Four-digit Year number eg. 1390
$jalali bool (Optional) pass false if you want to input gregorian time
$timezone string (Optional) acceps an optional timezone if you want one
리턴 integer Unix Timestamp (Epoch Time)

strftime() 공개 정적인 메소드

Format a local time/date according to locale settings built in strftime() function. e.g: $obj->strftime("%x %H", time()); $obj->strftime("%H", time(), false, false, 'America/New_York');
저자: Omid Pilevar
public static strftime ( $format, $stamp = false, $convert = null, $jalali = null, $timezone = null ) : string
$format string Acceps format string based on: php.net/date
$stamp int Unix Timestamp (Epoch Time)
$convert bool (Optional) forces convert action. pass null to use system default
$jalali bool (Optional) forces jalali conversion. pass null to use system default
$timezone string (Optional) forces a different timezone. pass null to use system default
리턴 string Formatted input

toGregorian() 공개 정적인 메소드

Jalali to Gregorian Conversion Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi
public static toGregorian ( $j_y, $j_m, $j_d )

toJalali() 공개 정적인 메소드

Gregorian to Jalali Conversion Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi
public static toJalali ( $g_y, $g_m, $g_d )