Skip to content

Commit

Permalink
added 7 day countdown minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-C-uk committed Jul 2, 2021
1 parent 9e49690 commit 830492b
Showing 1 changed file with 59 additions and 35 deletions.
94 changes: 59 additions & 35 deletions ical
Expand Up @@ -22,7 +22,7 @@ import java.text.SimpleDateFormat
import java.util.TimeZone

preferences {
input("icalink", "string", title: "ical link")
input("icalink", "string", title: "ical link(s), seperate with a ;")
input("updatefeq", "number", title: "Polling Rate (minuites)\nDefault:60", default:60)
input("shLoc", "bool", title: "Show location info?", default:false)
input("maxEvt", "number", title: "max number of events to show, if you regualy see 'please select an atribute' on dashboad, reduce this number\nDefault:10", default:10)
Expand Down Expand Up @@ -116,35 +116,53 @@ void getdata(){
}


Date today = new Date()
String todaydate = new SimpleDateFormat("dd-MM-yy").format(today)
log.debug "${today} & ${todaydate}"

//need to re forcast dates prio to sorting
/*
log.debug "${iCalMap.event.size()}"
iCalMap.event = iCalMap.event.values()sort{ a, b -> a.start <=> b.start} //sort the data
log.debug "sorted ${iCalMap.event.size()}"
iCalMap.event = iCalMap.event.unique()
log.debug "filltered ${iCalMap.event.size()}"
/*
iCalMap.event.each{
if (it.start == null) it.start = it.end // not used that i know off
if (it.end == null) it.end = it.start //used some envents didnt have a end date
(t,d,z) = timeHelp(it.start)
fullstart = z

(t,d,z) = timeHelp(it.end)
fullend = z
/*
if (it.repeatFreq){
(t,d,z) = timeHelp(it.start)
it.start = z
if (it.repeatFreq.contains("DAILY"){ //RRULE:FREQ=DAILY;WKST=TU // SEQUENCE:1
it.start = it.start + it.repeatNum-1 //add dd to time string

if (it.repeatFreq.contains("DAILY")&& !it.repeatFreq.contains("INTERVAL") && it.repeatNum < 0){ //RRULE:FREQ=DAILY;WKST=TU // SEQUENCE:1
log.debug "${fullstart} and ${it.repeatNum} and ${it.repeatFreq} and ${it.repeatNum}"
fullstart = fullstart + (it.repeatNum-1).days //add dd to time string
}
else if (it.repeatFreq.contains("WEEKLY") { //RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20210519T000000Z;INTERVAL=1;BYDAY=TU
it.start = it.start + (it.repeatNum-1*7)* //intervall from the string it.repeatFreq.find("INTERVAL=")+1charcter //add dd to time string
/*
else if (it.repeatFreq.contains("WEEKLY")) { //RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20210519T000000Z;INTERVAL=1;BYDAY=TU
log.debug "${it.start} and ${it.repeatNum-1*7} and ${it.repeatFreq}"
it.start = it.start + (it.repeatNum-1*7).days //intervall from the string it.repeatFreq.find("INTERVAL=")+1charcter //add dd to time string
}
else if (it.repeatFreq.contains("monthly") { // no data yet
it.start = it.start + (it.repeatNum-1) //add MM to time string
else if (it.repeatFreq.contains("monthly")) { // no data yet
it.start = it.start + (it.repeatNum-1).month //add MM to time string
}
else if (it.repeatFreq.contains("yearly") { // no data yet
it.start = it.start + (it.repeatNum-1) //add yyyy to time string
else if (it.repeatFreq.contains("yearly")) { // no data yet
it.start = it.start + (it.repeatNum-1).year //add yyyy to time string
}

}

*/
}

iCalMap.event = iCalMap.event.values()sort{ a, b -> a.start <=> b.start} //sort the data

Date today = new Date()
log.debug "${today}"
String todaydate = new SimpleDateFormat("dd-MM-yy").format(today)
log.debug "${today} & ${todaydate}"
}
*/
// iCalMap.event = iCalMap.event.values()sort{ a, b -> a.start <=> b.start} //sort the data
// log.debug iCalMap.event.size()
// iCalMap.event = iCalMap.event.unique()
// log.debug "fileter sorted again ${iCalMap.event.size()}"


Integer MaxCount = 0

Expand All @@ -164,35 +182,41 @@ void getdata(){
fullend = z
timeend = t

if (today<=fullstart || today<=fullend) { //and not canciled?

if (today<=fullstart || today<=fullend) { //and not canciled?
MaxCount = MaxCount +1
//today or date
if (today>=fullstart && today<=fullend || todaydate==datestart) attrString+="<tr><td style='font-size:${state.fontSize}px'>"+"TODAY"+" " //today events
else attrString+="<tr><td style='font-size:${state.fontSize}px'>"+datestart+" " //start date


if (today>=fullstart && today<=fullend || todaydate==datestart){ //today events
attrString+="<tr><td style='font-size:${state.fontSize}px'>"+"TODAY"+" "
}
else if (fullstart-today < 7) { //in 7 days
String days = fullstart-today
String dayordays
if (days == "1") dayordays = "day"
else dayordays = "days"
attrString+="<tr><td style='font-size:${state.fontSize}px'>"+"In "+days+" "+dayordays+" " //start date
}
else { // > 7 days
attrString+="<tr><td style='font-size:${state.fontSize}px'>"+datestart+" " //start date
}
// all day or times
if(it.start.indexOf("T") == -1) {attrString+="All Day</td></tr>"} //all day event
else { //time event
attrString+=timestart+" to " //start time
attrString+=timeend+"</td></tr>" //end time
}

//description and location
if(it.start.indexOf("T") == -1) {attrString+="All Day</td></tr>"} //all day event
else attrString+=timestart+" to "+timeend+"</td></tr>" //time event
//description
attrString+="<tr><td style='font-size:${state.fontSize-2}px'>${it.summary}</td></tr>" //description
//location
if(it.location != null) attrString+="<tr><td style='font-size:${state.fontSize-5}px'>${it.location.replace('\\','')}</td></tr>" //location

}

}
}

attrString+="</table>"

//log.debug"end"
if(attrString.length() >= 1024) log.warn "To many Char. please reduce max number of events or turn off location = ${attrString.length()}"
sendEvent(name:"tileAttr",value:attrString)
sendEvent(name: "CharCount", value: "${attrString.length()} out of 1024 alowed")
log.info "done get"
runIn(state.updatefeq,getdata)
}

Expand Down

0 comments on commit 830492b

Please sign in to comment.