Comparing Time Values - delphi

I want a method which compares the times, eg if Atime occurs earlier than Btime do something, I would use a CompareTime Function but my problem with this function is what is said in "Bold Brackets" (see below)
Call CompareTime to compare the two TDateTime values specified by A and B. CompareTime returns:
LessThanValue if A occurs earlier in the day than B (even if A occurs on a later day than B).
GreaterThanValue if A occurs later in the day than B (even if A occurs on an earlier day than B).

A TDateTime values can be thought of as containing two distinct parts: the date part and the time part. The CompareTime function only compares the time part and ignores the date part. The documentation says:
Indicates the relationship between the time portions of two TDateTime
values.
Call CompareTime to compare the two TDateTime values specified by A
and B. CompareTime returns:
LessThanValue if A occurs earlier in the day than B (even if A occurs on a later day than B).
EqualsValue if A occurs at the same time of day as B, ignoring the date portion of the two values.
GreaterThanValue if A occurs later in the day than B (even if A occurs on an earlier day than B).
You want to compare the entire date time value. To do that you should use CompareDateTime. One important note in the documentation for the function states:
Note: CompareDateTime differs from a direct comparison of the corresponding double precision values in that two TDateTime values are
considered the same if they have the same value down to the
millisecond. It is possible to create two TDateTime values that differ
numerically when viewed as doubles, but which represent the same year,
month, day, hour, minute, second, and millisecond.

Related

What is the format of the time field in this cypher?

Heading ##CALL ga.timetree.single({time: 1463659567468, create: true})
https://github.com/graphaware/neo4j-timetree
https://graphaware.com/neo4j/2014/08/20/graphaware-neo4j-timetree.html
The above link says that time is in long format YYYYMMDDHHmmss. But the time parameter doesn't make any sense and random nodes are getting generated in neo4j. enter image description here
What does the time parameter hold and what is the meaning of it?
The time parameter is a millisecond timestamp, or milliseconds elapsed since the UNIX epoch, which is an extremely common means of storing time-related data, you can find this in use in nearly every digital system.
The timestamp cited here represents "2016-05-19 12:06:07". The timetree built starts from a root (this is a modeling convenience), and then its child is the year (2016) followed by the month (5), then the date of the month (19). Looks like it didn't automatically create any nodes for time resolutions beyond that.
Keep in mind that now that Neo4j has native temporal values that you can use in Cypher and store as properties (as well as index), time trees are going to be less useful, as you can always do index lookups on indexed temporal properties.
There are still some cases where time trees can still be very useful, however, such as when you're searching for events that happened within some unit of time that disregards its parent units...such as finding events that happened on Mondays regardless of month, or on Januaries regardless of year, and so forth.

is momentjs incapable of getting time differences between time zones?

