Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale for date and time #1703

Closed
MaBecker opened this issue Nov 20, 2019 · 11 comments
Closed

Locale for date and time #1703

MaBecker opened this issue Nov 20, 2019 · 11 comments

Comments

@MaBecker
Copy link
Contributor

What about date and time in locale specific formats?

Not as part of firmware but as part of user javascript code.

  • Time: 24 hour format or 12hour with am and pm
var time = new Date();
console.log(
  time.toLocaleString('en-US', { hour: 'numeric', hour12: true })
); 
  • Date: order of day and month
  • Date: name of days and month

const char *MONTHNAMES = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec";
const char *DAYNAMES = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat";

Maybe assign lookup array for day and month names from customer code to a time format translation function in the firmware. (add prototype function to Date).

@gfwilliams
Copy link
Member

I'm not a massive fan of sticking it inside Espruino itself, because it's a lot of extra bulk when templated strings let you do format date reasonably easily.

It's kind of annoying that Date.toLocaleFormat isn't a standard, as I'd be totally behind putting something like that in.

Looking at the MDN docs there's a standard for Intl (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) that I reckon could be implemented as a JS library reasonably easily?

@MaBecker
Copy link
Contributor Author

Completely agreed, do not blow up the firmware with locale.

Will check for tiny js lib. There is a nice lib from @allObjects in the forum, will check this too.

@MaBecker
Copy link
Contributor Author

From the forum: Date().toDateString()

@MaBecker
Copy link
Contributor Author

Ok, locale is now available as Bangle.js app.

How could this be available for all other devices as well?

  • Implement a locale uploader into the WebIDE?
    or
  • use Espruino comandline tool to upload locale?
    or
  • ?

@gfwilliams
Copy link
Member

Maybe make this same code use UART.js to allow an upload to any Espruino device? https://github.com/espruino/EspruinoWebTools/blob/master/uart.js

We could add it to the Espruino site in a similar way to the Image Converter

@MaBecker
Copy link
Contributor Author

We could add it to the Espruino site in a similar way to the Image Converter

I like that idea, pick a language and get something like this:

require('Storage').write('local', ` .........`);

@gfwilliams
Copy link
Member

Yes - it could even write it automatically if needed.

@gfwilliams
Copy link
Member

Closing this - now implemented for Bangle.js

@MaBecker
Copy link
Contributor Author

Well, would be nice to have locale for all other devices too.

@MaBecker
Copy link
Contributor Author

Maybe as function in the WebIDE

@gfwilliams
Copy link
Member

Yes, that sounds like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants