Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
JDateTime - Iranian (Shamsi) Date for PHP (github.com/sallar)
29 points by sallar on Feb 23, 2013 | hide | past | favorite | 12 comments


You know you can do this:

    $idf = new IntlDateFormatter('fa_IR@calendar=persian',
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,"Asia/Tehran",
        IntlDateFormatter::TRADITIONAL);
right?

PHP has a wrapper for ICU.


Sure, but it's PHP 5 >= 5.3.0. jDateTime requires 5.2. IntlDateFormatter did not exist at the time of writing this code.


Thank god they finally introduced all this classes and inheritance kerfuffle in PHP, so we can now manually handle Iranian dates by calling "toJalali" on a pseudo-singleton "jDateTime" class.

In all seriousness, I wanted to punch myself in the face when I had to instantiate a "GregorianCalendar" in Java, but the general idea has a lot of merit, even if the implementation is terrible.


not to be confused with JDate.com..


That was my reaction as well. Maybe it is because I am from New York, but when I see JDateTime I did not think of Iranian time conversions.


Are you from Great Neck[0]? That would be doubly confusing....!

[0] http://en.wikipedia.org/wiki/Great_Neck,_New_York


I dont get it?


It's a joke - Great Neck has an extremely large population of Iranian Jews.


I've never seen JDate.com, I'm sorry for the confusion.


don't know much about how Iranian dates work so I peeked inside the code to see the actual conversion.

Line 482 - $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

Umm, what about leap years, you know the ones that have 29 days in February?


Looks as if lines 489 onwards are for detecting leap years.


upvote, you rock Sallar :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: