10-29-2017 03:16 - edited 10-29-2017 03:17
10-29-2017 03:16 - edited 10-29-2017 03:17
Has anybody some experience with the following task?
Since .toLocaleString() seems to support "en-??" only, I need to localise the montname and the weekday maually.
I have three different approaches and I'm asking myself, which would have the best performance and best space efficiency on the Ionic.
Approach 1: Arrays
var weekday = [];
var monthname = [];
weekday["en"]=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
monthName["en"]=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
weekday["de"] = ["Sonntag", "Montag", "Dienstag", "Mitwoch", "Donnerstag", "Freitag", "Samstag"];
monthName["de"] = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
Approach 2: Objects
var weekday = { en: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
de: ["Sonntag", "Montag", "Dienstag", "Mitwoch", "Donnerstag", "Freitag", "Samstag"],
};
var monthName = {
de: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
en: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
};
Approach 3: switch
function getWeekDay(prefix, num) { var weekday = []; switch (prefix) { case "de": weekday = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]; break; case "en": weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; break;
};
function getMonthName(prefix, num) {
var monthname = [];
switch (prefix) {
case "de":
monthname = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
break;
case "en":
monthname = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
break;
}
Which apporach would you prefer and why?
Answered! Go to the Best Answer.
10-29-2017 14:16 - edited 10-30-2017 07:02
10-29-2017 14:16 - edited 10-30-2017 07:02
I believe all 3 approaches would consume about the same memory and perform about the same. The advantage of any of these 3 approaches would be so minor it's not worth worrying about.
Update:
This question was bugging me last night, so I did a little digging and confirmed that there is little to no difference between the 3. Approach #1 and #2 have the most consistent performance, and for simplicity sake, I'd recommend #2.
10-29-2017 14:16 - edited 10-30-2017 07:02
10-29-2017 14:16 - edited 10-30-2017 07:02
I believe all 3 approaches would consume about the same memory and perform about the same. The advantage of any of these 3 approaches would be so minor it's not worth worrying about.
Update:
This question was bugging me last night, so I did a little digging and confirmed that there is little to no difference between the 3. Approach #1 and #2 have the most consistent performance, and for simplicity sake, I'd recommend #2.
10-30-2017 14:03
10-30-2017 14:03
Thank you! I'll choose approach # 2.