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 <[email protected]>wrote:
>
> 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>");
>
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:340252
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm