Created
August 8, 2015 23:37
-
-
Save zo0o0ot/a19e0d43a0143f0e8c11 to your computer and use it in GitHub Desktop.
TypeError: undefined is not a function - line 62 - not getting momentJS working in PebbleJS with Clock?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UI = require('ui'); | |
var ajax = require('ajax'); | |
var Vector2 = require('vector2'); | |
var Settings = require('settings'); | |
//Requiring clock to get moment.js | |
var Clock = require('clock'); | |
//var Moment = require('moment'); | |
// Show splash screen while waiting for data | |
var splashWindow = new UI.Window(); | |
// Set a configurable with just the close callback | |
Settings.config( | |
{ url: 'http://zo0o0ot.github.io/PebblePages/' }, | |
function(e) { | |
console.log('closed configurable'); | |
// Show the parsed response | |
console.log(JSON.stringify(e.options)); | |
Settings.option('propertyId', e.options.propertyId); | |
// Show the raw response if parsing failed | |
if (e.failed) { | |
console.log(e.response); | |
} | |
} | |
); | |
// Text element to inform user | |
var text = new UI.Text({ | |
position: new Vector2(0, 0), | |
size: new Vector2(144, 168), | |
text:'Downloading trash data...', | |
font:'GOTHIC_28_BOLD', | |
color:'black', | |
textOverflow:'wrap', | |
textAlign:'center', | |
backgroundColor:'white' | |
}); | |
// Add to splashWindow and show | |
splashWindow.add(text); | |
splashWindow.show(); | |
var propertyId = Settings.option('propertyId'); | |
if (propertyId === null || propertyId === undefined) | |
{ | |
propertyId = 315427100; | |
} | |
else | |
{ | |
console.log('Property Id is: ' + propertyId); | |
} | |
var clock = Clock; | |
// Check for existing recycle data that is still relevant. | |
var savedRecycleDay = Settings.option('savedRecycleDay'); | |
console.log('Saved Recycle Day is: ' + savedRecycleDay); | |
if (savedRecycleDay !== undefined) | |
{ | |
var tomorrow = clock.moment().add(1, 'd'); | |
var savedRecycleMoment = clock.moment(savedRecycleDay, "dddd, MMMM-DD-YYYY"); | |
console.log('Saved Recycle Moment is: ' + Clock.moment(savedRecycleMoment).format("dddd, MMMM Do YYYY")); | |
} | |
if (savedRecycleDay !== null && savedRecycleDay !== undefined && savedRecycleMoment.isAfter(tomorrow)) | |
{ | |
var card = new UI.Card({ | |
title:'Next Recycle Day:', | |
subtitle:savedRecycleDay | |
}); | |
card.show(); | |
} | |
else | |
{ | |
// Make request to Appleton API | |
ajax( | |
{ | |
//URL for Appleton API plus the user's property ID. | |
url:'http://appletonapi.appspot.com/property/' + propertyId, | |
type:'json' | |
}, | |
function(data) { | |
// The location of the recycling day is data[1].recycleday; | |
var recycleDay = data[1].recycleday; | |
// Create a Card with title and subtitle | |
var card = new UI.Card({ | |
title:'Next Recycle Day:', | |
subtitle:recycleDay | |
}); | |
//Save the recycle day to the watch settings storage (Settings.option) | |
Settings.option('savedRecycleDay', recycleDay); | |
// Display the Card | |
card.show(); | |
}, | |
function(error) { | |
console.log('Download failed: ' + error); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was overcomplicating things. Apparently, no import is needed. I can just use moment() without having to import or instantiate anything.
var tomorrow = clock.moment().add(1, 'd');
should be
var tomorrow = moment().add(1, 'd');
and
var savedRecycleMoment = clock.moment(savedRecycleDay, "dddd, MMMM-DD-YYYY");
should be
var savedRecycleMoment = moment(savedRecycleDay, "dddd, MM-DD-YYYY");
[PHONE] pebble-app.js:?: [PHONESIM] [WARNING] Exception decoding QemuInboundPacket.footer
[PHONE] pebble-app.js:?: (+) [window 1] : [window 1]
[PHONE] pebble-app.js:?: Property Id is: undefined
[PHONE] pebble-app.js:?: Saved Recycle Day is: Tuesday, 08-11-2015
[PHONE] pebble-app.js:?: Saved Recycle Moment is: Tuesday, August 11th 2015
[PHONE] pebble-app.js:?: (+) [card 2] : [window 1],[card 2]
[PHONE] pebble-app.js:?: [PHONESIM] [WARNING] Exception decoding QemuInboundPacket.footer