How to add Hour with sysdate in business hour in Oracle? - oracle11g

Need to adding in business hours between 9 to 6 ( mean 8 hours daily and exclude Saturday and Sunday; ), now i want to add 40 hours with sysdate date.Need to display finish time,
Suppose i will assign a task on Friday 2nd of May 2014 ,10:30 AM then finish time
should be Friday 8th of May 2014 ,10:30 AM

Related

More complex schedule. Is there an easier way in windows task scheduler?

I want to run an app via task scheduler in following schedule:
Sunday-Thursday every 30 minutes.
Friday every 30 minutes but only until 10:30 pm
Saturday every 30 minutes starting at 11:00 am.
So it should literally just not run every 30 minutes during a maintenance window of another tool which is from Friday 11pm to Saturday 11 am.
My actual approach would require a lot of triggers.
1 weekly trigger for all the full running days (Sun-Thu: Repeat every 30 minutes for 1 day)
1 weekly trigger for every Friday starting at 12am, repeat every 30 minutes for 12 hrs
10 weekly triggers for every Friday starting 1pm, 2pm, 3pm etc, repeat every 30 minutes for 1 hr)
1 weekly trigger for every Saturday starting 11am, repeat every 30 minutes for 12 hrs
1 weekly trigger for every Saturday starting 11:30pm.
And the similar thing for Saturday.
Is there any easier ways to schedule this? I was under the assumption that there is a "stop after x recurrences" option. But could not find it.

extract 2 days of previous data and exclude weekends in pl/sql

Looking assistance in PL/SQL query.
Business Case:
Extract 2 previous business days of data from DATE column excluding weekends.
(Business Days - Monday to Friday)
End users are going to provide only 1 date to extract data.
Example:
If Effective_date is on Monday, then need previous 2 working days data of Thursday and Friday.
If Effective_date is on Tuesday, then need previous 2 working days data of Friday and Monday.
If Effective_date is on Wednesday, then need previous 2 working days data of Monday and Tuesday. and so on.....

Cloud Firestore: query for an item's availability given a timestamp

Imagine an Airbnb like app. A rentals collection contains documents with fields start and end of type timestamp that records the start date and end date of the rental (year, month and day only). Inside my Flutter app, when a user wants to make a new rental request, I need to check if the request interferes with any existing rentals. Would it be too much to store an array of Timestamp objects that contain the amount of days, then use arrayContains to query/check?
For example:
rental #1
start: Jan 1
end: Jan 2
days: [Jan 1, Jan 2]
rental #2
start: Jan 6
end: Jan 10
days: [Jan 6, Jan 7, Jan 8, Jan 9, Jan 10]
Suppose the user wants to book a rental for Jan 3-4. I would run a loop and query for documents with arrayContains: Jan 3 and arrayContains: Jan 4 and if it returns any documents, then I know the rental request date is invalid. The maximum amount of days a user can rent is 27 days, although I expect the average rental duration to last under 7 days. Is my method viable? I could change the maximum rental duration from 27 to 14 possibly.
The other method I came up with is to query for the rentals immediately before and after the desired pickup time. So using the above example, if my desired rental date is Jan 3-4, I would query for the closest rental that ends before Jan 3 and the closest rental that starts after Jan 4. However, the issue I'm running into is what if the user in rental #1 decides to extend their rental from Jan 1-2 to Jan 1-3 (before our user is able to refresh their app)? Or if a particular listing has no rental history associated with it.

Scheduling events with changing Time zone

I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else

Representing an entire day or week or month as a number like timestamp

How can a day or week or month, essentially a range of time be represented by a single number?
The next interval would represent a number 1 more than the number for the previous interval, just how the next second is 1 more than the previous second, in timestamp representation.
Given a bunch of such numbers, the larger number simply means its representing a time interval afterwards in time, when compared to a number smaller than it.
Just realized if I stick to UTC and represent the day as YYYYMMDD, this becomes a number that I am looking for.
20180420 // 20 april 2018
20180421 // 21 april 2018
20180510 // 10 may 2018
20190101 // 1 jan 2019
This works for representing a day perfectly, I think.
For week, maybe do ceil() of days of current month divided by 7 for representing week as a number W and then using the format: YYYYMMW.
2018043 // 3rd week of april 2018
2018045 // 5th week of april 2018, though may not be the 5th week semantically but representation model works, greater than 4th week of april 2018 and smaller number than 1st week of may 2018
For month, simply YYYYMM works.
I feel so smart right now! 😄

Resources