I have a display on my intranet page that shows the hours of operation of each department. The problem is that the departments and users are spread out across Canada. I want to be able to display the HoO for each department based on the users' computer time, in a div tag. So as an example:
Billing 08:00 to 17:00 eastern.
Customer service 07:00 to 16:00 mountain.
Technical support 09:00 to 20:00 pacific.
If a user from Calgary (mountain) goes to the page they will see:
Billing 06:00 to 15:00
Customer service 07:00 to 16:00
Technical service 10:00 to 21:00
but if a user from Vancouver opens the page they will see the hours based on their computer's timezone setting.
Also, I want to be able to put another div next to each department that changes between "open" and "closed" based on those hours.
I've searched for this example but so far I can only find a script to display open/closed based on set hours. Meaning, if the computer timezone is that hour then it shows open, whether the HoO is actually for that region.
I appreciate any information on this.
Chester
Sorry folks, as Matt mentioned I forgot to put in the code I was using, but I think I figured it out. I realized I should be using the getTimezoneoffset() to determine the user's PC time zone, then add some if statements to display the hours. Here is the code I used, I'm sure there's a cleaner way to write this out, I don't mind your feedback:
var d new Date();
if (d.getDay() > 0 && d.getDay() < 6) { // Check if Monday to Friday
var openHour = 5;
var closeHour = 17;
}
var timezone = (d.getTimezoneoffset() / 60 - 6)*(-1), //Turn time zone into an integer to add it to display time
ohours = d.getHours(d.setHours(openHour + timezone)).toString().length == 1 ? '0'+d.getHours() : d.getHours(),
chours = d.getHours(d.setHours(closeHour + timezone)).toString().length == 1 ? '0'+d.getHours() : d.getHours(),
oampm = d.getHours(d.setHours(openHour + timezone)) >= 12 ? 'pm' : 'am',
campm = d.getHours(d.setHours(openHour + timezone)) >= 12 ? 'pm' : 'am';
var display = "Currently Closed";
if (!(isNaN(openHour)) && !(ht < openHour || ht > closeHour)) { //If openHour is empty or between openHour and closeHour
display = 'Open today from '+ohours+':00 '+oampm+' to '+chours+':00 '+campm;
}
document.getElementById("dayWeek").innerHTML = days[(new Date).getDay()];
document.getElementById("para1").innerHTML = display;
Then I used div id to display the two elements:
<h1><span id="dayWeek"></span> Hours</h1>
<div id="para1"></div>
The output looks like this (based on the current day and time) since it's Sunday it's closed:
Sunday HoursCurrently Closed
Related
App Overview
I'm building an iOS app in Swift that shows a list of events. The data that I have for the events shows the name of the event, the start date (day, month, year), and the end date (day, month, year).
When the data is pulled from Firebase, I look at the start and end months and show the event for the appropriate month in a table view. The data is shown by month, so a user looking at May only sees May events and has to choose a different month to see events from that month.
Problem
Some events stretch for several months. For example, if an event begins in July and ends in September, my current implementation won't show the events during August.
Possible Solutions
I'm looking for an elegant way to programmatically check for this case and make sure it's shown in the correct month rather than manually manipulating the data to state the months in between.
If you have any suggestions, please let me know. Here is the solution that I'm considering:
Add a Bool data point saying if the event stretches several months or not. When events for a specific month are shown, check through all of these events to see if the month selected is greater than the start month of the event and less than the end month of the event.
This breaks down if the event stretches from one year into the next. I would need to add additional logic to handle that.
It sounds like you are simply comparing the displayed month to the event's start month and the event's end month.
Without any specifics your basic logic to determine whether to show an event in a displayed month is to see if the displayed month is greater to or equal to the event start month and less than or equal to the even end month.
In pseudo code that would essentially be:
if displayMonth >= event.startMonth && displayMonth <= event.endMonth {
// show event
}
Of course this needs to account for the year as well.
In addition to check month you also need to check year. For example:
// Check start date
if (displayYear == event.startYear && displayMonth >= event.startMonth) || displayYear > event.startYear {
// Check end date
if (displayYear == event.endYear && displayMonth <= event.endMonth) || displayYear < event.endYear {
// show event
}
}
Let me know if you need more information or description of this code
comparing dates will work for you.
compare current date with starting date and ending date.
current date should be greater than starting date and less than ending date.
Here is code snippests for Date comparision
if currentDate.compare(startingDate) == .OrderedAscending && currentDate.compare(endingDate) == . OrderedDescending {
//Here will your event code will come.
}
I am trying to get week number(1,2,3,4,5) with in the month from Jquery UI datepicker. I googled and get the code of iso8601Week but not normal week number.
Kindly Help
This should give you close to what you want, although I've only smoke tested it and there are probably some more edge conditions that need to be addressed.
I basically took the iso8601Week of the first day of the month, and subtracted it from that of the selected date. That works as is for most dates, but ISO 8601 puts days before Jan 4th in the previous year if they fall before Thursday. That's the reason for the % 52.
The code assumes an input called testDate and a label called label1:
$('#testDate').datepicker({
onSelect: function(dateText, inst) {
var d = new Date(dateText);
var d1 = new Date(d.getFullYear(), d.getMonth(), 1)
var x = $.datepicker.iso8601Week(d) % 52;
var y = $.datepicker.iso8601Week(d1) % 52;
$('#label1').text(x-y+1);
}
});
I left in all the variables with partial results in them so you could tinker around with the values. This code assumes that the week begins on Monday (which is the ISO 8601 standard), and that partial weeks before Monday are week 1. So, if the month begins on a Monday, the first Monday is in week 1, and if the month begins on any other day, the first Monday is in week 2. Which looks a bit strange if the 2nd of the month is on Monday and also in week 2, but if you don't like that, you'll have to spend some time deciding in detail what you do like.
I am working on Rails application where I am trying to fetch date of particular week but week start from not 1 January of year but some fixed date.
Like, my week start from 8 july 2016 (08-07-2016) so now i want to fetch start date and end date of any week.
Means week 1 start date -> 08-07-2016 and end date -> 14-07-2016.
Now i want to fetch any week start date and end date but how? I already tried but got solution of year start date not like this.
Any one have idea?
Thanks in advance.
Ok friends,
I found my answer below
week = 3
number = (week-1) * 7
start_date = Date.new(2016, 7, 8) +number.to_i
d = start_date.to_s.split('-')
end_date = Date.new(d[0].to_i, d[1].to_i, d[2].to_i) + 6
end_date = end_date.strftime("%Y-%m-%d")
Let me know if any one have confusion in this answer.
There is no need to split the start date and create a new date object.
start_date_of_first_week = Date.new(2016, 7, 8)
week_number = 3
start_date = start_date_of_first_week + ( (week_number - 1) * 7 )
end_date = start_date + 6
I have a list of time slots with a 15 minute interval.
Each slot can have a activity bound to it that makes the slot "reserved".
What is the best way to return the slots in groups of 30 minutes.
So basically, how can I go from this:
10:00
10:15 = this is a reserved slot
10:30
To this:
10:00
10:30
This whole slot is then reserved because it contains the reserved 10:15 slot.
Without changing the slot size itself.
Is this possible to do within the linq query itself or do I have to return the collection of 15 minute slots and apply the 30 minute logic afterwards?
Please point me in the right direction, thanks!
The slots are object with these properties and types:
TimeslotId (int)
SlotStart (DateTime)
ActivityId (int)
UPDATE:
Ok, I tried to group the slots with this query.
var groups = service.TestGrouping().GroupBy(x =>
{
var stamp = x.SlotStart;
stamp = stamp.AddMinutes(-(stamp.Minute % 30));
stamp = stamp.AddMilliseconds(-stamp.Millisecond - 1000 * stamp.Second);
return stamp;
}).Select(g => new Sample() { GroupTime = g.Key, GroupedSlots = g.ToList() }).ToList();
Which takes me a little closer. Now I get the slots aggregated to closest 30 minute, like 8:00-8:30, 8:30-9:00.
However, this does not work for slots that is within quarter to / quarter past. I need some logic to catch all possible half hours:
8:00-8:30, 8:15-8:45, 8:30-9:00, 8:45-9:15.
How would the logic look like?
Im trying to add constraints to a user submitted text field, which is there Date of Birth. I need the user to be at least 18 but cant be over 113 years old.
final static Date MIN_DATE = new Date(Calendar.YEAR-18)
final static Date MAX_DATE = new Date(Calendar.YEAR-100)
static constraints = {
dob(nullabe: false, min: MIN_DATE, max: MAX_DATE
}
When I,
System.out.println('Year Max Date: ' + person.MAX_DATE)
it gives me,
Year Max Date: Wed Dec 31 17:59:59 CST 1969
and so does the min date.
I tried doing
final static Date MIN_DATE = new Date().getAt(Calendar.YEAR)-18
but that didn't work at all. I also tried doing it without the -18 and got the correct answer but it was 7 hours off. When I tried to relaunch the app from local it crashed it. And I cant recreate it ever since.
I have come to the understanding that the date its giving is the "Epoch" date or the date right before Unix was launched. Im just not sure how to get around it.
Any ideas/suggestions/concerns/experience with this problem?
Any Help would be greatly appreciated.
I don't agree with these constraints, firstly as they seem arbitrary (why should someone not be older than 100? And why can't I just lie if I am 16?)
And secondly, if the webserver is up for a couple of years, these static dates will slowly drift
But anyway (these concerns aside), I believe what you want is:
final static Date MIN_DATE = Calendar.instance.with { add( YEAR, -18 ) ; it }.time
final static Date MAX_DATE = Calendar.instance.with { add( YEAR, -100 ) ; it }.time
The issue is that Date constructor expects an argument representing milliseconds since January 1, 1970, 00:00:00 GMT. Since Calendar.YEAR is a constant that is used to represent the year field from a Calendar structure and equal to 1 you are getting the above values.
You need to convert the user submitted text field (a String) to a Date object with SimpleDateFormat. Then create a Calendar with the Date object and check the Year field.
Alternatively you can just parse the text field (String) yourself and pick the year, convert to int and do the check.