New-Bee Espruino Clock Module question

Posted on
  • Espruino Clock Module
    
     var Clock = require("clock").Clock;
      var clk=new Clock(2014,4,15,23,45,0,0);   // Initialise with specific date
      var clk=new Clock("Jun 23, 2014 12:18:02");   // ... or Initialise with specific date from a string
    
      // every time the button is pressed, print the current time..
      setWatch(function() {
        var d1=clk.getDate(); 
        print(d1.toString()); // prints "Thu May 15 2014 23:45:05" 
      }, BTN, { edge : "rising", repeat : true, debounce : 10 } );
    
      // You can also update the current time
      clk.setClock(Date.parse("Jun 23, 2014 12:18:02"));
    

    From above ...
    var clk=new Clock(2014,4,15,23,45,0,0); // Initialise with specific date
    print(d1.toString()); // prints "Thu May 15 2014 23:45:05"

    It does what it says BUT the number "4" for the month is April and 5 should be for May.
    Looks like someone started to use, for the months, 0-11 and not the normal 1-12?
    Are you going to keep the months index this way?

    Windows 8.1 64 Bit
    Chrome 35.0.1916.153 m (no beta)
    Espruino 1v69
    Web-IDE v 45
    Board: Espruino v 1.3

  • Hi,

    Yes, that's intentional. Normal Javascript has a date class that we implement, and it works just like that.

    It's strange I know - but it would be worse if we behaved totally different to normal javascript.

  • Is this module available for Puck.js ? I tried this code and it says module "clock" not found.

  • Did you upload using the right-hand side of the IDE? The clock module needs to be loaded off the net, so it has to be uploaded first via the right-hand side so the IDE can detect its use and upload it.

    However, you may find that the Date class does everything that you need all by itself? espruino.com/Reference#Date

    You can turn on Set Current Time in the Web IDE so that it will automatically set the correct time whenever you upload code.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

New-Bee Espruino Clock Module question

Posted by Avatar for user7114 @user7114

Actions