![Page 1: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/1.jpg)
WHEN THE HECK IS 4/8/2016?
A K A J U S T O N E O F T H E M A N Y T H I N G S T H E Y N E V E R TO L D YO U A B O U T …
![Page 2: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/2.jpg)
![Page 3: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/3.jpg)
WHO THE HECK AM I?
• Developer Advocate for IBM
• MobileFirst, Bluemix, Cordova/PhoneGap, and web stuff in general
• Blogging at raymondcamden.com
• Tweeting at @raymondcamden• Author of "Apache Cordova in Action" and "Client-Side
Data Storage"
![Page 4: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/4.jpg)
![Page 5: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/5.jpg)
![Page 6: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/6.jpg)
![Page 7: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/7.jpg)
SLIGHTLY MORE COMPLICATED…
![Page 8: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/8.jpg)
TIL
• America is one country
• There are other countries
• They use the Internet too!
![Page 9: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/9.jpg)
BUT WAIT…
• They speak a different language (that's cool)
• They use a different unit of measurement (that's mostly cool too)
• "NASA lost a $125 million Mars orbiter because a Lockheed Martin engineering team used English units of measurement while the agency's team used the more conventional metric system for a key spacecraft operation..." (oh crap)
• They write numbers differently (that's just insane)
![Page 10: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/10.jpg)
AN EXAMPLE…
1,000,000.99
1.000.000,99
1 000 000,99
![Page 11: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/11.jpg)
4/8/2016
![Page 12: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/12.jpg)
IS IT…
• April?
• August?
• It's my birthday – so you're both right!
![Page 13: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/13.jpg)
PROBLEM
• Numbers change
• Currencies change
• Dates change
![Page 14: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/14.jpg)
SOLUTION
• Pretend the rest of the world doesn't exist!
![Page 15: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/15.jpg)
REAL SOLUTION
• Detect the locale of the device
• Format numbers/dates accordingly
• Pro Tip: You can't just format American money into a Euro.– 1$ ≠ 1€
![Page 16: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/16.jpg)
GLOBALIZATION PLUGIN FTW
• https://www.npmjs.com/package/cordova-plugin-globalization
• cordova plugin add cordova-plugin-globalization• Supports numbers, currencies, and dates
• Supports getting information about locale/language
• Supports getting information about formats
• Even supports isDayLightSavingsTime – because that's still a thing apparently
![Page 17: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/17.jpg)
JUST ADD IT!
• Yes, you just add the plugin and your magically done!
![Page 18: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/18.jpg)
IDENTIFY CRAP TO UPDATE
• Check each view
• Look at the data
• Figure out what makes sense to localize
![Page 19: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/19.jpg)
![Page 20: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/20.jpg)
![Page 21: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/21.jpg)
http://www.raymondcamden.com/2015/10/14/adding-localization-to-your-ionic-application-with-ibm-bluemix/
![Page 22: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/22.jpg)
bankService.getAccountDetails().then(function(res) {$scope.bankAccount = res;
});
...
Total in account: ${{bankAccount.total}}Last Updated: {{bankAccount.lastUpd}}
![Page 23: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/23.jpg)
bankService.getAccountDetails().then(function(res) {
//$scope.bankAccount = res;navigator.globalization.numberToString(
res.total, function(number) {$scope.bankAccount.total = number.value;
},function() {}, {type:'currency'});
navigator.globalization.dateToString(new Date(res.lastUpd), function(d) {
$scope.bankAccount.lastUpd = date.value;}, function() {}, { options });
});
![Page 24: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/24.jpg)
OPTIONS
• For numbers:– decimal
– fraction
– currency (doesn't work in Browser)
• For dates:– formatLength: short, medium, long, and full
– "Apr 8, 2016 12:00 AM", "April 8, 2016 12:00 AM", "Fri, Apr 8, 2016 12:00 AM", "Friday, April 8, 2016 12:00 AM"
– selector: "date", "time", "date and time"
![Page 25: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/25.jpg)
![Page 26: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/26.jpg)
Changed Region (Locale) to France but kept language to English
![Page 27: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/27.jpg)
Changed language to Frenchbut kept Region/Locale to US
![Page 28: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/28.jpg)
Changed both region +language to French
![Page 29: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/29.jpg)
WHAT TO DO?
• Currency seems inherently unsafe
• Given you use "X seashells" for country Y using the ** symbol – just format it as a number and use ** on display
![Page 30: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/30.jpg)
WE'RE DONE!
• Nothing else can go wrong
• It's all downhill from here
• Rainbows and kittens and cookies for everyone!
![Page 31: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/31.jpg)
WHAT ABOUT LOTS OF DATA?
![Page 32: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/32.jpg)
PROMISES!
• Just promise the hell out of that crap!
• JavaScript Promises
• http://www.raymondcamden.com/2012/11/15/Testing-Globalization-Support-in-PhoneGap-22/
![Page 33: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/33.jpg)
ALTERNATIVES – PART 1
• One of the many libraries out there
• Moment.js
• http://momentjs.com/docs/#/i18n/
![Page 34: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/34.jpg)
ALTERNATIVES – PART 2
• Intl
• ECMAScript Internationalization API
• window.numberFormatter.format(n);
• http://code.tutsplus.com/tutorials/working-with-intl--cms-21082
• OMG AWESOME NO PLUGIN NO LIBRARY PERFECT!!!!!!!!!!!!!!11!!!!
• Let's check CanIUse.com
![Page 35: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/35.jpg)
![Page 36: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/36.jpg)
![Page 37: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/37.jpg)
BUT WAIT…
• I'm an American (sorry)
• I'm in America (not sorry – woot!)
• I'm looking at an event in France
• How should the date be formatted?
• Best for me – obviously? Right?
• Anything you do automatically – treat with caution
![Page 38: WHEN THE HECK IS 4/8/2016? · when the heck is 4/8/2016? aka just one of the many things they never told you about…](https://reader033.vdocuments.us/reader033/viewer/2022060906/60a130cb09f2396e2e3cca97/html5/thumbnails/38.jpg)