PhpZmanim
PhpZmanim copied to clipboard
cant get parsha for some reason ... maybe me :)
this is just sample code - everything works accept the "parsha" i tried using the getparsha and i get null and many diffrent things.... can you please tell me what am i doing wrong ?
<?php
require 'vendor/autoload.php';
use PhpZmanim\Zmanim;
use PhpZmanim\Calendar\ComplexZmanimCalendar;
use PhpZmanim\Geo\GeoLocation;
use Carbon\Carbon;
use PhpZmanim\HebrewCalendar\HebrewDateFormatter;
use PhpZmanim\HebrewCalendar\JewishCalendar;
use PhpZmanim\HebrewCalendar\JewishDate;
use PhpZmanim\HebrewCalendar\TefilaRules;
$locname = "random";
$lat = 32.09575001437873;
$long = 34.95249632904598;
$elev = 0;
$tz = 'Asia/Jerusalem';
$getyear = date("Y");
$getday = date("d");
$getmonth = date("m");
$zmanim = Zmanim::create($getyear, $getmonth, $getday, $locname, $lat, $long, $elev, $tz);
$jewishCalendar = Zmanim::jewishCalendar(Carbon::createFromDate($getyear, $getmonth, $getday));
$hebrewDate = JewishDate::create(Carbon::createFromDate($getyear, $getmonth, $getday));
$format = Zmanim::format();
$format->setHebrewFormat(true);
$daf = $jewishCalendar->getDafYomiBavli();
$daf = $format->formatDafYomiBavli($daf);
$hebdate = $format->format($hebrewDate);
$parsha = $format->formatParsha($jewishCalendar); // --------> this dosnt work <---------
$alos72 = $zmanim->alos72;
$alos72 = $alos72->format('H:i');
$sunrise = $zmanim->sunrise;
$sunrise = $sunrise->format('H:i');
$sofZmanShmaMGA = $zmanim->sofZmanShmaMGA;
$sofZmanShmaMGA = $sofZmanShmaMGA->format('H:i');
$sofZmanShmaGra = $zmanim->sofZmanShmaGra;
$sofZmanShmaGra = $sofZmanShmaGra->format('H:i');
$sofZmanTfilaMGA = $zmanim->sofZmanTfilaMGA;
$sofZmanTfilaMGA = $sofZmanTfilaMGA->format('H:i');
$sofZmanTfilaGra = $zmanim->sofZmanTfilaGra;
$sofZmanTfilaGra = $sofZmanTfilaGra->format('H:i');
$chatzosAsHalfDay = $zmanim->chatzosAsHalfDay;
$chatzosAsHalfDay = $chatzosAsHalfDay->format('H:i');
$minchaGedola = $zmanim->minchaGedola;
$minchaGedola = $minchaGedola->format('H:i');
$minchaKetana = $zmanim->minchaKetana;
$minchaKetana = $minchaKetana->format('H:i');
$plagHamincha = $zmanim->plagHamincha;
$plagHamincha = $plagHamincha->format('H:i');
$sunset = $zmanim->sunset;
$sunset = $sunset->format('H:i');
$tzais = $zmanim->tzais;
$tzais = $tzais->format('H:i');
?>
<ul id="timeslist">
<li><span><?php echo "$getyear, $getday, $getmonth"; ?></span></li>
<li><span><?php echo "$hebdate"; ?></span></li>
<li><span><?php echo "$daf"; ?></span></li>
<li><span><?php echo "$parsha"; ?></span></li> // -------------------------------> this return empty <------------
<li><span>עלות השחר</span>time><?php echo "$alos72"; ?></time></li>
<li><span>זריחה</span><time><?php echo "$sunrise";?></time></li>
<li><span>קריאת שמע מג"א</span><time><?php echo "$sofZmanShmaMGA"; ?></time></li>
<li><span>קריאת שמע גר"א</span><time><?php echo "$sofZmanShmaGra"; ?></time></li>
<li><span>תפילה מג"א</span><time><?php echo "$sofZmanTfilaMGA"; ?></time></li>
<li><span>תפילה גר"א</span><time><?php echo "$sofZmanTfilaGra"; ?></time></li>
<li><span>חצות היום</span><time><?php echo "$chatzosAsHalfDay"; ?></time></li>
<li><span>מנחה גדולה</span><time><?php echo "$minchaGedola"; ?></time></li>
<li><span>מנחה קטנה</span><time><?php echo "$minchaKetana"; ?></time></li>
<li><span>פלג המנחה</span><time><?php echo "$plagHamincha"; ?></time></li>
<li><span>שקיעה</span><time><?php echo "$sunset";?></time></li>
<li><span>צאת כוכבים</span><time><?php echo "$tzais"; ?></time></li>
</ul>
thank you for your time ! :)
I apologize for the poor documentation. You need to try the parsha on shabbos. During the week there is no parsha returned. If you're looking to show the upcoming shabbos, then you can add a JewishCalendar object for the coming shabbos and then it will give you that week's parsha
so did somthing like this and it works ... for anybody else that maybe encounter the same problem :
$daysToShabbos = 7 - ($jewishCalendar->getDayOfWeek() % 7); $jewishCalendar = Zmanim::jewishCalendar(Carbon::createFromDate($getyear, $getmonth, $getday + $daysToShabbos)); $parsha = $format->formatParsha($jewishCalendar);
@zachweix , KosherJava added a method that you probably did not yet port. See https://github.com/KosherJava/zmanim/blob/master/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishCalendar.java#L515
so i foxed the the code... this function dosnt work as far as i can see,,,, clone is a keyword, not a method. When you use $this->clone(), it should instead be $clone = clone $this;.
public function getUpcomingParshah() {
$clone = $this->clone();
$daysToShabbos = 7 - ($this->getDayOfWeek() % 7);
$clone->addDays($daysToShabbos);
while($clone->getParshah() == Parsha::NONE) {
$clone->addDays(7);
}
return $clone->getParshah();
}
i changed it to this because the cloning methoed does not execute correctly
public function getUpcomingParshah() {
$clone = clone $this; // correct way...
$daysToShabbos = 7 - ($this->getDayOfWeek() % 7);
$clone->addDays($daysToShabbos);
while($clone->getParshah() == Parsha::NONE) {
$clone->addDays(7);
}
return $clone->getParshah();
}
but then i have to go to the parshamap directly :
$parshanew = $jewishCalendar->getUpcomingParshah(); // for the number
$parshanew = HebrewDateFormatter::HEBREW_PARSHA_MAP[$parshanew]; // name in array
You're correct that clone is not a function, it should be copy
@giggty Your code seems to work for me.
It would be great to have a function available to get the upcoming parsha.
There is in KosherJava, I just need to add it to this port. They added it after my last update