House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Internationalization of Week() function in ColdFusion - Last resort to Java [spamtrap heur]

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
On 12/22/2010 8:41 PM, Nando wrote:
Paul Hastings
12/22/10 12:19 P
...
denstar
12/22/10 11:20 P
Paul,
Nando
12/23/10 11:12 A
On 12/23/2010 11:11 PM, Nando wrote:
Paul Hastings
12/23/10 09:35 P
Paul,
Nando
12/24/10 04:38 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Paul Hastings
12/22/2010 12:19 PM

On 12/22/2010 8:41 PM, Nando wrote: > numbers are often used in calenders and agendas. A question such as "Can we > arrange a meeting during week 43?" can be rather common. The question, for actually i think that's rather an uncommon datepart to use. in fact in all my years nobody's ever asked for that functionality. furthermore the ISO calendar is not universal, it won't work in the US/Canada & in most arabic countries for instance. week starts are *locale* based. but anyways, see below. > Long story short, I eventually solved this, as a last resort, by dropping > down to Java. I'm an absolute novice at Java and wanted to ask if anyone java is not an uncommon solution to i18n problems in cf. you can short circuit this > var inputDate = DateFormat(inputDateObj,"yyyy-mm-dd"); >      var formatter = > CreateObject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd"); > var theDate = formatter.parse(inputDate); to this: ----- Excess quoted text cut - see Original Post for more ----- bit of advice, rather than do it this way you might want to think about simply supplying timezone and locale arguments to the calendar getInstance() method. see this snippet: <cfscript> locales=createObject("java","java.util.Locale").getAvailableLocales(); calObj=createObject("java","java.util.Calendar"); for (i=1; i LTE arrayLen(locales); i=i+1) {   cal=calObj.getInstance(locales[i]);   writeoutput("#locales[i].getDisplayName()# (#locales[i].toString()#) 1st day of week:=#cal.getFirstDayOfWeek()#<br>"); }    </cfscript> supplying a user's locale will ensure you get their week numbers correct without having to resort to universalities that aren't. final bit of advice, if you want to get the best/latest locale data, use the icu4j lib instead of core java.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
denstar
12/22/2010 11:20 PM

... > supplying a user's locale will ensure you get their week numbers correct without > having to resort to universalities that aren't. +1! > final bit of advice, if you want to get the best/latest locale data, use the > icu4j lib instead of core java. Joda seems pretty swell too. :Den -- Those who wish to appear wise among fools, among the wise seem foolish. Marcus Fabius Quintilian

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Nando
12/23/2010 11:12 AM

Paul, Thanks! Your suggestions are very helpful. I'm trying to implement them. I ran your getAvailableLocales() code sample, adding cal.getMinimalDaysInFirstWeek(), and it confirms that all of Europe seems to be on the ISO calender system, with Monday as the first day of the week and a minimum of 4 days in the first week of the year. My experience here in Europe is that many businesses use the week system in communications to arrange meetings. For instance, I just received an email seeking to schedule a meeting asking "How does week 04 or 05 look like?" I've been trying to figure out how to set and use the locale, as you suggest. Here's what I've come up with so far: <cfscript> function LocaleWeek(inputDateObj) { var loc = createObject("java","java.util.Locale").init('it','CH'); var calObj = CreateObject("java","java.util.Calendar"); var c = calObj.getInstance(loc); c.setTimeInMillis(inputDateObj.getTime()); return c.get(c.WEEK_OF_YEAR); } </cfscript> What I would like would be to pull the language and country information from the currently set ColdFusion locale. Do you have a handy way to accomplish that? Or would a UDF like this need to pass the two letter country and language codes into the function? Thanks again, Nando On Wed, Dec 22, 2010 at 6:19 PM, Paul Hastings <paul@sustainablegis.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- writeoutput("#locales[i].getDisplayName()# (#locales[i].toString()#) 1st day of week:=#cal.getFirstDayOfWeek()#<br>"); ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Paul Hastings
12/23/2010 09:35 PM

On 12/23/2010 11:11 PM, Nando wrote: > adding cal.getMinimalDaysInFirstWeek(), and it confirms that all of Europe > seems to be on the ISO calender system, with Monday as the first day of the > week and a minimum of 4 days in the first week of the year. another piece of advice, don't hardwire if you don't have to. the minute you hardwire the function/app for european locales is the minute that the client tells you his cousin has opened a shop in montreal & you need to support en_CA, fr_CA locales too. > My experience here in Europe is that many businesses use the week system in > communications to arrange meetings. For instance, I just received an email > seeking to schedule a meeting asking "How does week 04 or 05 look like?" as i said "but anyways".... > What I would like would be to pull the language and country information from > the currently set ColdFusion locale. Do you have a handy way to accomplish > that? Or would a UDF like this need to pass the two letter country and > language codes into the function? if your app is already setting the locale somehow (user choice, geoLocation, etc.) that would be the best way. we have a geoLocation CFC but it's ip db is woefully out of date (that bit is maintained by a dirty perl programmer ;-) and passing in locale AND timezone would make that a function *i'd* use. for locales that cf *didn't* support prior to cf7 using getLocale() will get you a core java locale ID, "th_TH", etc. which is easy to parse (treat it as a list delimited by "_"). the problem is locales that cf *did* support prior to cf7, which will return the goofy cf locale names, "English (US)" (in fact the old cf locales are duplicated with their new core java locales, ie in the server scope supported locales you'll see both English (US) & en_US). since there aren't too many of these & are static, i guess create a structure using those old locale names as keys & do a structFind on it if the locale returned by getLocale() doesn't contain a "_" or something like that.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Nando
12/24/2010 04:38 AM

Paul, *Fully* agreed that the ideal is to let the Locale set MinimalDaysInFirstWeek and FirstDayOfWeek as you've indicated. I'm just looking for a clean way of doing that. The only hitch involved in providing a relatively simple LocaleWeek() UDF back to the CF community at this point seems to be that there is no straightforward way to pull the language and country data needed out of ColdFusion's Locale settings. The fact, which you've pointed out, that getLocale() returns inconsistent data, rather than always returning core java locale ID, makes it pretty much useless for programming purposes. As you point out, it can be worked around, but perhaps it is better to simply require that the language and country code are passed into the function. Hence it seems this is what we should be using now for lack of a native LSWeek() function in ColdFusion: <cfscript> function LocaleWeek(inputDateObj,languageCode,countryCode) { var loc = createObject("java","java.util.Locale").init(languageCode,countryCode); var calObj = CreateObject("java","java.util.Calendar"); var c = calObj.getInstance(loc); c.setTimeInMillis(inputDateObj.getTime()); return c.get(c.WEEK_OF_YEAR); } </cfscript> Would you agree? Thanks very much for your feedback. Nando ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

July 30, 2014

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference