Skip to content

Commit

Permalink
Merge pull request #1 from flautrup/add_locale_support
Browse files Browse the repository at this point in the history
Add locale support and 12H support
  • Loading branch information
flautrup authored Apr 23, 2020
2 parents d1bb0d3 + 5c3e5ff commit b4bec5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/rclock/ChangeLog
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0.01: First published version of app
0.02: Added support for locale and 12H clock
36 changes: 24 additions & 12 deletions apps/rclock/rclock.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
var hours;
var date;
var first = true;
var locale = require('locale');
var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false;

const screen = {
width: g.getWidth(),
Expand Down Expand Up @@ -41,17 +43,7 @@
};

const dateStr = function (date) {
day = date.getDate();
month = date.getMonth();
year = date.getFullYear();
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}

return year + "-" + month + "-" + day;
return locale.date(new Date(),1);
};

const getArcXY = function (centerX, centerY, radius, angle) {
Expand Down Expand Up @@ -133,9 +125,29 @@

//Write the time as configured in the settings
hours = currentTime.getHours();
if(_12hour && hours>13) {
hours=hours-12;
}

var meridian;

if (typeof locale.meridian === "function") {
meridian=locale.meridian(new Date());
} else {
meridian="";
}

var timestr;

if(meridian.length>0 && _12hour) {
timestr=hours+" "+meridian;
} else {
timestr=hours;
}

g.setColor(settings.time.color);
g.setFont(settings.time.font, settings.time.size);
g.drawString(hours, settings.time.center, settings.time.middle);
g.drawString(timestr, settings.time.center, settings.time.middle);

//Write the date as configured in the settings
g.setColor(settings.date.color);
Expand Down

0 comments on commit b4bec5c

Please sign in to comment.