You are reading a single comment by @ancienthero and its replies. Click here to read the full conversation.
  • the js Date object is marvelous
    https://www.w3schools.com/jsref/jsref_ob­j_date.asp

    but it's espruino implementation is very limited so far, to be specific, we can only read from the Date object once it has been created.

    >t = new Date;
    =Date { "ms": 949363947471.30676269531 }
    >t.setHours(10);
    Uncaught Error: Function "setHours" not found!
     at line 1 col 3
    

    Im working on a time switch, I've been using date class all around, finding out that set-methods are not implemented made me (almost :P ) depressed

    setDate()	Sets the day of the month of a date object
    setFullYear()	Sets the year of a date object
    setHours()	Sets the hour of a date object
    setMilliseconds()	Sets the milliseconds of a date object
    setMinutes()	Set the minutes of a date object
    setMonth()	Sets the month of a date object
    setSeconds()	Sets the seconds of a date object
    

    Extending espruino's Date class would be extremely beneficial:
    1) easy, date, time manipulation - clocks, timers, time switches
    2) clock module wouldn't be necessary
    3) if it's about memory, we can add set-methods and remove some of these:

    • function Date.getTimezoneOffset - doesn't make sense on espruino since it's always 0;
    • Date.getTime() is almost identical with Date.now() and Date.now() makes more sense on embedded
    • Date.toUTCString is kind of useless when our timezoneOffset is always 0

    Let me know what do you think of it!

About

Avatar for ancienthero @ancienthero started