Solr: Day of week, second of day with timezones - datetime

We require to search by day of week and time of day using SOLR.
That`s why we first convert date to UTC and then create two index fields: UTC second of day and UTC day of week.
We know what timezone user requests, so we are able to shift this required values and create query:
Monday from 4:00 to 6:00 AM in +5 timezone
is converted to search values for UTC:
(Sunday from 23:00 to 24:00) OR Monday (0:00 to 1:00)
Unfortunatelly this query will fail in timezones with daylight saving time, when timezone is shifted +5 is +6.
Is there a way how to query by correct time of day?
Only solution we could think of is add to query also date ranges, which were in summer/winter time:
((Sunday from 23:00 to 24:00) OR Monday (0:00 to 1:00)) AND (30.10.2015 TO 27.3.2016) OR Monday (0:00 to 2:00)) AND (27.3.2015 TO 30.10.2015 ) OR ... OR ... ,
where these ... represents date, when was switched from summer to winter time.
Data may be recorded in any timezone and viewed in any timezone as well

Related

Teradata Conversion of difference between dates in hours

I need to calculate the difference between 2 dates i.e creation date till todays date in hours in teradata.
((Creation_date - Current_Date) HOUR) As Open_Hour
If you just want hours:
select current_timestamp - <your timestamp> hour
If you want to get more granular, you can use hour to minute or hour to second.

Can I define exact weekday in iso8601 datetime to schedule a job?

The date-time that i have now:
"schedule": "R/2017-10-05T17:21:00/PT15M"
for now the job is scheduled for every 15 minutes (in chron), but if i want to perform it three times a day at a certain time and only Monday - Friday?
Is it possible to define in this format?
It's not possible
ISO8601 is designed to define intervals but only static. There is no way to define weekdays or weekends. This means you can only define interval for 3 times a day but not every day from Monday to Friday because then you will have not equal intervals between Friday and Monday.
What you can do is to create 15 jobs scheduled weekly.

Add hours to timestamp in moment.js

I have two inputs first input is for getting the date and the second input is for getting the time of the day.
For example,
User selects date: 20 January 2019 and time: 12:30 pm.
When I convert the date input to Unix timestamp I get the timestamp for 00:00 hours on 20 January 2019.
startingDate = moment(date.startsOn).unix();
So I want to add hours that I'm getting from the user into the date timestamp.
When I try to convert hours into Unix timestamp I get a timestamp for the present day along with the hours entered by the user i.e. I get timestamp for 12:00 pm on 11 January 2019.
startingTime = moment(date.startingTime).unix();
Any suggestion how I can achieve this?
I managed to do this in this way:
As I had my starting date and time in unix format
startingDate = moment(date.startsOn).unix();
startingTime = moment(date.startingTime).unix();
I had to convert them into moment format
const date = moment.unix(this.startingDate).format('YYYY-MM-DD h:mm a');
const hours = moment.unix(this.startingTime).format('HH');
Then I added hours to my date constant
var finalTime = date.add(hours, 'hours');
Then I posted this finalTime to my API.

Determine hours using date and time fields

I have separate date and time fields for an event and the data entry of that event. How do I determine the hours between the event and the data entry?
The time field is a string in standard time which I converted to a military time time field using a formula.
date is written in mm/dd/yyyy format and time is in standard time hh:mm am/pm which I've converted to HH:MM military time.
If an event happened at 12:10 pm on 12/3/2016 but it was entered at 1:25 pm on 12/5/2016, I want to see 49 Hours and 15 Minutes in my final field
DateDiff is just what you need. Something like:
DateDiff("h", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime}))
& " Hours and " &
DateDiff("n", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime})) Mod 60
& " Minutes"
This will retrieve the difference between your two dateTimes twice - Once in hours, once in minutes. Perform Mod 60 on the minutes section to get only the remainder minutes after subtracting 60 minutes for each hour.

How to calculate day of the week from timestamp? (DST)

I am developing code for device where datetime library is not available (note: floats also unavailable), so I have to do math myslef.
My timestamp is seconds from 1 Jan 2000 (in UTC).
In configuration of device I have:
current timezone as number of hours +/- from UTC
dst as number of hours to add
I need to know:
current day of week
current hour
Calculating current hour is pretty easy:
timestamp % 86400 # seconds from midnight
Calculating day of the week (1-monday,7-sunday):
dayofweek = (timestamp - 86400) % (86400*7) / 86400
if dayofweek = 0:
dayofweek = 7
notes:
86400 = seconds in one day
But before calculations I should:
1. add timezone hours
2. add DST hours
The problem is how to calculate if DST hours (for European Summer Time only) should be added or not? I need to do this efficiently beacuse I have very limited computing power and I need to do this as fast as possible :-)
To determine if DST is applied, you need to know day and month as well. In Europe, the change is on last weekend in March/last weekend in October. Would suggest you apply timezone offset without DST, do your calculations to get hour, day of week, day and month, and then if you are in DST, you may need to adjust any or all of these values (depending on the original value of hour, it may just be hour that needs adjusting).
By doing the timezone offset first, you are getting the local hour/day of week/day values correct without DST, then the DST adjustment is trivial.

Resources