Help with display of dates in log


(Aaron) #1

In a SmartApp have code: log.info "scheduling sunrise handler for $state.riseTime"
That produces: 10:11:28 AM: info scheduling sunrise handler for Thu Nov 20 12:48:00 UTC 2014

and, in the same SmartApp, this: log.info "scheduling sunset handler for $state.setTime"
produces: 10:25:53 AM: info scheduling sunset handler for 1416437160000

I have read in the documentation regarding the issue of using the state method with dates. Is there a way to revise the log statements to force the display of dates in a normal date format? I think the functional part is OK. . . just would like the log to be human readable (without conversion)

BTW - I am almost 100% sure that, last night, both values were displayed as milliseconds.


(Brian) #2

Its showing up in Epoch time, which the IDE isnt properly formatting for you. Likely one of the many UI glitches. I would log out and log back in :frowning:


(Aaron) #3

Here’s another clue. . . .There is a conditional branch in the code. Depending on the time of day the code runs, neither, one, or both of the time values get a next() method applied. Seems like creating the state object wipes the tag but applying the next() method restores it. Could this be possible? Right now, since it is after midnight, neither value gets the next() method and, right now, both values are displayed in Epoch time.


(Andrew Urman) #4

Epoch time just sounds so damn cool.


(Aaron) #5

Well, OK. I thought this was going to be easy. If it helps, here is the entire method:

def astroCheck() {
	//query sunset and sunrise times with offsets applied, schedule handlers for sun events
    //this method lifted from Sunrise/Sunset with some mods and error corrections
    
	def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)
	def now = new Date()
	def riseTime = s.sunrise
	def setTime = s.sunset
	log.debug "riseTime: $riseTime"
	log.debug "setTime: $setTime"
    log.debug "Now: $now"
	
	if (state.riseTime != riseTime.time) {
		state.riseTime = riseTime.time
		
		unschedule("sunriseHandler")
		if(riseTime.before(now)) {
			state.riseTime = riseTime.next()
		}
		
        
        log.info "scheduling sunrise handler for $state.riseTime"
        //todo: resolve issue with date formated as Epoch sometimes in log
		schedule(state.riseTime, sunriseHandler)
	}
   
	if (state.setTime != setTime.time) {
		state.setTime = setTime.time
		unschedule("sunsetHandler")

	    if(setTime.before(now)) {
	        state.setTime = setTime.next()
	    }
	    
        
        log.info "scheduling sunset handler for $state.setTime"
        //todo: resolve issue with date formated as Epoch sometimes in log
	    schedule(state.setTime, sunsetHandler)
	}
}

@matthewnohr - if you have a chance, can you look at this? Solving the issue in Sunrise/Sunset seemed to cause this problem :wink:


(Aaron) #6

I just discovered the status screen for my SmartApp which shows the tag/format confusion that exists within the app:

However, the app is running without issue in practice and the future sunset and sunrise handlers are being scheduled correctly in spite of the tag issue:

Even though this is a really minor issue, I would still like to solve it and better understand the concepts involved.


(Ron) #7

@AaronZON Where can you see these status screens ? I don’t see them in the ide


(Ron S) #8

My Location -> SmartApps (6th column) ->Scroll to the SmartApp of interest ->Click it. This popup will open.


(Aaron) #9

what he said. . …

BTW, all of the questions I had with handling dates in ST have been answered here and in this thread: Troubleshooting scheduled event failures