HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How to convert Vanilla date to Jalali (Shamsi)

Hi
does it possible to convert the Vanilla date to Jalali (Shamsi) date ?

Answers

  • Options
    businessdadbusinessdad Stealth contributor MVP

    I just learnt about Jalali calendar, now I know something new. As for how to display dates in such format, I'm afraid it can be a complicate task.

    To achieve such result, some issues have to be solved:

    • Conversion: Gregorian dates must converted into their Jalali counterpart. This could be done by using one of the many libraries available on the Internet. Conversion should be bidirectional, i.e. Gregorian->Jalali for the output and Jalali->Gregorian for the input.
    • Formatting: Vanilla makes extensive use of Gdn_Format::Date(), which uses the locale file to determine how to format the date. As far as I could see, the format constants used by the class, which correspond to the ones used by PHP function strftime(), don't support the formatting of these dates.

    In short, the objective would be converting every output date to Jalali before printing, and converting every Jalali input to Gregorian before passing it to Vanilla engine. Perhaps it may be easier than I think, but I'm afraid that some core functions would have to be modified.

  • Options

    perhaps javascript could be used

    look at this script
    https://github.com/farhadi/JalaliJSCalendar/blob/master/jalali.js#L72

    you could parse the date on the page, which would require little detection, manipulation, conversion and replace.

    Historical Jalali is complicated becuase it has no leap years.

    grep is your friend.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @x00 That could also be a clean option. The OP would just have to make sure that the Users have JavaScript enabled.

  • Options

    well it is a compromise solution obviously not full proof.

    I doubt that the users are unfamiliar with Gregorian.

    grep is your friend.

  • Options

    good idea to use livequery given that comment are added dynamically.

    grep is your friend.

Sign In or Register to comment.