zachweix / php-zmanim
将KosherJava移植到PHP
Requires
- nesbot/carbon: ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^8
README
A PHP移植自Eliyahu Hershfeld的KosherJava Zmanim API(代码在KosherJava Zmanim项目)。请参阅Kosher Java文档以了解每个类变量和方法的注释。以下是如何安装和使用以及您可以访问的详细方法和可以调用的方法的列表。一旦实例化,您就可以立即请求许多Zmanim。
$zmanim = Zmanim::create(2019, 2, 22, 'Lakewood', 40.0721087, -74.2400243, 39.57, 'America/New_York'); $zmanim->tzais72->format('Y-m-d\TH:i:sP'); // 2019-02-22T18:52:38-05:00 $jewishCalendar = Zmanim::jewishCalendar(Carbon::createFromDate(2023, 9, 30)); // This will give you a Jewish calendar date for the given date $jewishCalendar = Zmanim::jewishCalendar(5784, 7, 15); // This will give the same date, but with the Jewish date given as parameters $jewishCalendar->isRoshHashana(); // false $jewishCalendar->isSuccos(); // true $daf = $jewishCalendar->getDafYomiBavli(); $format = Zmanim::format(); $format->formatDafYomiBavli($daf); // Kiddushin 48 $jewishCalendar = Zmanim::jewishCalendar(5784, 7, 26); $format->formatParsha($jewishCalendar); // Bereshis
安装(使用Composer)
$ composer require zachweix/php-zmanim
{
"require": {
"zachweix/php-zmanim": "^2.0"
}
}
设置
<?php require 'vendor/autoload.php'; use PhpZmanim\Zmanim;
实例化
您可以使用Zmanim::create()函数创建一个新的Zmanim对象。(如果您愿意,可以通过创建一个GeoLocation对象和一个ComplexZmanimCalendar对象来实例化,就像在KosherJava中一样)。目前有两种计算Zmanim时间的方法,SunTimesCalculator和NoaaCalculator;默认计算器是NoaaCalculator。
通过Zmanim::create()
预期参数是:$year、$month、$day、$locationName、$latitude、$longitude、$elevation、$timeZone
所有参数都是可选的。默认值是格林尼治标准时间今天,海拔0。如下所示,这些是设置默认位置或自定义位置的示例。位置名称在任何地方都没有使用,仅供您内部参考(如果您想的话,可以是null)。
如果您将年、月或日设置为null,将使用今天的UTC日期,这可能不同于您当前的日期(例如,2月21日在纽约的晚上9点在UTC上是2月22日凌晨2点)。
$zmanimInGMT = Zmanim::create(2019, 2, 21, "Greenwich"); $zmanim = Zmanim::create(2019, 2, 21, "New York City", 40.850519, -73.929214, 200, "America/New_York");
通过GeoLocation和ComplexZmanimCalendar
GeoLocation的预期参数是:$locationName、$latitude、$longitude、$elevation、$timeZone
ComplexZmanimCalendar的预期参数是:$geoLocation、$year、$month、$day
如果您将年、月或日设置为null,将使用今天的UTC日期,这可能不同于您当前的日期(例如,2月21日在纽约的晚上9点在UTC上是2月22日凌晨2点)。
use PhpZmanim\Calendar\ComplexZmanimCalendar; use PhpZmanim\Geo\GeoLocation; $geoLocation = new GeoLocation("New York City", 40.850519, -73.929214, 200, "America/New_York"); $complexZmanimCalendar = new ComplexZmanimCalendar($geoLocation, 2019, 2, 21);
用法
任何调用方式如$zmanim->sunrise或您看到的任何名为$zmanim->get("Sunrise")的方法都可以通过将get连接到Zman并确保首字母大写来调用,因此您将获得$zmanim->getSunrise();以下三个将返回相同的结果,都是Carbon对象。
$sunrise = $zmanim->sunrise; $sunrise = $zmanim->get("Sunrise"); $sunrise = $zmanim->getSunrise();
如果您在计算时要考虑海拔,请确保在实例化对象时设置海拔。如果您设置了一个非0的海拔并想忽略海拔,您可以调用$zmanim->setUseElevation(false),然后当您想再次使用它时,只需调用$zmanim->setUseElevation(true)。
可用方法
$zmanim->setCalculatorType($type); // 'SunTimes' and 'Noaa' are currently the only calculators $zmanim->setDate($year, $month, $day); // Change current date $zmanim->addDays($value); // Change current date, by adding requested number of days $zmanim->subDays($value); // Change current date, by subtracting requested number of days
Zmanim列表
以下是您可以请求的许多可能的Zmanim列表,所有这些都会返回在创建$zmanim对象时设置的时区的Carbon对象。如果您找不到您想要的,请参阅以下如何获取更多自定义Zmanim的说明。
日出
$zmanim->sunrise; // Get sunrise based on current elevation $zmanim->seaLevelSunrise; // Get sunrise at zero elevation $zmanim->beginCivilTwilight; // The point when sun's zenith is at 96 degrees $zmanim->beginNauticalTwilight; // The point when sun's zenith is at 102 degrees $zmanim->beginAstronomicalTwilight; // The point when sun's zenith is at 108 degrees
日落
$zmanim->sunset; // Sunset based on current elevation $zmanim->seaLevelSunset; // Sunset at zero elevation $zmanim->endCivilTwilight; // The point when sun's zenith is at 96 degrees $zmanim->endNauticalTwilight; // The point when sun's zenith is at 102 degrees $zmanim->endAstronomicalTwilight; // The point when sun's zenith is at 108 degrees
Shaah Zmanim的长度(以分钟计)
$zmanim->shaahZmanis19Point8Degrees; $zmanim->shaahZmanis18Degrees; $zmanim->shaahZmanis26Degrees; $zmanim->shaahZmanis16Point1Degrees; $zmanim->shaahZmanis60Minutes; $zmanim->shaahZmanis72Minutes; $zmanim->shaahZmanis72MinutesZmanis; $zmanim->shaahZmanis90Minutes; $zmanim->shaahZmanis90MinutesZmanis; $zmanim->shaahZmanis96MinutesZmanis; $zmanim->shaahZmanisAteretTorah; // See note 1 below $zmanim->shaahZmanisAlos16Point1ToTzais3Point8; $zmanim->shaahZmanisAlos16Point1ToTzais3Point7; $zmanim->shaahZmanis96Minutes; $zmanim->shaahZmanis120Minutes; $zmanim->shaahZmanis120MinutesZmanis; $zmanim->shaahZmanisBaalHatanya; // See note 3 below $zmanim->shaahZmanisGra; $zmanim->shaahZmanisMGA;
Alos Hashachar
$zmanim->alosHashachar; // Sunrise offset by 16.1 degrees $zmanim->alos72; $zmanim->alos60; $zmanim->alos72Zmanis; $zmanim->alos96; $zmanim->alos90Zmanis; $zmanim->alos96Zmanis; $zmanim->alos90; $zmanim->alos120; $zmanim->alos120Zmanis; $zmanim->alos26Degrees; $zmanim->alos18Degrees; $zmanim->alos19Degrees; $zmanim->alos19Point8Degrees; $zmanim->alos16Point1Degrees; // Same as default $zmanim->alosBaalHatanya; // See note 3 below
Misheyakir
$zmanim->misheyakir11Point5Degrees; $zmanim->misheyakir11Degrees; $zmanim->misheyakir10Point2Degrees; $zmanim->misheyakir7Point65Degrees; $zmanim->misheyakir9Point5Degrees;
Sof Zman Shma
$zmanim->sofZmanShmaMGA; $zmanim->sofZmanShmaGra; $zmanim->sofZmanShmaMGA19Point8Degrees; $zmanim->sofZmanShmaMGA16Point1Degrees; $zmanim->sofZmanShmaMGA18Degrees; $zmanim->sofZmanShmaMGA72Minutes; $zmanim->sofZmanShmaMGA72MinutesZmanis; $zmanim->sofZmanShmaMGA90Minutes; $zmanim->sofZmanShmaMGA90MinutesZmanis; $zmanim->sofZmanShmaMGA96Minutes; $zmanim->sofZmanShmaMGA96MinutesZmanis; $zmanim->sofZmanShma3HoursBeforeChatzos; $zmanim->sofZmanShmaMGA120Minutes; $zmanim->sofZmanShmaAlos16Point1ToSunset; $zmanim->sofZmanShmaAlos16Point1ToTzaisGeonim7Point083Degrees; $zmanim->sofZmanShmaKolEliyahu; $zmanim->sofZmanShmaAteretTorah; // See note 1 below $zmanim->sofZmanShmaFixedLocal; // See note 2 below $zmanim->sofZmanShmaBaalHatanya; // See note 3 below $zmanim->sofZmanShmaMGA18DegreesToFixedLocalChatzos; $zmanim->sofZmanShmaMGA16Point1DegreesToFixedLocalChatzos; $zmanim->sofZmanShmaMGA90MinutesToFixedLocalChatzos; $zmanim->sofZmanShmaMGA72MinutesToFixedLocalChatzos; $zmanim->sofZmanShmaGRASunriseToFixedLocalChatzos;
Sof Zman Tfila
$zmanim->sofZmanTfilaMGA; $zmanim->sofZmanTfilaGra; $zmanim->sofZmanTfilaMGA19Point8Degrees; $zmanim->sofZmanTfilaMGA16Point1Degrees; $zmanim->sofZmanTfilaMGA18Degrees; $zmanim->sofZmanTfilaMGA72Minutes; $zmanim->sofZmanTfilaMGA72MinutesZmanis; $zmanim->sofZmanTfilaMGA90Minutes; $zmanim->sofZmanTfilaMGA90MinutesZmanis; $zmanim->sofZmanTfilaMGA96Minutes; $zmanim->sofZmanTfilaMGA96MinutesZmanis; $zmanim->sofZmanTfilaMGA120Minutes; $zmanim->sofZmanTfila2HoursBeforeChatzos; $zmanim->sofZmanTfilahAteretTorah; // See note 1 below $zmanim->sofZmanTfilaFixedLocal; // See note 2 below $zmanim->sofZmanTfilaBaalHatanya; // See note 3 below $zmanim->sofZmanTfilaGRASunriseToFixedLocalChatzos;
Erev Pesach
$zmanim->sofZmanAchilasChametzGRA; $zmanim->sofZmanAchilasChametzMGA72Minutes; $zmanim->sofZmanAchilasChametzMGA16Point1Degrees; $zmanim->sofZmanAchilasChametzBaalHatanya; // See note 3 below $zmanim->sofZmanBiurChametzGRA; $zmanim->sofZmanBiurChametzMGA72Minutes; $zmanim->sofZmanBiurChametzMGA16Point1Degrees; $zmanim->sofZmanBiurChametzBaalHatanya; // See note 3 below
Chatzos
$zmanim->chatzos; // This defaults to astronomical chatzos $zmanim->chatzosAsHalfDay; // This defaults to halfway between sunrise and sunset and falls back to chatzos if that is not possible (e.g. the North Pole during summer) $zmanim->fixedLocalChatzos; // See note 2 below
Mincha Gedola
$zmanim->minchaGedola; $zmanim->minchaGedola30Minutes; $zmanim->minchaGedola72Minutes; $zmanim->minchaGedola16Point1Degrees; $zmanim->minchaGedolaAhavatShalom; $zmanim->minchaGedolaGreaterThan30; // Fixed 30 minutes or degrees, whichever is later $zmanim->minchaGedolaAteretTorah; // See note 1 below $zmanim->minchaGedolaBaalHatanya; // See note 3 below $zmanim->minchaGedolaBaalHatanyaGreaterThan30; $zmanim->minchaGedolaGRAFixedLocalChatzos30Minutes;
Mincha Ketana
$zmanim->minchaKetana; $zmanim->minchaKetana16Point1Degrees; $zmanim->minchaKetanaAhavatShalom; $zmanim->minchaKetana72Minutes; $zmanim->minchaKetanaAteretTorah; // See note 1 below $zmanim->minchaKetanaBaalHatanya; // See note 3 below $zmanim->minchaKetanaGRAFixedLocalChatzosToSunset; $zmanim->samuchLeMinchaKetanaGRA; $zmanim->samuchLeMinchaKetana16Point1Degrees; $zmanim->samuchLeMinchaKetana72Minutes;
Plag Hamincha
$zmanim->plagHamincha; $zmanim->plagHamincha120MinutesZmanis; $zmanim->plagHamincha120Minutes; $zmanim->plagHamincha60Minutes; $zmanim->plagHamincha72Minutes; $zmanim->plagHamincha90Minutes; $zmanim->plagHamincha96Minutes; $zmanim->plagHamincha96MinutesZmanis; $zmanim->plagHamincha90MinutesZmanis; $zmanim->plagHamincha72MinutesZmanis; $zmanim->plagHamincha16Point1Degrees; $zmanim->plagHamincha19Point8Degrees; $zmanim->plagHamincha26Degrees; $zmanim->plagHamincha18Degrees; $zmanim->plagAlosToSunset; $zmanim->plagAlos16Point1ToTzaisGeonim7Point083Degrees; $zmanim->plagAhavatShalom; $zmanim->plagHaminchaAteretTorah; // See note 1 below $zmanim->plagHaminchaBaalHatanya; // See note 3 below $zmanim->plagHaminchaGRAFixedLocalChatzosToSunset;
Candle Lighting
$zmanim->candleLighting; // Get sea level sunset minus candle lighting offset. Default is 18 minutes $zmanim->setCandleLightingOffset($candleLightingOffset);
Bain Hasmashos的开始(根据Rabbeinu Tam)
$zmanim->bainHashmashosRT13Point24Degrees; $zmanim->bainHashmashosRT58Point5Minutes; $zmanim->bainHashmashosRT13Point5MinutesBefore7Point083Degrees; $zmanim->bainHashmashosRT2Stars; $zmanim->bainHashmashosYereim18Minutes; $zmanim->bainHashmashosYereim3Point05Degrees; $zmanim->bainHashmashosYereim16Point875Minutes; $zmanim->bainHashmashosYereim2Point8Degrees; $zmanim->bainHashmashosYereim13Point5Minutes; $zmanim->bainHashmashosYereim2Point1Degrees;
Tzais
$zmanim->tzais; // Sunset offset by 8.5 degrees $zmanim->tzais72;getTzais() $zmanim->tzaisGeonim3Point7Degrees; $zmanim->tzaisGeonim3Point8Degrees; $zmanim->tzaisGeonim5Point95Degrees; $zmanim->tzaisGeonim3Point65Degrees; $zmanim->tzaisGeonim3Point676Degrees; $zmanim->tzaisGeonim4Point61Degrees; $zmanim->tzaisGeonim4Point37Degrees; $zmanim->tzaisGeonim5Point88Degrees; $zmanim->tzaisGeonim4Point8Degrees; $zmanim->tzaisGeonim6Point45Degrees; $zmanim->tzaisGeonim7Point083Degrees; $zmanim->tzaisGeonim7Point67Degrees; $zmanim->tzaisGeonim8Point5Degrees; $zmanim->tzaisGeonim9Point3Degrees; $zmanim->tzaisGeonim9Point75Degrees; $zmanim->tzais60; $zmanim->tzaisAteretTorah; // See note 1 below $zmanim->tzais72Zmanis; $zmanim->tzais90Zmanis; $zmanim->tzais96Zmanis; $zmanim->tzais90; $zmanim->tzais120; $zmanim->tzais120Zmanis; $zmanim->tzais16Point1Degrees; $zmanim->tzais26Degrees; $zmanim->tzais18Degrees; $zmanim->tzais19Point8Degrees; $zmanim->tzais96; $zmanim->tzaisBaalHatanya; // See note 3 below $zmanim->tzais50;
Chatzos Halayla(午夜)
$zmanim->solarMidnight;
Molad Zmanim
$zmanim->sofZmanKidushLevanaBetweenMoldos; $zmanim->sofZmanKidushLevana15Days; $zmanim->tchilasZmanKidushLevana3Days; $zmanim->zmanMolad; $zmanim->tchilasZmanKidushLevana7Days;
注释
- AteretTorah Zman是基于从Alos72Zmanis到日落后40分钟的时间计算的。但是,可以通过调用
$zmanim->setAteretTorahSunsetOffset($ateretTorahSunsetOffset)来更改确切的偏移时间。 - FixedLocalChatzos 基于全年固定时间的 Chatzos,更多详情请参阅 KosherJava 的文档。
- 巴阿·哈坦亚基于90度几何天顶以下1.583度的天顶来计算 Zmanim。
替代 Zmanim
如果您正在寻找列表中未列出的任何偏离日出或日落的 Zman,您可以使用以下方法之一并带上您的偏移量。
$zmanim->getSunriseOffsetByDegrees($offsetZenith); $zmanim->getSunriseSolarDipFromOffset($minutes); $zmanim->getSunsetOffsetByDegrees($offsetZenith); $zmanim->getSunsetSolarDipFromOffset($minutes);
您可以使用这些时间作为以下函数的自定义计算的参数
$zmanim->getSofZmanShma($startOfDay, $endOfDay); $zmanim->getSofZmanTfila($startOfDay, $endOfDay); $zmanim->getMinchaGedola($startOfDay, $endOfDay); $zmanim->getMinchaKetana($startOfDay, $endOfDay); $zmanim->getPlagHamincha($startOfDay, $endOfDay);
犹太历计算
关于使用语法,您可以查看 KosherJava 文档。(待办:在此处添加方法)。
地理定位数学计算
有一些函数可以在 GeoLocation 对象上进行计算。
use PhpZmanim\Geo\GeoLocation; use PhpZmanim\Geo\GeoLocationUtils; $new_york = new GeoLocation("New York City", 40.850519, -73.929214, 200, "America/New_York"); $jerusalem = new GeoLocation('Jerusalem, Israel', 31.7781161, 35.233804, 740, 'Asia/Jerusalem'); GeoLocationUtils::getGeodesicInitialBearing($new_york, $jerusalem); GeoLocationUtils::getGeodesicFinalBearing($new_york, $jerusalem); GeoLocationUtils::getGeodesicDistance($new_york, $jerusalem); GeoLocationUtils::getRhumbLineBearing($new_york, $jerusalem); GeoLocationUtils::getRhumbLineDistance($new_york, $jerusalem);