I have this timer I wrote myself but its way too complicated and then when I need to get back to it to re-use it I already forgot how it works and always takes some time to understand. For sure there must be a simpler way to do it.
Here it is:
=IF(((E4/86400+DATE(1970,1,1))+TIME($K$9,0,0))<NOW(),"RENT", IF((TRUNC(((iferror(datedif(NOW(), E4/86400+DATE(1970,1,1), "d"),""))-TIME((24-(text(E4/86400+DATE(1970,1,1) - NOW() - int(E4/86400+DATE(1970,1,1) - NOW())+TIME($K$9,0,0), "HH"))),0,0))) - 365 * iferror(datedif(NOW(), E4/86400+DATE(1970,1,1), "y"),""))<(1),"",(TRUNC(((iferror(datedif(NOW(), E4/86400+DATE(1970,1,1), "d"),""))-TIME((24-(text(E4/86400+DATE(1970,1,1) - NOW() - int(E4/86400+DATE(1970,1,1) - NOW())+TIME($K$9,0,0), "HH"))),0,0))) - 365 * iferror(datedif(NOW(), E4/86400+DATE(1970,1,1), "y"),""))&"d ")&(TEXT((E4/86400+DATE(1970,1,1))-(now()-TIME($K$9,0,0)),"HH""h"" mm""m""")))
The "d" from days needs to disappear when ETA is less than 24h.
Is there a cleaner simpler way to do this?
My file:
https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
unix input countdown:
=REGEXREPLACE(TEXT(E4/86400+25569-NOW(),
"\"&INT(E4/86400+25569-NOW())&"\d h\h m\m"), "0d ", )
Related
I'm developing a simple app in Swift and I need to schedule a function execution every 24 hours. I'm aware of the method:
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: {
self.functionToCall()
})
that could solve my problem but, is this the right solution for a 24 hours delay?
Thanks
Theoretically, this is possible.
The problem is that your app would have to run in the foreground for 24 hours, which is very unlikely to happen. Unfortunately, you can not run background tasks just like that.
The solution:
Just make it look like the function would execute in the background. Every time the update function is called, simply save the Int(Date().timeIntervalSince1970) to UserDefaults. This works like a timestamp and saves the last time you called your update function. Every time in the viewDidLoad()-function (not sure if it's called the same on Mac apps, but you can imagine what I mean) call:
If let timestamp = UserDefaults.standard.integer(forKey: "yourTimestampKey") {
let currentTimestamp = Date().timeIntervalSince1970
if (currentTimestamp - timestamp) > 86400 { // number of seconds in 24 hours
// the last time your function was updated was at least 24h ago
update()
}
}
That's how you can make it appear like it was updated in the background. I use this all the time in my apps and it works perfectly.
EDIT:
Maybe, just in case the app does indeed run 24 hours in a row, I would set up the upper function that you posted first as well.
I'm looking for the best way to determine whether the current time is between 9PM and 6AM, and perform the relevant action, depending on the boolean.
I'm not entirely sure on the best way of doing this though... I'm thinking I could maybe use epoch time (Time::Local) to get the time as it was at 9PM last night, and the time that it will be at 6AM the following day - but is this the best way of doing it or is there a better way?
Thanks
This is all that is necessary
my $hour = (localtime)[2];
if ( $hour >= 21 or $hour < 6 ) { ... }
I am trying to use the Joda Time library to help me schedule sending some messages to an Actor in Akka.
I would like to schedule sending emails every day at 8:30 AM. To do this, I have to tell the scheduler how many seconds (or milliseconds) to wait until the next message is sent.
I would like to account for daylight savings (to make sure it always fires around 8:30, and not 7:30 or 9:30) so I will use LocalDate and LocalTime.
So, basically, I have:
targetDate = LocalDate.now().plusDays(1) and targetTime = new LocalTime(8, 30)
and
rightNow = LocalDateTime.now()
I was wondering what is the best way to compose a targetDateTime based on targetDate and targetTime so I can use it to compute the time difference with rightNow
I know I can create a new LocalDateTime extracting all the values for the constructor from my targetDate and targetTime but: is there a more elegant way?
So far, I have settled for:
targetDateTime = targetDate.toLocalDateTime(targetTime)
secondsToWait = Seconds.secondsBetween(rightNow, targetDateTime)
Getting targetDateTime is easy if you have the targetDate and targetTime (as given in your question) :
targetDateTime = targetDate.toDateTime(targetTime);
Getting the seconds of the Duration between now and targetDateTime:
new Duration(new DateTime(), targetDateTime).getStandardSeconds();
The method is called standard seconds because it assumes every second to be a standard second of 1000 milliseconds. As its javadoc says, currently all Chronologies only have standard seconds.
But you can also simply use milliseconds (no conversion assumptions needed) :
new Duration(new DateTime(), targetDateTime).getMillis();
Disclaimer : I only just saw this was a scala question, so you may have to correct for any syntax differences, since I'm not versed in scala.
I'm building an application to record when my cat has an asthma attack. I'm not interested in the exact time since glancing at the time in interval of 15 minutes is easier to review (e.g. rounding 9:38am should be recorded as 9:45am).
I looked for a UDF at cflib.org for this but couldn't find one. I tinkered with CF's round function but I'm not getting it to do what I want.
Any advice?
This could do with a bit more polish (like data type validation) but it will take a time value and return it rounded to the nearest 15-minute increment.
<cfscript>
function roundTo15(theTime) {
var roundedMinutes = round(minute(theTime) / 15 ) * 15;
var newHour=hour(theTime);
if (roundedMinutes EQ 60) {
newHour=newHour + 1;
roundedMinutes=0;
}
return timeFormat(createTime(newHour,roundedMinutes,0),"HH:mm");
}
</cfscript>
I'm not familiar with the format of the timestamp here, but generally when I want to round I do something like floor((val + increment / 2) / increment) * increment
I like Al Everett's answer, or alternatively store the actual time to preserve the most accurate time, then use query of query in the view and use between :00 and :15 to show the time in 15min period.
If you use Henry's suggestion to store the precise time in the database (principle: if there's no cost, prefer to preserve data), then you can simply use Al Everett's rounding function whenever you display the data to the user.
is it any possible to get time left for uploading files using swfupload?
You can most certainly estimate the time remaining, but this isn't a feature built-in to SWFUpload to my knowledge. Here's what I do:
In your uploadStart() handler for your file, record the start time of the upload and store in somewhere.
var startTime = +new Date(); // the current date time in UTC * 1000 milliseconds
Then, in your uploadProgress() handler for the same file:
var percentage = bytesLoaded/file.size,
timeDiff = +new Date() - startTime,
status = (percentage > 0 ? Math.round(timeDiff / percentage / 1000 * (1 - percentage)) + " seconds remaining." : "Uploading...");
Works well!
I hope this is helpful.
EDIT, added test for percentage > 0
No, because the time taken to upload anything over a normal Internet connection can never be known in advance due to speed fluctuations. On the other hand swfupload provides a progress handler to report the percentage uploaded so you can either use that to display a progress counter/bar or guesstimate the time remaining based on the time already spent and hope it's somewhat accurate.