Skip to content

Commit

Permalink
var
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-blackson committed Jul 28, 2023
1 parent 2502293 commit 5f67b2d
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 153 deletions.
72 changes: 3 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,78 +20,12 @@ Countdown Adapter for ioBroker

The goal of the adapter is to provide you a possibility to run countdowns for future events, with years, months, days, hours and minutes. It will provide you each of those valies seperately, and also two strings with a short and long version of the date.

## How to use it

## Displaying countdowns
The adapter provides you automatically a json table and as a HTML table. For the json, please choose the widget "basic-table". For the html, choose the "basic - string (unescaped)" one.
[English description](docs/en/countdown.md)

It is possible to either display the short text or the long text.
![Logo](admin/countdown_json.png)
[Deutsche Anleitung](docs/de/countdown.md)

## How to create countdowns
There are two ways to set up countdowns:

* You can create a countdown in the adapter settings, in the tab "Create Countdown".
* You can create a manual state in the device "setup". The name of the object is the alarm name, and the value will be the date. The date neets to be in the format "DD.MM.YYYY HH:mm:ss".
* You can create an alarm with sendto. There, you can either send the components (minimum is Year Month Date) or a date string. For the date string, you can adjust the format in the setup of the adapter.
![Logo](admin/countdown_blocky.png)
* You can add days, months and years with sendto to todays date. Therefore, please send the component "name" and either "addminutes", "addhours", "adddays", "addmonths" or "addyears" as int value.
![Logo](admin/countdown_blocky_add.png)

## How to delete countdowns
You can delete a countdown with the sendto. Therefore, send just the name with sendto to the adapter, and the countdown will be deleted automatically.

## Repeating countdown
If you want a countdown to repeat in a defined period (e.g. you cant a countdown for your wedding day every year) you can also do this with this adapter. Therefore either fill the field "Repeat period" in the settings of the adapter, or add the period after the date when you create a countdown with the type "date". A sendTo would look like that for a countdown which should end on the 1st of April 2020 and repeat every year:

sendTo("countdown.0", "send", {
"name": 'Wedding Day',
"date": '01.04.2020 00:01+1Y'
});

## Count Up
Newly added is the feature to "count up" - so to count the days from a date in the past. This can be done either in the adapter setup, or with adding a "#" to a date string, e.g.

sendTo("countdown.0", "send", {
"name": 'Birthdate',
"date": '01.04.2020 00:01#
});



Parameters here are:
* Y: Years
* M: Months
* D: Days
* H: Hours
* m: Minutes


## Available outputs

|Data type|Description|
|:---:|:---:|
|minutes|Minutes until countdown end (not total!)|
|hours|Hours until countdown end (not total!)|
|days|Days until countdown end (not total!)|
|months|Months until countdown end (not total!)|
|years|Years until countdown end (not total!)|
|name|Countdown name|
|endDate|End date of countdown - formated as in the setup defined|
|inWordsShort|Combined value of minutes, hours,... - e.g. 1Y 5M 4D|
|inWordsLong|Combined value of minutes, hours,... - e.g. 1 Year 5 Months 4 Days|
|totalHours|Total no. of hours until the end date|
|totalDays|Total no. of days until the end date|
|totalWeeks|Total no. of weeks until the end date|
|totalMonths|Total no. of months until the end date|
|totalYears|Total no. of years until the end date|

|reached|Boolean field defining if the end date was reached or not|
|repeatEvery|Countdown is repeted by this period after reaching the enddate|


## Features to add
* Possibility to add a script as a parameter and start it when countdown ends
* Possibility to use plus and minus in addminutes and the other add functions

## Changelog

