Search code examples
javascriptpebble-watchpebble-js

Date formatting and manipulation in PebbleJS


I'm writing an app using PebbleJS in CloudPebble and would like to have functionality similar to that provided by Moment.js and xdate.js. Specifically, I am interested in:

  • turning a datetime into a string using a custom format string
  • adding and subtracting days/weeks/months/years from the current datetime

These modules claim to support CommonJS, so I've tried adding the files to CloudPebble and importing with something like var Moment = require('moment');. When I do this, the app will simply fail to run. I'm not even sure that it compiles.

All I can find in the logs is:

[PHONE] pebble-app.js:?: [PHONESIM] [WARNING] Exception decoding QemuInboundPacket.footer

Solution

  • I see here that moment.js is included in the vendor folder of Pebble.JS. The reasoning for that error must be something universal as I am getting the same error when I try the same thing on a HelloWorld brand new Pebble.JS project on CloudPebble.

    I looked at the source code from a pbw export from cloudpebble and it has the full library inside the file. It seems that part of the clock.js file uses moment.js

    Look here on how to reference the clock library and inherit the moment.js library at the same time.