Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client's first day of the week

Is it possible to determine regional settings of the client's machine, using pure javascript? I need to get first day of the week. Is it Sunday or Monday.

like image 757
iLemming Avatar asked Sep 19 '11 16:09

iLemming


2 Answers

I could not find any out-of-the-box solutions for you, but if you want to persist this endeavor you may find the following ideas useful:

You can detect the locale of the browser using one of the following functions in JavaScript:

http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931

Then, you have to map the locale (language) to the preferred start day of the week. You could create JavaScript arrays in a separate source file using a local (server side) scripting language with I18N support:

How to determine the first day of week in python

(shows Java and Python example)


As an alternative, YUI, a JavaScript framework, provides a rich internationalization framework. Although it may be a bit heavy for your needs, and I couldn't find a function that would provide you the first day of the week, it may come in handy for your application:

http://yuilibrary.com/yui/docs/intl/

You can add the first day of the week attribute to the resource bundles yourself (or log a ticket with tem). For an example of the French resource bundle:

http://yui.yahooapis.com/combo?3.3.0/build/datatype/lang/datatype-date_fr-FR.js


There also is a jQuery plugin for i18n support:

http://plugins.jquery.com/project/jquery_i18n_properties

But it looks like that it doesn't come with usable resource bundles.

like image 82
2 revsuser742071 Avatar answered Sep 25 '22 17:09

2 revsuser742071


The library datejs can do things like that. Also check this discussion

like image 20
Dan Avatar answered Sep 25 '22 17:09

Dan