Last active
June 6, 2018 01:58
-
-
Save levelsio/798df34b42e7fcc12f2ae4d6fc70141c to your computer and use it in GitHub Desktop.
"Is it now Ramadan?" function in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# by @levelsio | |
# | |
# MIT licensed | |
# | |
# make sure you enable php_intl on PHP | |
# you can do by uncommenting ;extension=intl or ;extension=php_intl | |
# and installing php-intl, e.g. sudo apt-get install php-intl | |
# | |
# made for Nomad List to give people a notice if they go to a place | |
# where it is currently Ramadan | |
# | |
# enjoy | |
# | |
function isItNowRamadan() { | |
$formatter = IntlDateFormatter::create( | |
'en_US', | |
IntlDateFormatter::SHORT, | |
IntlDateFormatter::NONE, | |
'US/Eastern', | |
IntlDateFormatter::GREGORIAN | |
); | |
$cal = IntlCalendar::createInstance('US/Eastern', '@calendar=islamic-civil'); | |
$cal->set(IntlCalendar::FIELD_MONTH, 8); | |
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); | |
$cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); | |
$cal->clear(IntlCalendar::FIELD_MINUTE); | |
$cal->clear(IntlCalendar::FIELD_SECOND); | |
$cal->clear(IntlCalendar::FIELD_MILLISECOND); | |
$start=strtotime($formatter->format($cal)); | |
$cal = IntlCalendar::createInstance('US/Eastern', '@calendar=islamic-civil'); | |
$cal->set(IntlCalendar::FIELD_MONTH, 9); | |
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); | |
$cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); | |
$cal->clear(IntlCalendar::FIELD_MINUTE); | |
$cal->clear(IntlCalendar::FIELD_SECOND); | |
$cal->clear(IntlCalendar::FIELD_MILLISECOND); | |
$end=strtotime($formatter->format($cal)); | |
if(time()>$start && time()<$end) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment