Merge pull request #198 from Intecpsp/v2-beta

Allow 12 hour period config
This commit is contained in:
Michael Teeuw 2016-04-19 07:48:10 +02:00
commit a7948ee1da
4 changed files with 50 additions and 3 deletions

View File

@ -45,5 +45,19 @@ The following properties can be configured:
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
<tr>
<td><code>showPeriod</code></td>
<td>Show the period (am/pm) with 12 hour format<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
<tr>
<td><code>showPeriodUpper</code></td>
<td>Show the period (AM/PM) with 12 hour format as uppercase<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>false</code>
</td>
</tr>
</tbody>
</table>

View File

@ -13,6 +13,8 @@ Module.register("clock",{
defaults: {
timeFormat: config.timeFormat,
displaySeconds: true,
showPeriod: true,
showPeriodUpper: false,
},
// Define required scripts.
@ -55,7 +57,15 @@ Module.register("clock",{
if (this.config.timeFormat !== 24) {
var now = new Date();
var hours = now.getHours() % 12 || 12;
timeString = hours + moment().format(':mm a');
if (this.config.showPeriod) {
if (this.config.showPeriodUpper) {
timeString = hours + moment().format(':mm A');
} else {
timeString = hours + moment().format(':mm a');
}
} else {
timeString = hours + moment().format(':mm');
}
}
dateWrapper.innerHTML = moment().format("dddd, LL");

View File

@ -76,6 +76,20 @@ The following properties can be configured:
<br><b>Default value:</b> uses value of <i>config.timeFormat</i>
</td>
</tr>
<tr>
<td><code>showPeriod</code></td>
<td>Show the period (am/pm) with 12 hour format<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
<tr>
<td><code>showPeriodUpper</code></td>
<td>Show the period (AM/PM) with 12 hour format as uppercase<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>false</code>
</td>
</tr>
<tr>
<td><code>lang</code></td>
<td>The language of the days.<br>
@ -140,6 +154,5 @@ The following properties can be configured:
}</code>
</td>
</tr>
</tbody>
</table>

View File

@ -17,6 +17,8 @@ Module.register("currentweather",{
updateInterval: 10 * 60 * 1000, // every 10 minutes
animationSpeed: 1000,
timeFormat: config.timeFormat,
showPeriod: true,
showPeriodUpper: false,
lang: config.language,
initialLoadDelay: 0, // 0 seconds delay
@ -209,7 +211,15 @@ Module.register("currentweather",{
var timeString = moment(sunriseSunsetDateObject).format('HH:mm');
if (this.config.timeFormat !== 24) {
var hours = sunriseSunsetDateObject.getHours() % 12 || 12;
timeString = hours + moment(sunriseSunsetDateObject).format(':mm a');
if (this.config.showPeriod) {
if (this.config.showPeriodUpper) {
timeString = hours + moment(sunriseSunsetDateObject).format(':mm A');
} else {
timeString = hours + moment(sunriseSunsetDateObject).format(':mm a');
}
} else {
timeString = hours + moment(sunriseSunsetDateObject).format(':mm');
}
}
this.sunriseSunsetTime = timeString;