i have a date string on NodeJS
2019-02-25T09:00:00Z
I create a moment object, and set the timezone to new york
let a = moment.tz("2019-02-25T09:00:00Z", "America/New_York");
I then create another moment object, with the same time, but set a different place, arizona
let b = moment.tz("2019-02-25T09:00:00Z", "America/Phoenix");
console.log(a.diff(b));
prints out 0 milliseconds. i would expect expect to get 7200000 (2 hour time difference). why am i not getting this difference?
"2019-02-25T09:00:00Z" means "9am on February 25th 2019, UTC". The "Z" part is what indicates that the value is in UTC.
You've created two values representing the same instant in time, but in two different time zones - so they'll have different local values, but they both represent the same instant, so the difference between them is 0.
If you want to create a value which represents "9am on February 25th 2019, in the given time zone" then just remove the Z. (I don't know what Moment does if the value you specify is either ambiguous or skipped due to offset changes in the time zone, but that's something you should investigate if you're going to do this with arbitrary data.)

Check variable of Time within a timeframe

Is there a way to check and see if a time is between a time duration in Crystal Report? Our application has a field, let’s say, called StopTime but stored in integer format. It has the value of 0 at midnight, 60 at 1 am, … , 12x60= 720 at noon.
There is a need for me to create an input parameter with type Time which allows a range value so that user could select to view records within a certain time in the day.
My question is how do I check the value of the field again the input parameter in the record selection formula? I have tried
cast({StopTime}/60 as time) in {?TimeDuration}
but I got the error “There is an error in the formula. Do you want to save it anyway?”
I have also tried
{StopTime}/60 in {?TimeDuration}
and still got the error.
The only way to get around this error is declaring the parameter TimeDuration as Number that accepts a range. However, if possible, it is better to use the type of Time as I can foresee user issues with Number range when a time range is actually needed.
Your field {StopTime} is a number representing a number of minutes, and so must be cast to a time. In Crystal Syntax this is achieved using the CTime function which takes a parameter of a number in days. Therefore you must divide the number of minutes by 1440 to get it in to days. The following will do what you need.
ctime({StopTime}/1440) in {?TimeDuration}

How to handle time-intervals with timezone in iOS/Swift

I am new to this iOS world, trying to learn how to handle dates and time.
Imagine I have a Class Shop. The shop have time-intervals which represent the open and close time for each day of the week.
Some context data (example string from database, GMT Timezone):
Monday: "08:00:00-13:00:00, 15:00:00-18:00:00"
Tuesday:"09:00:00-13:00:00, 15:00:00-19:00:00"
Wednesday: "15:00:00-23:59:59"
Thursday: "00:00:00-08:00:00"
etc..
Monday for example would have to store 2 time-intervals.
My question is how can I store this data (array of DateIntervals? TimeIntervals? or another more suitable class?) in a Class and get the current time to check if the store is opened or not.
The native date format for iOS (and Mac OS) is the Date object. A Date object represents and instant in time, independent of time zone. You then use a DateFormatter to convert a date to a string representation in a particular time zone.
In your case, though, you need to represent timer ranges for days of the week on a variety of different dates.
You should read the Calendar class reference in the Xcode documentation. Of particular interest would be the date(bySetting:value:of:) method, which will let you start from a given date and calculate a new date by changing the value of various date components.
You have a set of time intervals for each day. So you need a way to store, for a given day of the week, one or more time intervals. Your time intervals have a start time and an end time. Each of those needs to be represented by an hour, minute, and optionally second.
With that information you can get the current date/time and split it into components. Get the weekday, hour, minute, and second. Using the weekday you can get the appropriate time intervals. Then you can iterate those intervals and see if the current hour, minute, second falls between one of the intervals.
This all assumes that for a given business, your time intervals (open times) are specified in local time for the given business.
When converting the current date/time into its components, you should ensure that you set the calendar's timezone to match the timezone of the business in question.
There is no need for any date comparisons for any of this. You want to compare hours/minutes/seconds of the current date with the hours/minutes/seconds of the open times.

Get difference of time and output to decimal format

I am trying to get the different between two times, lets say 2:00PM and 12:00AM. So I want to get how many hours are between those two times but have it be in decimal format which in this case would be 10.00 hours?. I am not sure how to go about this. The most I got to was just subtracting the two times and multiplying that decimal number by 24 which works if I do 2PM and 11PM which gives me 9.00hours, but as soon as I go to 2PM and 12AM it should show 10.00hours but shows -14.
Assuming your times are in ColumnA ("earlier") and ColumnB ("later") then:
=if(B1=0,(B1-A1+1)*24,(B1-A1)*24)
should work for you. The quotes are because (seems to depend upon how the times values are entered) Google may associate a date with the times even when that is not displayed. Google treats noon as 12:00PM which is wrong, it is noon not after noon (post meridiem) but one minute later 12:01PM, etc, does make sense. So 12:00AM is midnight and a special case where a date is associated because seen as midnight of the previous day - it counts as 0 not 24. Hence relative to 2pm today is 14 hours earlier (your result) whereas midnight tonight is 10 ahead (the result you expected).
The formula above checks whether the later time is midnight and compensates for that being treated as the day before by +1 in the formula.

Resources