|
|
 |
VI. Funzioni CalendarIntroduzione
L'estensione calendar presenta una serie di funzioni che semplificano
la conversione tra differenti formati di calendario. Il formato intermedio
o standard è basato sul Conteggio del Giorno Giuliano. Il Conteggio
Giuliano è un conteggio di giorni che parte molto prima di qualsiasi data
la maggior parte della gente potrebbe usare (circa il 4000 a.C.). Per
convertire tra i sistemi di calendario, si deve prima convertire nel sistema
del Giorno Giuliano, poi nel sistema di calendario scelto. Il Conteggio del Giorno
Giuliano è molto diverso dal Calendario Giulano! Per maggiori
informazioni sui sistemi di calendario vedere http://www.boogle.com/info/cal-overview.html. Parti di questa
pagina sono inclusi in queste istruzioni, citate tra virgolette.
Installazione
Affinché queste funzioni siano disponibili, occorre compilare PHP con
l'opzione --enable-calendar.
La versione per Windows di PHP
ha già compilato il supporto per questo modulo. Non occorre caricare alcun modulo
addizionale per potere utilizzare queste funzioni. Configurazione di RuntimeQuesta estensione non definisce
alcuna direttiva di configurazione in php.ini Tipi di risorseQuesta estensione non definisce alcun tipo di risorsa. Costanti predefinite
Queste costanti sono definite da questa estensione e
sono disponibili solo se l'estensione è stata compilata
nel PHP o se è stata caricata dinamicamente a runtime.
Le seguenti costanti sono disponibili dal PHP 4.3.0 :
Le seguenti costanti sono disponibili dal PHP 5.0.0 :
- CAL_JEWISH_ADD_ALAFIM_GERESH
(integer)
- CAL_JEWISH_ADD_ALAFIM
(integer)
- CAL_JEWISH_ADD_GERESHAYIM
(integer)
- Sommario
- cal_days_in_month -- Restituisce il numero di giorni di un mese per un dato anno e calendario
- cal_from_jd -- Converte dal Giorno Giuliano ad un calendario
- cal_info -- Restituisce informazioni su un particolare calendario
- cal_to_jd -- Converte da un calendario a un Giorno Giuliano
- easter_date --
Restituisce un timestamp Unix della mezzanotte del giorno di Pasqua di un dato anno
- easter_days --
Restituisce il numero di giorni tra il 21 Marzo e Pasqua, dato un
anno
- FrenchToJD --
Converte una data del Calendario Repubblicano Francese in un Giorno
Giuliano
- GregorianToJD --
Converte una data Gregoriana in un Giorno Giuliano
- JDDayOfWeek -- Restituisce il giorno della settimana
- JDMonthName -- Restituisce il nome di un mese
- JDToFrench --
Converte un Giorno Giuliano in una data del Calendario Repubblicano Francese
- JDToGregorian -- Converte il Giorno Giuliano in data Gregoriana
- jdtojewish --
Converte un Giorno Giuliano nel Calendario Giudeo
- JDToJulian --
Converte un Giorno Giuliano in una data Giuliana
- jdtounix -- Converte un Giorno Giuliano in un timestamp Unix
- JewishToJD --
Converte una data del Calendario Giudeo in Giorno Giuliano
- JulianToJD --
Converte una data Giuliana in un Giorno Giuliano
- unixtojd -- Converte un timestamp Unix in un Giorno Giuliano
add a note
User Contributed Notes
Funzioni Calendar
pouya
03-Apr-2004 05:39
There is an implementation of the Persian calendar at www.farsiweb.info.
amichauer at NOSPAM dot gmx dot de
06-Dec-2003 11:07
Where is CAL_HIJRI?
# Julian Day Count To Hijri
function JDToHijri($jd)
{
$jd = $jd - 1948440 + 10632;
$n = (int)(($jd - 1) / 10631);
$jd = $jd - 10631 * $n + 354;
$j = ((int)((10985 - $jd) / 5316)) *
((int)(50 * $jd / 17719)) +
((int)($jd / 5670)) *
((int)(43 * $jd / 15238));
$jd = $jd - ((int)((30 - $j) / 15)) *
((int)((17719 * $j) / 50)) -
((int)($j / 16)) *
((int)((15238 * $j) / 43)) + 29;
$m = (int)(24 * $jd / 709);
$d = $jd - (int)(709 * $m / 24);
$y = 30*$n + $j - 30;
return array($d, $m, $y);
}
# Hijri To Julian Day Count
function HijriToJD($d, $m, $y)
{
return (int)((11 * $y + 3) / 30) +
354 * $y + 30 * $m -
(int)(($m - 1) / 2) + $d + 1948440 - 385;
}
jthome at fcgov dot com
02-Oct-2003 05:38
Had a similar problem as curlee, except I needed to create a JDE_ERP date. [format is CYYDDD]
<?php
function jde_date_create($month, $day, $year){
$jde_year_prefix = substr($year, 0, 1) - 1;
$jde_year_suffix = substr($year, -2);
$timestamp = mktime(0,0,0,$month, $day, $year);
$baseline_timestamp = mktime(0,0,0,1,0,$year);
$day_count = round(($timestamp - $baseline_timestamp)/86400);
$day_count_padded = str_pad($day_count,3,"0",STR_PAD_LEFT);
return ($jde_year_prefix . $jde_year_suffix . $day_count_padded);
}
echo jde_date_create(6,25,2000);?>
--
Jim
curlee at mindspring dot com
29-Aug-2003 02:55
I solved a problem with Julian dates that are used in the JD Edwards ERP package (running on AS/400). The Julian format for this system is as follows: CYYDDD
Where C is 0 for 1900 and 1 for 2000
DDD is the day of the year count
I used the mktime built-in php function to convert dates to the normal DD/MM/YYYY format. This function will convert dates that are between 1970 and 2038 (limitation of unix timestamps and the mktime function)
The $jde_date var needs to be a 6 len STRING.... if you use a numeric var type it will drop the leading 0 for any date that represents 1900.... this will botch the substr functions and thus make the whole thing wrong.
function jde_date_conv($jde_date)
{
$ct = substr($jde_date,0,1);
$yr = substr($jde_date,1,2);
$dy = substr($jde_date,3,3);
if($ct == 0) $yr_pfx = 19;
if($ct == 1) $yr_pfx = 20;
$tlt_yr = $yr_pfx.$yr;
$base_time = mktime(0,0,0,1,0,$tlt_yr);
$unix_time = ($dy * 86400) + $base_time;
return date("m/d/Y" , $unix_time);
}
carlj at vibez dot ca
17-Jun-2003 06:28
Why not do something like this, to find the number of days in a month?
$monthNum = date("n"); // or any value from 1-12
$year = date("Y"); // or any value >= 1
$numDays = date("t",mktime(0,0,0,$monthNum,1,$year))
This will tell you if there is 28-31 days in a month
dy64 at dy64 dot de
12-Nov-2002 12:18
Best performance:
/*
* Find the number of days in a month
* Year is between 1 and 32767 inclusive
* Month is between 1 and 12 inclusive
*/
function DayInMonth($month, $year) {
var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ($month != 2) return $daysInMonth[$month - 1];
return (checkdate($month, 29, $year)) ? 29 : 28;
}
gaoweibin at 163 dot net
26-Aug-2002 08:26
kmcm at bigfoot dot com
21-Jan-2002 12:42
if, like me, you don't have a PHP build that includes the cal functions, you may want to use this function for sorting out leap year.
function days_in_feb($year){
//$year must be YYYY
//[gregorian] leap year math :
if ($year < 0) $year++;
$year += 4800;
if ( ($year % 4) == 0) {
if (($year % 100) == 0) {
if (($year % 400) == 0) {
return(29);
} else {
return(28);
}
} else {
return(29);
}
} else {
return(28);
}
}
of course the next leap year isn't until the end of the century but this makes for timeless code I guess ...or if you are using 2000 in your dates or are going far back in time, etc, it is necessary.
mikebabcock at pobox dot com
17-Jul-2000 03:20
There are two world calculations for the date of Easter. The Easter date function should account for this; one used (generally) by the Western world and one (generally) used by the Eastern (the official date used by the East Orthodox Church).
ssharma at odc dot net
31-Jan-2000 09:36
| |