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:

> <cfscript>
> function ISOWeek(inputDateObj) {
> c = CreateObject("java","java.util.Calendar").getInstance();
> c.setTimeInMillis(arguments.inputDateObj.getTime());
> c.setFirstDayOfWeek(c.MONDAY);
> c.setMinimalDaysInFirstWeek(4);
> return c.get(c.WEEK_OF_YEAR);
> }
> </cfscript>

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.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:340210
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to