Expand Down
147 changes: 63 additions & 84 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
}

})
console.log('Found ' + originalNames[i] + " :" + found)
if (!found){
sendTo(adapter + '.' + instance, 'send', {
"name": originalNames[i],
Expand All @@ -74,31 +73,48 @@
// update setup entries
for (var i = 0; i < countdownData.length; i++) {

console.log('orig Date: ' + countdownData[i].countdownDate)
if (checkError(countdownData[i].countdownName,countdownData[i].countdownDate,countdownData[i].countdownTime)){

var dateMomentObject = moment(countdownData[i].countdownDate, "YYYY-MM-DD");
console.log('New Date: ' + dateMomentObject)
var dateMomentObject = moment(countdownData[i].countdownDate, "YYYY-MM-DD");

var dateString = moment(dateMomentObject).local().format('DD.MM.YYYY')
dateString += ' ' + countdownData[i].countdownTime + ':00'
var dateString = moment(dateMomentObject).local().format('DD.MM.YYYY')
dateString += ' ' + countdownData[i].countdownTime + ':00'

if (countdownData[i].countdownRepeatCycle != ''){
dateString += '+' + countdownData[i].countdownRepeatCycle
if (countdownData[i].countdownRepeatCycle != ''){
dateString += '+' + countdownData[i].countdownRepeatCycle
}
if (countdownData[i].countdownCountUp){
dateString += '#'
}
if (countdownData[i].countdownCountUp){
dateString += '#'
}
console.log('DateString: ' + dateString)


sendTo(adapter + '.' + instance, 'send', {
"name": countdownData[i].countdownName,
"date": dateString
sendTo(adapter + '.' + instance, 'send', {
"name": countdownData[i].countdownName,
"date": dateString
})

}


}

}

function checkError(countname,date,time){
var noerrorFound = true
if (name = ""){
showToast(_('Please fill in a name for the countdown!'));
noerrorFound = false
}
if (!moment(date, 'YYYY-MM-DD',true).isValid()) {
showToast(_('Please fill in a valid date for the countdown '+ countname ));
noerrorFound = false
}


console.log('No error found for ' + countname + ': ' + noerrorFound)
return noerrorFound
}

function load(settings, onChange) {
_onChange = onChange;
Expand All @@ -124,44 +140,6 @@
onChange(false);
if (M) M.updateTextFields();

/*
$('#addCountdown').on('click', function () {
let CountdownName = $('#CountName').val();
let CountdownDate = $('#CountDate').val();
let CountdownTime = $('#CountTime').val();
let RepeatPeriod = $('#RepeatPeriod').val();
let CountUp = $('#CountUp').is(':checked');
if (CountdownName == ''){
showToast(_('Please fill in a name for the countdown!'));
}
else if ((CountdownTime == '')|| (CountdownDate =='')) {
showToast(_('Please fill in date and time for the countdown!'))
}
else {
let CountYear = CountdownDate.slice(0, 0 + 4)
let CountMonth= CountdownDate.slice(5, 5 + 2)
let CountDay = CountdownDate.slice(8, 8 + 2)
var CountDateTime = ''
CountDateTime = CountDay + '.' + CountMonth + '.' + CountYear + ' ' + CountdownTime + ':00'
if (RepeatPeriod != ''){
CountDateTime += '+' + RepeatPeriod
}
if (CountUp){
CountDateTime += '#'
}
sendTo(adapter + '.' + instance, 'send', {
"name": CountdownName,
"date": CountDateTime
})
showToast(_('Countdown ' + CountdownName + ' with date ' + CountDateTime + ' added.'))
}
console.log('Countdown ' + CountdownName + ' ' + CountdownDate)
});
*/
}
function loadSetup() {

Expand Down Expand Up @@ -221,8 +199,37 @@
</ul>
</div>


<div id="tab-addcountdown" class="col s12 page">
<div class="row">
<div class="input-field col s3">
<img src="countdown.png" class="logo">
</div>
</div>
<div class="row">
</div>
<div class="col s10" id="countdownData">
<div class="row">
<div class="col s2 m1 l1 left">
<a id="responseOIDDialog" class="btn-floating waves-effect waves-light blue table-button-add"><i class="material-icons">add</i></a>
</div>
</div>
<div class="table-values-div">
<table class="table-values">
<thead>
<tr>
<th data-name="countdownName" class="translate city" data-style="text-align: left">name</th>
<th data-name="countdownDate" class="translate lati" data-type="date" data-style="text-align: left">date</th>
<th data-name="countdownTime" class="translate lati" data-type="time" data-style="text-align: left">time</th>
<th data-name="countdownRepeatCycle" class="translate lati" data-style="text-align: left">repeatColoumn</th>
<th data-name="countdownCountUp" data-type="checkbox" class="translate lati" data-style="text-align: left">countUp</th>
<th data-buttons="delete" class="translate">delete</th>
</tr>
</thead>
</table>
</div>
</div>

</div>

<div id="tab-settings" class="col s12 page">
<div class="row">
Expand Down Expand Up @@ -288,35 +295,7 @@
</div>
</div>
</div>
<div id="tab-addcountdown" class="col s12 page">
<div class="row">
<div class="input-field col s3">
<img src="countdown.png" class="logo">
</div>
</div>
<div class="row">
</div>
<div class="col s10" id="countdownData">
<div class="row s10 left">
<a class="waves-effect waves-light btn table-button-add translate">addCountdown</a>
</div>
<div class="table-values-div">
<table class="table-values">
<thead>
<tr>
<th data-name="countdownName" class="translate city" data-style="text-align: left">name</th>
<th data-name="countdownDate" class="translate lati" data-type="date" data-style="text-align: left">date</th>
<th data-name="countdownTime" class="translate lati" data-type="time" data-style="text-align: left">time</th>
<th data-name="countdownRepeatCycle" class="translate lati" data-style="text-align: left">repeatColoumn</th>
<th data-name="countdownCountUp" data-type="checkbox" class="translate lati" data-style="text-align: left">countUp</th>
<th data-buttons="delete" class="translate">delete</th>
</tr>
</thead>
</table>
</div>
</div>

</div>

</div>
</div>
</body>
Expand Down
2 changes: 2 additions & 0 deletions docs/de/countdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ioBroker.countdown

71 changes: 71 additions & 0 deletions docs/en/countdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ioBroker.countdown

## Displaying countdowns
The adapter provides you automatically a json table and as a HTML table. For the json, please choose the widget "basic-table". For the html, choose the "basic - string (unescaped)" one.

It is possible to either display the short text or the long text.
![Logo](admin/countdown_json.png)

## How to create countdowns
There are several ways to set up countdowns:

* You can create a countdown in the adapter settings, in the tab "Create Countdown".
* You can create a manual state in the device "setup". The name of the object is the alarm name, and the value will be the date. The date neets to be in the format "DD.MM.YYYY HH:mm:ss".
* You can create an alarm with sendto. There, you can either send the components (minimum is Year Month Date) or a date string. For the date string, you can adjust the format in the setup of the adapter.
![Logo](admin/countdown_blocky.png)
* You can add days, months and years with sendto to todays date. Therefore, please send the component "name" and either "addminutes", "addhours", "adddays", "addmonths" or "addyears" as int value.
![Logo](admin/countdown_blocky_add.png)

## How to delete countdowns
You can delete a countdown with the sendto. Therefore, send just the name with sendto to the adapter, and the countdown will be deleted automatically.

## Repeating countdown
If you want a countdown to repeat in a defined period (e.g. you cant a countdown for your wedding day every year) you can also do this with this adapter. Therefore either fill the field "Repeat period" in the settings of the adapter, or add the period after the date when you create a countdown with the type "date". A sendTo would look like that for a countdown which should end on the 1st of April 2020 and repeat every year:

sendTo("countdown.0", "send", {
"name": 'Wedding Day',
"date": '01.04.2020 00:01+1Y'
});

Parameters here are:
* Y: Years
* M: Months
* D: Days
* H: Hours
* m: Minutes

## Count Up
Newly added is the feature to "count up" - so to count the days from a date in the past. This can be done either in the adapter setup, or with adding a "#" to a date string, e.g.

sendTo("countdown.0", "send", {
"name": 'Birthdate',
"date": '01.04.2020 00:01#
});


## Available outputs

|Data type|Description|
|:---:|:---:|
|minutes|Minutes until countdown end (not total!)|
|hours|Hours until countdown end (not total!)|
|days|Days until countdown end (not total!)|
|months|Months until countdown end (not total!)|
|years|Years until countdown end (not total!)|
|name|Countdown name|
|endDate|End date of countdown - formated as in the setup defined|
|inWordsShort|Combined value of minutes, hours,... - e.g. 1Y 5M 4D|
|inWordsLong|Combined value of minutes, hours,... - e.g. 1 Year 5 Months 4 Days|
|totalHours|Total no. of hours until the end date|
|totalDays|Total no. of days until the end date|
|totalWeeks|Total no. of weeks until the end date|
|totalMonths|Total no. of months until the end date|
|totalYears|Total no. of years until the end date|

|reached|Boolean field defining if the end date was reached or not|
|repeatEvery|Countdown is repeted by this period after reaching the enddate|


## Features to add
* Possibility to add a script as a parameter and start it when countdown ends
* Possibility to use plus and minus in addminutes and the other add functions

0 comments on commit 5f67b2d

Please sign in to comment.