Perl - Check if the current time between 9PM and 6AM - perl

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 ) { ... }

Related

How to build a timer in google sheets

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 ", )

Rexx: increment current time value

Hi I'm running REXX script on ZOC terminal and i want to display current time and ETA like this:
start time 22:44:24
end time 22:56:24
but I don't know how to increment current time ???
maybe to convert time to seconds then increment it and then convert time in seconds back to hh:mm:ss ??
I tried this way but dont know how to convert back time from seconds
intTime= TIME('S')+900
say="start time " TIME()
say="end time " intTime
One way would be along the lines of:-
intTime = TIME('S') + 900
hours = (intTime % 3600) // 24
minutes = (intTime // 3600) % 60
seconds = intTime // 60
endtime = RIGHT(hours,2,'0') || ":" || RIGHT(minutes,2,'0') || ":" || RIGHT(seconds,2,'0')
NOTE!! I don't have access to test this and it's been many years since I've written Rexx or had access. However, I think the basic process would work. That is:-
1) Extract the hours as an integer from the time (catering for the the potential to cross into the next day or days ie the // 24 ()).
2) Extract the minutes, as an integer, from the time, after dropping/subtracting the hours (the remainder of the time divided by hours ie intTime // 3600).
3) Extract the seconds, as an integer, from the time. By obtaining the remaining of diving the time by 60 (will drop hours and minutes).
4) Building the end string as a concatenation of the hours, minutes and seconds. With : as the separator between two values (or surrounding the middle values). The right function to include a leading zero.
You could also try:-
intTime = TIME('S',TIME('S')+900,'S')
That is based upon TIME, which may be Object Rexx. I did also read something mentioning an extended TIME/DATE functionality. However, again that may have been referencing Object Rexx. Although, Mike Colishaw's name was mentioned.
Mike Colishaw, I believe, being the creator of the Rexx programming language.

Calculating Seconds Until a Given Date and Time in Joda Time

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.

How to print Time stamps through out the program in iOS

Some of the operations in my app are taking a lot of time to execute. SO, i am planing to print time stamps from starting of the app execution to end in order to check the time taken for certain operations. Is there any way in order to do that so that i can keep track of all the time stamps in a continuos way...
You can just NSLog(#"Any sensible log message describing your location in the code") - the output in XCode contains the time it was logged, to the millisecond.
You can define a var at the start of the methods you want to analyse:
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
and then print it at the end:
NSLog(#"It took %f seconds in method <methodname>",[NSDate timeIntervalSinceReferenceDate] - start);
good luck!

How to round the minute of a timestamp to increments of 15?

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.