3

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
rossng
  • 318
  • 3
  • 11
  • You are using the emulator right? Maybe those libraries are not loaded into the emulator properly. Have you tried running it on a watch itself? When you do not include the `var Moment = require('moment');` line, its working 100% fine? Usually I have found CloudPebble to warn me when something I add is not used or not supported. – Kenneth Salomon Jul 30 '15 at 14:53

1 Answers1

1

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.

Kenneth Salomon
  • 1,352
  • 11
  • 18
  • 2
    I had seen moment.js in the PebbleJS sources, but hadn't realised that it's already available globally for your app.js and other sources. You can literally reference it with `moment()` in any file and it works (though JSHint marks it as invalid in the editor) – rossng Jul 30 '15 at 22:47
  • I am glad I could be of help. When I looked at the PebbleJS sources I noticed it got loaded in the loader.js so I figured something had to be wrong with what we were trying to accomplish. Seeing the app.js from CloudPebble showed me it's not referenced like the other libraries we can require, so it had to be inherited as part of the Pebble.JS library – Kenneth Salomon Jul 30 '15 at 22:55
  • Please expand your explanation of referencing the clock library to inherit moment.js. I'm trying to understand the syntax of using momentjs within clock, and CloudPebble isn't being very specific. – Zoot Aug 09 '15 at 13:37
  • I downloaded a PBW file and opened it up and looked at the app.js file after it had been compiled. By looking at the contents I noticed that the clock library uses Moment.JS to handle some of the functionality listed in the GetPebble documentation for PebbleJS. – Kenneth Salomon Aug 09 '15 at 13:53
  • I agree that Moment.js is there, I'm just having a devil of a time actually trying to use it in my code. I'll try the rossng method. I may have been worried about the editor showing it as invalid. – Zoot Aug 09 '15 at 14:13
  • 1
    OK, I'm an idiot. @rossng already showed me how to use it and I was complicating things by trying to instantiate it or import it. I can confirm that simply using moment() will work, even if CloudPebble syntax highlighting thinks it's wrong. – Zoot Aug 09 '15 at 14:42