• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

persian date

Participant ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

3.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Hi,

Have you installed that ICU4J.jar under <cf_root>\wwwroot\WEB-INF\lib directory?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

fairly certain i answered this before.

there's no persian calendar in icu4j (or core java). you have to use dr. ghasem's lib. see:

http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=719B5036-20ED-7DEE-2AB3B8F1EF7C...

use the testbed here:
http://www.sustainablegis.com/projects/icu4j/calendarsTB.cfm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

@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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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?

These are the things I did:
1. I copy the persianCalendar.cfc and the rest of the cfc's to my cfc path.
2. I copy the files(icu4j_3_2_calendar.jar, icu4j-4_0_d02-src.jar, icu4j-4_0_d02.jar, icu4j-charsets-4_0_d02.jar, icu4j-localespi-4_0_d02.jar and persiancalendar.jar) to \CF8root\WEB-INF\lib\addedClass where addedClass directory is my created dir which is already mapped or added in the java/jvm path in cf admin.
3. I copy the calendarsTB.cfm to my cf apps directory.
4. I restarted CF8 server.
5. I tested calendarsTB.cfm and got year 1386 in persian instead of 1387

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

dongzky wrote:
> @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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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.

From your given site

From my local PC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

Hi Paul,

everything works fine now. My bad. I was using the old files (which makes me wonder if the old files were correct? or maybe i have messed up those files). Anyway, I tried the latest files which i downloaded from the links you gave and everything is ok. Thank you so much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2008 Jul 04, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2008 Jul 08, 2008

Copy link to clipboard

Copied

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.jalaliMonth),javaCast("int",arguments.jalaliDay))>

to this:
pc.setDateFields(javaCast("int",arguments.jalaliYear),javaCast("int",arguments.jalaliMonth-1),javaCast("int",arguments.jalaliDay))>

And then it gave me the expected result.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2008 Jul 08, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2008 Jul 08, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: Newsgroup User
dongzky wrote:
> 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).



Oh, I see. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 15, 2008 Jul 15, 2008

Copy link to clipboard

Copied

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)? Anything I did wrong? Hope I'm making sense. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2008 Jul 15, 2008

Copy link to clipboard

Copied

dongzky wrote:
> 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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 15, 2008 Jul 15, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: Newsgroup User
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?



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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2008 Jul 15, 2008

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 15, 2008 Jul 15, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: Newsgroup User
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>



Hi Paul,

The core java code above outputs "Iran Standard Time". Does this mean the String format I get in i18nDateTimeFormat is incorrect?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation