Date().toDateString() #1364
Replies: 34 comments
-
Posted at 2016-07-19 by @allObjects ...such things get me going... from a private (messages) conversation: Some food for thought... you will also see some typical dynamic Javascript constructs in this code. In some contexts one likes to separate the data from the presentation... two classes are used: The first one is - obviously - the Javascript built-in
Since this may look like a bit cumbersome, short and very short form have been introduced:
The code would look like something below.
Attachment: DateFormatter.js and DateFormatter.min.js as modules to be placed in project sandbox modules folder. To be continued in next post... Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @allObjects Test code:
Test output:
Attached html can be clicked and it runs right away same code in the browser. Placed in a module named To be continued in next post...Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @allObjects Formatting pattern characters: // yMNdHhmsSxXDZ are date and time pattern chars, escape-able with ^ (default).
Formatting pattern examples:
Usage Notes:
Common to below usage examples is this snippet:
Examples related to Usage Note 7. (with snippet a runnable sequence):
Examples related to Usage Note 8. (with snippet a runnable sequence):
Examples related to Usage Note 9. (with snippet a runnable sequence):
At a later time, I may put this up as a module. Until then, it still needs some hardening. Closing comments in next post... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @allObjects Some closing comments: Parameters are unfortunately positional... the first for Adding... some more examples based on the description of items 7. through 9. of Notes of previous post. Since I know that not all users are inclined to use objects (constructed from classes), I provided also the class (or static) method usage, and a plain function usage. For the class (or static) method usage, you assign the module to a variable: For the functional usage, you assign the module to a variable: Btw, if you always provide the format, you need only one instance of formatter. If you always use the same format or have a prevailing format, create a formatter with that format: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @MaBecker @allObjects: wow - great stuff - looks like you coded your own date.js and more ;-) my intention is to code a small and simple helper to get a human readable date/time a little change for a shorter the length checker:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @allObjects @MaBecker, the whole came out of a personal conversation that had less in mind to get a formatter going but more so to show the separation of concerns: model / data separate from presentation. Therefore, I would not not extend the Date 'class'... last but not least to prevent future conflicts, when one day Date will extend... The DateFormatter then just became the icing on the cake - a Kürlauf! ...and freebee... ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @MaBecker @allObjects - thanks for sharing ! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-19 by @allObjects The 'complete' (or almost perfect separation) would go one step further: extract the internationalization (i18n) out of the formatter itself and have it as a separate modules, one for each language... loaded automatically correctly by the locale information by the system or overridable (with a parm in require module and/or constructor. Since the argument in |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-20 by @MaBecker @gfwilliams are you thinking of an implementing of DateFormatter in Espruino as native code ? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-20 by @gfwilliams As far as I can tell, If there is a date formatting that's part of the JS standard then I'd be interested in implementing it - but memory is too scarce to add non-standard functionality, especially if it can be done easily with JS. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-20 by @MaBecker Ok so the solution is clear to me - do it in JS and use the code allObjects share. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-20 by @MaBecker @allObjects btw - now reading Cross-cutting_concern to understand what you pointed out:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-07-20 by @allObjects Subject domains are like silos and in silos separation of concerns is applied. For example, the date subject has subject specific data (and calculation/behavior) and subject specific formatting. Other subjects are: Numbers, bank accounts, address, etc. Subjects are also composition of other subjects. So far, we just talked about subject specific separation of concerns. Cross-cutting concerns are concerns that are across all subjects / across the silos / horizontal - not subject specific - and this is for example logging, security/access control/... etc. Most of the time, these cross-cutting things are services/servers and clients to domain specific clients. In other words, 'the world' is diced and sliced in two dimensions, and some of the pieces are logically and physically 'shared': The logging has a domain specific component and a cross domains shared generic component: invocation of the logging - what to log (and often also some of the configuration info of the logging)- is a domain specific and the actual writing/appending to the log is generic and common to all domains. There are programming paradigms to generalize and separate also the specific components to keep the domain code as concise as possible. A good example for that is aspect oriented (ao) programming. Javascript is especially nice to this idea, because it can be dynamically / at runtime changed... (in java, it is a bit more difficult, but still doable... therefore annotations are used to 'inject' the code at build / compile time). In JavaScript, ao can be applied even when only programming with functions. For an example, let's assume we have a
Now, we want to have (configurable, conditional) logging for before and after - in other words: log the parameters (input) and log the returned result (output). Easy, p(l)easy! you say... but it may not really be pleasant...
Ooooookaaaaay... you got your (1st round of) logging (the configurable/conditional we put off for later... and ...never), but you also change the code not just by adding but also in structure: you had to temp store the result for the logging the way the it was.
Go through these steps after uploading of above code snippet:
Now, we want to use the button BTN1. Pressing button BTN1 will alternately lite red and green (Pico and Original) onboard LED. But how do we know if odd result shows red LED on, and even green LED? We add logging and compare log output in console with lit LED. Conclusion: This brief exercise shows conceptually how logging can be added without changing the implementation. NOTE: Real world is much more sophisticated and does not have issues like this example (after upload enter in console |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-15 by @MaBecker Possible applications use for Bangle.js clocks with date. Like to continue this discussion , because there will be requests for something like
named in espruino/Espruino#1703 What about extend "DateFormatter" to pass names for your local days and month so it’s not blowing up the module. eg days and mons as long and/or short format days: "Sunday___Monday___Tuesday__Wednesday...", dayLen: 9 and equally for mons: "January__Feburary_...", monLen: 9) To make a clock app very flexible, same code for all locales. What do you think about this idea? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-15 by @allObjects As much as I (still) enjoy reading thru the solution, I feel it is "too fat" for casually formatting a date (and time) on BangleJS... BUT: If an application has the subject of date(s) and time(s), then it is most likely already the smallest 'module' for it's comprehensiveness, flexibility and efficiency (w/ @MaBecker 's shorter length checker/stretcher). Here is another - cheap - Date Formatter:
Usage:
Attached .html file can be directly executed to run formatter and example in browser. It can also be downloaded, modified, and played with. The formatter can be modularized and then composed with a base module and extended with - for example - the week day and month names and combined formatting functions - and last but not lest - with the time formatting functions. The base module with just the number formatter is very compact and looks then like this:
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-18 by @MaBecker Using glibc export for an example how locale could look So this peace of code is not a app but a locale saver
What do you think?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-19 by Robin Tue 2020.02.18
While I have only been taking sneak peaks at this Bangle.js development, I must say @MaBecker that the concept and presentation are succinct, tidy and easy to understand. Nicely Done. Kudos! As I understand this then, for uncommon Locales, would a developer then use the Local Helper Library (link in #20 post) to create their own
Following the usage of that now defined Locale, that it's form would then be enhanced by the use of @allObjects Date Formatter code in post #2 or post #16? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-24 by @gfwilliams This looks really promising. Definitely something that could be pulled into Bangle.js. I guess one question is we have similar issues with time (12/24 hr), distance, speed, and maybe even numbers ( My suggestion would be:
A second option is to still have the app and
That'd then be compatible with all devices including the emulator (which doesn't support apps yet) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-24 by @MaBecker glad you like it :) Yes it would be nice to have some more locale entries like this, or even more.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-24 by @allObjects @MaBecker, right now I could use de_CH ... hahaha... don't know if this is a official thing, but you know what it means... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-24 by @gfwilliams I guess one nice option with the app approach is there's actually no requirement to have a settings file if it wasn't needed. The app could just write the relevant functions into the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-24 by @MaBecker yes, just something nicer than this locale picker Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-25 by @gfwilliams Just fixed an issue for this at espruino/BangleApps#105 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-26 by @MaBecker @allObjects |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-02-28 by @gfwilliams Lots of updates here: espruino/BangleApps#105 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-02 by @MaBecker Just added 18 locales. Would be great if this is checked be native speakers. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-03 by Robin Mon 2020.03.02 While not actively involved/engaged with Bangle and this thread as I have only been observing from a distance, Thank You @MaBecker for the effort fleshing out the locales object.
Wasn't sure if suggestions were meant to be listed here, sent as a PM, or posted at GitHub, So, as the question is asked here . . . . Not sure if this was just a typo, as it mimics the GB example, for USA we typically use only 'km' for kilometer adopting your Deutsche 'de_DE' or International format:
Q: Is the default, element 0 or element 1 ? If the speed designator is considered the parent, then the distance element 0 would be correct if the answer to the question above is true. Is the display of the speed designator dependent on the default distance label? Reference
I also had an observation with some of the case labels. Wasn't sure of the specific reference used, so grabbed the first Google response:
Have always had a struggle with 'M' and 'm' as This might be considered a personal preference, but maybe there was a programming reason to use upper case?: (also note the 'M' and 'm' conflict here also)
This one is a little tougher, my preference is for a 'yy' format, but banks, C.C. companies and our Government insist on 'yyyy' So, there isn't an easy way to incorporate both, just yet.
> EDIT: Who is the controlling body for these locales? There are some items there that are not common here in the mid-west, specifically the date format as above: > https://lh.2xlibre.net/locale/en_US/glibc/ > http://docs.translatehouse.org/projects/localization-guide/en/latest/guide/locales/glibc.html Would be interesting to get feedback from other areas of the USA - a few known
If 'M' is required for the Month to avoid the 'minute' time conflict, then we'll have to accept:
Tougher yet, as I'm sure this is the desire to have an all three alpha character solution, but for the month of September, Sept is more frequently used:
Finally, either
The rest of the 'en_US' locale looks ok, Ok, okay, Okay !! ;-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-03 by @MaBecker Thanks @robin, this exactly what helps to make this a great locale app.
I like to followed en_US definition which is standard and keep it like that. The goal is to find an internal definition set to have a standard and short form for date including time, so something like this mapping would work. At the moment it is a mix of Javascript and Unix. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-05 by Robin Wed 2020.03.04 My concern post #22 about code bloat while adding additional locales was answered today in a separate thread: (individual locale parsed and uploaded to Bangle - entire locales object remains on server) See post #6 and #7 for explanation
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-05 by @MaBecker it’s available now, check this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-07-19 by @MaBecker
would something like this make sense to be a part of Espruinos Date() class ?
Beta Was this translation helpful? Give feedback.
All reactions