Rexx: increment current time value - rexx

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.

Related

Calculate the time difference

I am trying to calculate time difference between 2 ZonedTime dates in Scala. I am receiving dates in "2021-03-19T15:39:42.834248-07:00" format as a String. I need the difference in seconds between 2 dates in Scala. How to convert the string to zoned time and calculate the difference?
You'll want to use the between() method as offered on a temporal.ChronoUnit.
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit.SECONDS
val start = ZonedDateTime.parse("2021-03-19T15:39:42.834248-07:00")
val stop = ZonedDateTime.parse("2021-03-19T15:49:42.834248-08:00")
val secsBetween:Long = SECONDS.between(start, stop) // 4200
An alternative is to use the until() method on the ZonedDateTime instance itself.
val secsBetween:Long = start.until(stop, SECONDS) //same result
[Java syntax, not Scala.]
tl;dr
Duration
.between
(
OffsetDateTime.parse( "2021-03-19T15:39:42.834248-07:00" ) ,
OffsetDateTime.parse( "2021-03-19T15:49:42.834248-08:00" )
)
.toString()
See this code run live at IdeOne.com.
PT1H10M
…which in standard ISO 8601 format means 1 hour and 10 minutes.
Details
The Answer by jwvh is close, but I would change a couple things.
OffsetDateTime, not ZonedDateTime
Your input strings have only a mere offset-from-UTC but no time zone. So parse those as OffsetDateTime.
An offset is simply a number of hours-minutes-seconds ahead or behind the baseline of UTC, the line drawn through Royal Observatory, Greenwich. An example of an offset is -07:00 which means seven hours behind UTC.
A time zone is much more. A time zone is history of the past, present, and future changes to the offset used by the people of a particular region. A time zone has a name in format of Continent/Region. Given our example above, on some dates, several time zones may share the offset of -07:00, including America/Dawson, America/Los_Angeles, America/Phoenix, America/Boise, and more.
OffsetDateTime odt = OffsetDateTime.parse( "2021-03-19T15:39:42.834248-07:00" ) ;
Duration
Represent a span-of-time using Duration, on the scale of hours-minutes-seconds-nanos.
Duration d = Duration.between( sooner , later ) ;
Generate text in standard ISO 8601 format.
String output = d.toString() ;

Is there a class in JDK to represent an hour of the day, but not necessarily a specific hour at a specific date?

Is there a class in JDK or Guava to represent an hour of the day, but not necessarily a specific hour at a specific date?
If not, why?
In JDK 1.3-1.7, the answer is no. A specific time within a day is much easier to calculate then date, because you don't have to deal with leap year, leap month, such headache stuff. A simple integer is just enough. When you need to convert the time to a locale string, using SimpleDateFormatter or whatever, you can simply convert the time to a Date, just ignore the date part:
int time = 8 * 60 + 34; // 8:34 am
Date date = new Date(60000L * time);
Reset the time zone to +0, and pass the date to the formatter:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
sdf.format(date);
You could simply wrap a byte into a class and every time that the current hour passes 23 within your increment() (or appropriate name) method, set the value of the byte to 0, and whenever the value passes below 0 in your decrement() (or appropriate name) method, set the value of the byte to 23.
As far as I know, there is not a specific class representing Hour (in the JDK or Guava), but there are easy to use classes to fetch the hours from a specific instance of time (which is what I am assuming you are after with this question).
You could use JODA-Time, as Paŭlo Ebermann mentions, but that is an external library. Within the JDK, there is a class called Calendar, which has many useful methods.
To get the hour of a long representing the current time, you could do this:
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
int hour = c.get(Calendar.HOUR); //returns 0-11
int hourOfDay = c.get(Calendar.HOUR_OF_DAY); //returns 0-23

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.

swfupload get timer left

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.

ASP: convert milliseconds to date

I need to convert a field with milliseconds created by PHP app to a date value. Is there a way to do this using VBScript? or convert to datetime in SQL 2005?
Example: 1113192000 to mm/dd/yyyy hh:mm:ss
Something like the following should work:
Function ConvertPhpToDate(numSeconds)
Dim dEpoch
dEpoch = DateSerial(1970,1,1)
ConvertPhpToDate = DateAdd("s",numSeconds,dEpoch)
End Function
Note, the php time() function returns the number of 'seconds', not milliseconds. http://php.net/manual/en/function.time.php
I think what you are referring to as milliseconds is really the epoch time as returned by the php's time/date functions. You can give this a function a shot to get the epoch time converted to datetime format in ASP:
function epoch2date(myEpoch)
epoch2date = DateAdd("s", myEpoch, "01/01/1970 00:00:00")
end function
Source: http://www.epochconverter.com/epoch/functions.php#asp
msValue = 32312312
dtValue = DateAdd("s", msValue/1000, CDate("1970-01-01 00:00:00"))
Wrap it in a function:
Function TimestampToDate(timestamp)
TimestampToDate = DateAdd("s", timestamp/1000, CDate("1970-01-01 00:00:00"))
End Function
You'll need to have a base time to count the milliseconds from e.g. 1st Jan 1970 or similar.
You then divide the number of milliseconds by 1000 to get the number of seconds - saving the remainder.
Divide the number of seconds by 60 (saving the remainder) to get the number of minutes.
Then 60 again for hours, 24 for days.
Then it get's difficult as you've got leap years to consider. There is another question on this here.
Once you've got your years, days, hours, minutes, seconds and milliseconds you add this to the base date-time to get the date-time represented.
Others have posted code etc. that you might use.