persian date
|
|
Thread rating:  |
dongzky - 02 Jul 2008 10:16 GMT Hi all, Since coldfusion doesn't support Farsi/Persian dates, I tried to use the icu4j lib and installed it as instructed. I tried to run the attached code(sample from a cf article) and as expected, it gave me an output in Farsi/Persian, literally. I mean, the characters and numbers were in Persian. The thing that I don't get is the Now(), as used in this code, which is supposed to give a Persian date (year 1387), it still gives me the gregorian date(year 2008). Although the characters are in persian, the date is still in gregorian. i want it to output in persian as in year 1387 which is the current year right now in Persian calendar. Same also with the month and day. Am I missing something here? Any insights are really much appreciated. Thanks.
<cfprocessingDirective pageencoding="utf-8">
<cfsilent>
<cfscript> //full date format, common to both core java and icu4j fullFormat=javacast("int",0); // 0 to 2 farsiUlocale=createObject("java","com.ibm.icu.util.ULocale"); farsiUlocale.init("fa_IR"); icu4jDateFormat=createObject("java","com.ibm.icu.text.DateFormat"); icu4jDF=icu4jDateFormat.getDateInstance(fullFormat,farsiUlocale); </cfscript> </cfsilent>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="rtl"> <head> <title>locale comparison</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> </head>
<body> <cfoutput> <b>ICU4J:</b> #icu4jDF.format(now())# <br />
</cfoutput>
</body> </html>
Daverms - 02 Jul 2008 11:04 GMT Hi,
Have you installed that ICU4J.jar under <cf_root>\wwwroot\WEB-INF\lib directory?
PaulH - 02 Jul 2008 12:05 GMT fairly certain i answered this before.
there's no persian calendar in icu4j (or core java). you have use dr. ghasem's lib. see:
http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=719B5036-20 ED-7DEE-2AB3B8F1EF7CF163
use the testbed here: http://www.sustainablegis.com/projects/icu4j/calendarsTB.cfm
dongzky - 03 Jul 2008 03:21 GMT @Paul: thanks. i'll be looking into this. So, to clear things, icu4j only supports farsi for displaying and not automatic date calculations according to the farsi locale, right?
PaulH **AdobeCommunityExpert** - 03 Jul 2008 05:54 GMT > @Paul: thanks. i'll be looking into this. So, to clear things, icu4j only > supports farsi for displaying and not automatic date calculations according > to the farsi locale, right? you need a calendar to do date math, etc. icu4j doesn't have the jalali calendar built in (if i recall correctly some kind of academic politics or the regular old kind of politics prevented any kind of official persian calendar from being included in icu4j but it does have a lot of others like coptic, arabic, chinese, etc).
dongzky - 03 Jul 2008 04:21 GMT hi Paul,
I tried your testbed http://www.sustainablegis.com/projects/icu4j/calendarsTB.cfm and it gave me the output i was expecting. Persian year now is 1387. However, when I tried to download all the files for this testbed and ran it from my local PC, the year now in Persian is giving me 1386 instead of 1387? Anything more I have to configure?
PaulH **AdobeCommunityExpert** - 03 Jul 2008 05:58 GMT > http://www.sustainablegis.com/projects/icu4j/calendarsTB.cfm and it gave me the > output i was expecting. Persian year now is 1387. However, when I tried to > download all the files for this testbed and ran it from my local PC, the year > now in Persian is giving me 1386 instead of 1387? Anything more I have to what date did you pass in? there's no one-to-one year correspondence between the gregorian & persian calendars:
AP 1386 covers 2007-2008 AD AP 1387 covers 2008-2009 AD
dongzky - 03 Jul 2008 06:32 GMT Hi Paul,
I was actually just using your files. The date passed is now(). When i tried to compare the one in your site and the one i ran here in my PC, it's quite different. Although, the one in my PC outputs the correct date, the calculation at the lower table is different. The screenshots are shown in the links below.
http://www.geocities.com/franalje/temp/fromSite.jpg
http://www.geocities.com/franalje/temp/fromMyPC.jpg
dongzky - 03 Jul 2008 08:07 GMT Hi Paul,
everything works fine now. My bad. I was using the old files (which makes me wonder if the old files were correct?). But I tried the latest files which i downloaded from the links you gave and everything is ok. Thank you so much.
dongzky - 04 Jul 2008 03:07 GMT Hi Paul,
Your i18ncalendars is really a great help. There is another thing also I want to clarify about the i18ncalendars and the persiancalendar class. Correct me if I am wrong, but the date base(I mean the basis for date conversion) is the gregorian date right? Which means, whatever date I input, the cf app(or maybe this is done from the classes) will consider date inputs as gregorian and then convert it to the desired calendar format? What if I am entering a date input that is already a persian date, say I enter 1387-04-14(yyyy-mm-dd), is there any way that we can tell the classes(or maybe the i18ncalendars) that the input date is already a persian date(which means tell the app that the basis for date conversion is Persian) ? The thing is, when I enter 1387-04-14(a persian date), the app accepts it as a gregorian date and do some conversions. But I want to let the app know that the input date is already a Persian date. Any insights, ideas or suggestions on this. Thanks.
-Fran
PaulH **AdobeCommunityExpert** - 04 Jul 2008 05:53 GMT > I am wrong, but the date base(I mean the basis for date conversion) is the > gregorian date right? Which means, whatever date I input, the cf app(or maybe no, it's based on cf(java) datetime, which happens to be gregorian calendar based (actually it's decimals days since 31-dec-1899 like exel & db2).
> let the app know that the input date is already a Persian date. Any insights, > ideas or suggestions on this. Thanks. store your dates as cf datetimes or better yet as java epoch offsets (you will eventually run into timezone issues if you have to support clients in multiple TZ).
i don't have any time right now to rework the persian calendar CFC so add the method below to the CFC, it converts jalali calendar datetimes to gregorian calendar datetimes. just be aware that cf sees all datetimes as being in the server's TZ.
<cffunction name="jalaliToGregorian" access="public" output="false" returntype="date" hint="converts Jalali calendar date to gregorian calendar date"> <cfargument name="jalaliYear" type="Numeric" required="true" hint="jalali year"> <cfargument name="jalaliMonth" type="Numeric" required="true" hint="jalali month"> <cfargument name="jalaliDay" type="Numeric" required="true" hint="jalali day"> <cfargument name="hours" type="Numeric" required="false" default=0> <cfargument name="minutes" type="Numeric" required="false" default=0> <cfargument name="seconds" type="Numeric" required="false" default=0> <cfset var gregorianDate=""> <cfset var pc=createObject("java","com.ghasemkiani.util.SimplePersianCalendar")> <cfset pc.setDateFields(javaCast("int",arguments.jalaliYear),javaCast("int",arguments.jalaliMonth),javaCast("int",arguments.jalaliDay))> <cfset gregorianDate=pc.getTime()> <cfset gregorianDate=createDateTime(year(gregorianDate),month(gregorianDate),day(gregorianDate),arguments.hours,arguments.minutes,arguments.seconds)> <cfreturn gregorianDate> <!--- returns datetime in server TZ ---> </cffunction>
dongzky - 04 Jul 2008 06:32 GMT Hi Paul,
Thank you so much for the help. I got it working now. So far, so good. Anyway, I won't be having problems with TZ 'coz I will be specifically doing this app in a Persian locale server. I am going to look more info also from Dr. Ghasem's lib to familiarize the class as well. Thanks.
PaulH **AdobeCommunityExpert** - 04 Jul 2008 08:21 GMT > I won't be having problems with TZ 'coz I will be specifically doing this app > in a Persian locale server. I am going to look more info also from Dr. Ghasem's locale has nothing to do w/TZ. it usually depends on where the client & server are physically located. i live in bangkok, use ITC ("Indochina Time" UTC+7) tz but my w/s is in en_US locale.
dongzky - 08 Jul 2008 10:07 GMT Hi Paul,
The cffunction "jalaliToGregorian" you gave me returns a date which is added by a month. I mean if today is 2008-07-08(yyyy-mm-dd), it returned 2008-08-08. Then I came across some documentations on java that the month starts from zero. So I made a little change on your function. I am not sure if I am right(correct me if I'm wrong here) but what I did is subtract 1 from the passed month parameter as shown:
from this: pc.setDateFields(javaCast("int",arguments.jalaliYear),javaCast("int",arguments.j alaliMonth),javaCast("int",arguments.jalaliDay))>
to this: pc.setDateFields(javaCast("int",arguments.jalaliYear),javaCast("int",arguments.j alaliMonth-1),javaCast("int",arguments.jalaliDay))>
And then it gave me the expected result.
PaulH **AdobeCommunityExpert** - 08 Jul 2008 12:34 GMT > The cffunction "jalaliToGregorian" you gave me returns a date which is added > by a month. I mean if today is 2008-07-08(yyyy-mm-dd), it returned 2008-08-08. yeah probably right. i hesitated over that but i assumed the good doctor's method handled that (it's a jalali calendar date after all). good catch.
dongzky - 09 Jul 2008 02:54 GMT It could be that the class/method is by default meant for java apps, that's why it never bothered to subtract 1. Coz, if it did, then when a java app passes 0(first month), it would become -1 and would throw an error. In cf, that wouldn't be the case though since month number starts from 1.
I really appreciate the help. I'll be looking more also into this class and do some tests. And if I need help again, I'll be keeping this thread up again. :) Thanks.
dongzky - 09 Jul 2008 08:23 GMT Hi Paul and to anyone else,
I have been using the classes and your cfc to display and calculate persian dates within coldfusion. The next thing I did is retrieve persian dates from an Oracle db and display in the client side(cf page) without using the components and the classes.
These are the things I did in cfqueries before querying the dates.
1) alter session set nls_calendar='persian' <- in oracle, this is how to tell oracle that the current session for calendar is in Persian so that it will give me a persian date(which is automatically calculated by oracle)
2) alter session set nls_date_format='yyyy-mm-dd' <-setting date format in oracle for current session
After that, in the same file I tried to query the db using select statement. But when I output the date object from Oracle to a cf page, the date object display becomes gregorian. I'm pretty sure oracle gave me a persian date 'coz i tried doing it inside oracle itself. But when cf page tries to display it, it becomes gregorian. My question is, do I need to use again the i18ncalendars component together with the classes or is there any other easier way that I have to set in order to display the Persian date in cf? My guess would be use again the components. But maybe there is another way.
dongzky - 10 Jul 2008 06:09 GMT Hi Paul,
How do I use your cfc to return a persian date object? I mean in your testbed, when you show your column for the i18nDateAdd, it still return a gregorian date object right? How do you convert this to a persian date object and not a string?
PaulH **AdobeCommunityExpert** - 10 Jul 2008 07:14 GMT > How do I use your cfc to return a persian date object? I mean in your testbed, why? as i explained before you're better off storing gregorian datetime objects (or better yet epoch offsets which is the underlying value for all icu4j calendars & all my calendar CFCs).
dongzky - 10 Jul 2008 07:37 GMT @Paul: Oh, I see. Thanks.
dongzky - 15 Jul 2008 10:03 GMT Hi Paul,
I have a question on the i18nDateTimeFormat regarding the time. I am testing on my PC using windows xp. I set the locale of my PC to Farsi/Persian through the regional settings. After that, I changed the time zone in my pc to use GMT +3:30 (Tehran), which is I believe the tz, if not used, is similar in Iran. Now looking again at i18nDateTimeFormat method, the argument accepts a date in UTC format, right? So if I have a now() function to pass, I have to use DateConvert("local2utc",now()) as my input date(Please correct me If I'm no longer on the right track here of using your cfc). Base on the cfc, the return is:
return tDateFormatter.format(dateConvert("utc2local",arguments.thisDate));
In the return above, the UTC time is converted to local time(in my PC) and gives the format based on its locale, which is Farsi.Persian in my case. The output string is shown below: ?:??:?? (GMT+??:??)? ???? ??????? ?? ??? ????
(GMT+??:??) -> this part means (GMT+00:00), the standard UTC tz. I thought the time return is going to use my locale tz (GMT+3:30). Any way of displaying the actual local time in my PC(GMT+3:30)? Hope I'm making sense. Thanks.
PaulH **AdobeCommunityExpert** - 16 Jul 2008 00:59 GMT > I have a question on the i18nDateTimeFormat regarding the time. I am testing > on my PC using windows xp. I set the locale of my PC to Farsi/Persian through locale has nothing to do w/tz.
> looking again at i18nDateTimeFormat method, the argument accepts a date in UTC > format, right? So if I have a now() function to pass, I have to use yes. it's an attempt to workaround the fact that all datetimes are server tz datetimes to cf.
> (GMT+??:??) -> this part means (GMT+00:00), the standard UTC tz. I thought > the time return is going to use my locale tz (GMT+3:30). Any way of displaying > the actual local time in my PC(GMT+3:30)? Hope I'm making sense. Thanks. i'm not seeing that here: en_US: Wednesday, Tir 26, 1387 6:54:04 AM Thailand Time fa_IR: چهارشنبه ۲۶ تیر ۱۳۸۷، ساعت ۶:۵۶:۱۵ (وقت هندوچین)
i don't read farsi but the en_US datetime string is correct for our dev server's tz. if the farsi string's not correct let me know (could be a bug in dr. ghasem's lib).
sure you got the server tz correct?
or do you mean the client & server are different tz? and you want the datetime string in the client's tz?
dongzky - 16 Jul 2008 02:22 GMT [q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i] i don't read farsi but the en_US datetime string is correct for our dev server's tz. if the farsi string's not correct let me know (could be a bug in dr. ghasem's lib).
sure you got the server tz correct?
or do you mean the client & server are different tz? and you want the datetime string in the client's tz? [/q]
Hi Paul,
Thanks for the quick reply. To clarify things more, I am actually using my PC as my test server. Actually, I tested your testbed online and it returned your server TZ(I assume it was correct 'cause it was returning GMT-05:00, could be your server's tz). But when I tried to download your testbed files and test here in my PC locally(which is also my test server), I also found out that the server TZ returned is always GMT+00:00. I'm not sure why but could it be some settings I have not done with my PC? Like I said, I'm using WinXP and tried to change the locale in Regional Settings control panel and then changed the time zone. Is there something more I should do? Thanks again for your guidance on this area.
PaulH **AdobeCommunityExpert** - 16 Jul 2008 05:51 GMT > here in my PC locally(which is also my test server), I also found out that the > server TZ returned is always GMT+00:00. I'm not sure why but could it be some what does this snippet show?
<cfscript> tz=createObject("java","java.util.TimeZone"); writeoutput(tz.getDefault().getDisplayName()); </cfscript>
dongzky - 16 Jul 2008 06:05 GMT [q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i] dongzky wrote:
> here in my PC locally(which is also my test server), I also found out that the > server TZ returned is always GMT+00:00. I'm not sure why but could it be some what does this snippet show?
<cfscript> tz=createObject("java","java.util.TimeZone"); writeoutput(tz.getDefault().getDisplayName()); </cfscript> [/q]
Hi Paul,
it outputs "Iran Standard Time"
PaulH **AdobeCommunityExpert** - 16 Jul 2008 06:24 GMT > it outputs "Iran Standard Time" ok.
was the farsi date string correct (or did it get mojibake-d)?
dongzky - 16 Jul 2008 06:51 GMT [q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i] dongzky wrote:
> it outputs "Iran Standard Time" ok.
was the farsi date string correct (or did it get mojibake-d)?
[/q] Yes, the farsi date string is correct. It's only the time that is giving me a a GMT +00:00.
PaulH **AdobeCommunityExpert** - 16 Jul 2008 09:56 GMT > Yes, the farsi date string is correct. It's only the time that is giving me a > a GMT +00:00. sorry i meant was the farsi datetime string i posted correct? as i said i can't reproduce what you're seeing here (the en_US locale produces the correct tz in the datetimestring returned from that method).
dongzky - 16 Jul 2008 10:46 GMT [q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i] dongzky wrote:
> Yes, the farsi date string is correct. It's only the time that is giving me a > a GMT +00:00. sorry i meant was the farsi datetime string i posted correct? as i said i can't reproduce what you're seeing here (the en_US locale produces the correct tz in the datetimestring returned from that method). [/q]
Hi Paul, the testbed you posted online is displaying the date correctly in Persian. However, the time is different from the actual Persian time. Online shows GMT -05:00 while in actual, right now it should be GMT +03:30 plus 1 hr DST, so it's about GMT+04;30 in all. Anyway, I have solved my problem in my case which I have posted before this post.
By the way, another thing I made a little change in your cfc is the i18nDayOfWeek. Today, Persian day(if i'm not mistaken), I think is already in it's 5th day of the week, but the method returned 4. So I was assuming that this could be another issue on the offset difference between java and cf. Java, correct me if I'm wrong, starts day of week from 0 while cf starts from 1. So I just added the return value of i18nDayOfWeek method by 1: <cfreturn tCalendar.get(tCalendar.DAY_OF_WEEK)+1>
Any comments on this? Maybe I'm in the wrong way. Thanks.
PaulH **AdobeCommunityExpert** - 16 Jul 2008 11:37 GMT > Hi Paul, the testbed you posted online is displaying the date correctly in > Persian. However, the time is different from the actual Persian time. Online > shows GMT -05:00 while in actual, right now it should be GMT +03:30 plus 1 hr ok let me say this again, "all datetimes are server datetimes in cf". see this for more details:
http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=77223B6A-20 ED-7DEE-2AB7FBB1F37ABD77
also let me repeat that "locales have nothing to do with timezones".
if you have to work with different timezones you need to understand these points.
> DST, so it's about GMT+04;30 in all. Anyway, I have solved my problem in my > case which I have posted before this post. that somehow didn't make it through to the news forums (unless you edited an existing post, that never shows up in the news forums via my news reader). if i get the chance i'll have a look via a browser.
> correct me if I'm wrong, starts day of week from 0 while cf starts from 1. So I sorry no, core java days of week start at 1 not zero (yes it's confusing because of the months starting at zero). the day of week difference could be as a result of tz differences.
> just added the return value of i18nDayOfWeek method by 1: > <cfreturn tCalendar.get(tCalendar.DAY_OF_WEEK)+1> no, that will return the wrong value.
dongzky - 18 Jul 2008 06:26 GMT Hi Paul,
Thanks for all the help. I think I'm getting it now.
dongzky - 16 Jul 2008 07:37 GMT Hi Paul,
More info on what I did: My server/PC is localozed to persian and also the timezone.
I created the ff. customized functions:
<!--- substitutes the Now() function in CF ---> <cffunction access="public" name="global_Now" output="No" returntype="date"> <cfscript> var utcNow=DateConvert("local2utc",Now()); </cfscript> <cfreturn utcNow> </cffunction>
<!--- this will make a call to your i18nDateTImeFormat ---> <cffunction access="public" name="global_DateTimeFormat" output="no" returntype="string"> <cfargument name="thisDate" required="yes" type="date"> <cfargument name="thisDateFormat" default="LONG" required="No" type="string"> <cfargument name="thisTimeFormat" default="LONG" required="No" type="string"> <cfscript> var lstStandardDateTimeFormats = "FULL,LONG,MEDIUM,SHORT"; var nDateFormat=1; var nTimeFormat=1; if(ListFindNoCase(lstStandardDateTimeFormats,arguments.thisDateFormat,",")) { nDateFormat=ListFindNoCase(lstStandardDateTimeFormats,arguments.thisDateForma t,",")-1; } else { nDateFormat=1; } if(ListFindNoCase(lstStandardDateTimeFormats,arguments.thisTimeFormat,",")) { nTimeFormat=ListFindNoCase(lstStandardDateTimeFormats,arguments.thisTimeForma t,","); } else { nTimeFormat=1; } sDateTime=thisCalendar.i18nDateTimeFormat(thisDate=arguments.thisDate,thisLoca le=theLocale,thisDateFormat=nDateFormat,thisTimeFormat=nTimeFormat); </cfscript>
<cfreturn sDateTime> </cffunction>
-------------------------------------------------------------------------------- ------ This is the code that tries to display the persian datetime:
#global_DateTimeFormat(global_Now(),"FULL","FULL")#
Anything wrong you can see with what I'm doing?
dongzky - 16 Jul 2008 08:41 GMT Hi Paul,
I have fixed the problem. It is in my code. The problem was I tried to declare my thisCalendar object this way:
<cfparam name="theCalendar" default="#cfcLocation#gregorianCalendar">
<cfset theLocale = "fa_IR"> <cfset theCalendar = "#cfcLocation#persianCalendar">
<cfset init()>
<cffunction access="public" name="init" output="No"> <cfset variables.thisCalendar=CreateObject("component",theCalendar)> </cffunction> ---------------------------------------- I also tried another way: No init() function and just simply this:
<cfset variables.thisCalendar=CreateObject("component",theCalendar)>
Base on those two ways of declaring above, the variables.thisCalendar doesn't seem to produce the correct output. I still don't understand why. So what I did is I remove the init() function or the direct cfset for the 2nd test, and just declare the object thisCalendar in each function I created. And it worked! But still confused why. I don't want to be declaring the object everytime I create a new function. But I guess I'll just have to stick with this workaround for now. Thanks again.
|
|
|