Banglejs locale module time() function

Posted on
  • I was trying to extend BangleJS locale module to localize time and observed that time() function is not giving the expected result.

    >let l = require("locale");
    ={
      name: "en_GB",
      currencySym: "\xA3",
      translate: function (a) { ... },
      date: function (a,c) { ... },
      time: function (a,c) { ... },
      dow: function (a,c) { ... },
      month: function (a,c) { ... },
      number: function (a) { ... },
      currency: function (a) { ... },
      distance: function (a) { ... },
      speed: function (a) { ... },
      temp: function (a) { ... },
      meridian: function (a) { ... }
     }
    >l.time(new Date());
    ="am:52.46 am"
    > 
    

    from this https://github.com/espruino/Espruino/blo­b/master/libs/js/banglejs/locale.js#L9 it looks like this is a bug.

    and it should be

    time : (d,short) => { // Date to  "4:15.28 pm" or "15:42"(short)
        var h = d.getHours(), m = d.getMinutes()
        if (short)
          return (" "+h).substr(-2)+":"+("0"+m).substr(-2);
        else {
          var r = "am";
          if (h==0) { h=12; }
          else if (h>=12) {
            if (h>12) h-=12;
            r = "pm";
          }
          return (" "+h).substr(-2)+":"+("0"+m).substr(-2)+"­."+("0"+d.getSeconds()).substr(-2)+" "+r;
        }
      },
    
  • Thanks! Just fixed - looks like I made a stupid copy/paste bug when updating it previously :( https://github.com/espruino/Espruino/com­mit/c6d011c7aae62324cc20dfdf06b5cc4e2c32­0dae#diff-6806dd1c5d7ec9c0799a6b305b2677­3269ea2af4c710e1703753f25fe2706971

    If you install a locale from the 'Languages' app it'll override the default module and fix this though

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

Banglejs locale module time() function

Posted by Avatar for Abhigkar @Abhigkar

Actions