Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Very PHP Simple method for counting of the Omer.
<?php
/**
* Very Simple method for Omer count.
*
* @return bool|int Omer count or false if out Omer range date.
*
* @author Yakir Sitbon (http://www.yakirs.net/)
*/
function yakir_get_omer_count() {
// Get now jd date.
$jd_now = unixtojd();
// Get now jewish date.
list( $month, $day, $year ) = explode( '/', jdtojewish( $jd_now ) );
// Get start Omer in current year.
$jd_start_omer = jewishtojd( 8, 15, $year);
// Get end Omer in current year.
$jd_end_omer = jewishtojd( 10, 6, $year);
// If we are in Omer range date.
if ( $jd_now >= $jd_start_omer && $jd_now <= $jd_end_omer ) {
return $jd_now - $jd_start_omer;
}
return false;
}
/**
* Very Simple method for Omer count text (Hebrew).
*
* @return bool|string Omer text or false if out Omer range date.
*
* @author Yakir Sitbon (http://www.yakirs.net/)
*/
function yakir_get_omer_count_text() {
if ( $omer_count = yakir_get_omer_count() ) {
$return = sprintf( 'היום %d יום', $omer_count );
if ( $omer_count >= 7) {
$weeks = floor( $omer_count / 7 );
$return .= sprintf( ' שהם %d שבועות', $weeks );
if ( $weeks < ( $omer_count / 7 ) ) {
$return .= sprintf( ' ו-%d ימים', $omer_count - ( $weeks * 7 ) );
}
}
$return .= ' לעומר';
return $return;
}
return false;
}
// Example..
if ( $omer_text = yakir_get_omer_count_text() ) {
echo $omer_text;
} else {
echo 'We are no in Omer range date.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment