Skip to content

Instantly share code, notes, and snippets.

@levelsio
Last active June 6, 2018 01:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levelsio/798df34b42e7fcc12f2ae4d6fc70141c to your computer and use it in GitHub Desktop.
Save levelsio/798df34b42e7fcc12f2ae4d6fc70141c to your computer and use it in GitHub Desktop.
"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