Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Is it now Ramadan?" function in PHP
# 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