Date and DateTime Modification

105 views
Skip to first unread message

Mazdak B.

unread,
Apr 4, 2015, 7:21:25 PM4/4/15
to silverst...@googlegroups.com
I want to use a Jalali calendar and it's not supported by Zend libraries.

I've well implemented a solution to change whole date and time functionality at certain files to store and show Jalali dates correctly but I've done it by overwriting Date.php, DateTime.php, SS_DateTime class, DateField and DateTimeField classes in place. Its a bad aproach as I should modify framework files.

here's one solution: Create a module that adds a task for making backup of native files and insert modified ones (Install and Uninstall)

Is there any way to load dynamically those classes instead of modifying original files?

If I want to implement it (Make it dependant by selected locale) and make a pull request what are correct points that I should tap in to switch date and time functionality?

Patrick Nelson

unread,
Apr 6, 2015, 11:10:59 PM4/6/15
to silverst...@googlegroups.com
Nope, not a great idea since it makes it more difficult for you to manage security updates, for example, or just upgrades for new features.

Since you ended up making modifications to the core date and date/time classes, would it instead make sense for you to simply override them (e.g. "JDate" extending "Date" and "JDateTime" extending "SS_DateTime") and then everywhere in your CMS code that you need these calendars, just use those classes instead? There shouldn't be much stopping you from doing that. Is there any reason why you can just use standard OOP style extensibility instead? 

Also, do you have a repo (e.g. github) with an example of some of the updates, by chance?


--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/d/optout.

Ingo Schommer

unread,
Apr 7, 2015, 6:17:35 AM4/7/15
to silverst...@googlegroups.com
Hello Mazdak! 

First of all, thanks for the opportunity to learn a bit about the Jalali calendar (https://en.wikipedia.org/wiki/Jalali_calendar) :)

The underlying Zend library (Zend_Date) supports localisation for the fa and fa_IR locales (see framework/thirdparty/Zend/Locale/Data/fa.xml. You should be able to configure that via DateField->setLocale().
Please excuse my ignorance if I got the locale mixed up with your localisation requirements.
I don't think there's a need to subclass Date and SS_Datetime directly - which methods did you alter?

In terms of an actual calendar UI field, the default jQuery UI widget doesn't seem to support this locale.
There's a few alternatives out there, e.g. http://farhadi.ir/projects/jalalijscalendar/.
It'll require a replacement of framework/javascript/Datepicker.js to allow its use,
basically translating the config values in HTML5 attributes back to the JS initialisation for this specific plugin.
This could be nicely packaged up into a SilverStripe module for drop-in replacements.

Good luck, happy hacking!
Ingo

 
--
Ingo Schommer | Solutions Architect
SilverStripe (http://silverstripe.com)
Mobile: 0221601782
Skype: chillu23

Mazdak B.

unread,
Apr 12, 2015, 10:34:45 AM4/12/15
to silverst...@googlegroups.com
Thank you for response

Using Jalali date in website is not a problem. I'm looking for a way to bring Jalali Calendar/Date support to whole CMS and Framework.

I will post a link to a forked version of Silvestripe

--
You received this message because you are subscribed to a topic in the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/silverstripe-dev/yfiTyckQhIg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to silverstripe-d...@googlegroups.com.

Mazdak B.

unread,
Apr 12, 2015, 10:37:51 AM4/12/15
to silverst...@googlegroups.com
Thank you for response

Using Jalali date in website is not a problem. I'm looking for a way to bring Jalali Calendar/Date support to whole CMS and Framework.

I will post a link to a forked version of Silvestripe
On Tue, Apr 7, 2015 at 7:40 AM, Patrick Nelson <p...@catchyour.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/silverstripe-dev/yfiTyckQhIg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to silverstripe-d...@googlegroups.com.

Mazdak B.

unread,
Apr 12, 2015, 11:07:19 AM4/12/15
to silverst...@googlegroups.com
Hi

Thank you for you feedback.

Unfortunately Zend_Date desn't support Jalali (Persian) Calendar. It just provide localization (Translation for months name). As you mentioned, I always switch locale but it doesn't help as Zend doesn't support a different calendar.

I've managed to change whole calendar by using https://github.com/sallar/jDateTime (PHP Jalali Date Library). Now every "date object" in CMS or Framework is JDate. I Also altered Javascript calendar UI to support Jalali date. Everything seems to work fine (Filtering and other date and time related functionalities)

I've Altered these files:
framework/model/fieldtypes/Date.php
framework/model/fieldtypes/Datetime.php
framework/forms/DateField.php
framework/forms/DatetimeField.php
framework/thirdparty/jquery-ui/datepicker/i18n/jquery.ui.datepicker-fa.js

In Field classes I altered:
setValue, Format, Format, FormatI18N, FormatFromSettings, Rfc822, Rfc2822, Rfc3339, Age, TimeDiff, TimeDiffIn and almost every instance of date() or zend_date.
The PHP function I used has same interface as PHP's builtin date().

Switching jQuery UI datepicker and calendar should work fine, but what is a good solution here? I would like to contribute to Silverstripe and make it compatible with my locale calendar.
By altering those classes date values stored in database are Jalali date!
What is a good solution (design) to this multi calendar problem?

Is it good to store time and date values in a universal format (i.e Unix time) and convert in on retrieval based on locale?
Where else do you think I should alter to have complete JDate support?

Thanks

Mazdak

--
You received this message because you are subscribed to a topic in the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/silverstripe-dev/yfiTyckQhIg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to silverstripe-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages