I am trying to create an interactive table which can display work shifts for a given week. I wanted the table to look something like this.
I've managed to recreate something like this using VB.net, however I have done it in (what I consider to be) a ridiculous way. I have used a TableLayoutPanel with a column for each day and a row for each hour of the day. This works, looks okay, and also allows editing of shifts. (I.e, you click in a cell to turn it green and add it to a shift).
The problems with this solution are (a) there is no easy way to represent half hours, or quarter hour segments easily and (b) the fact that each cell contains a blank label which then gets coloured in, the form takes a long time (~ 6 seconds) to load, which seems unnecessary to me. What would be a better way to implement something similar to this? Preferably without using the VB reporting, since I can't seem to get that to work, though that's a separate issue.
Thanks.
An NSDate object represents an absolute date and time, e.g. September 4, 2012, 10:00PM CDT. While this works fine when an event did indeed happen at a certain moment in time, it's much more of a hassle to work with NSDate when you're dealing with something that's a recurring event. For example, I'm currently working on an app that stores the hours of operation of businesses. Most businesses have a weekly schedule, which means that I would like to store the times per weekday, regardless of the date.
There are several solutions: create an extra entity (I'm working with Core Data), Hours, with attributes weekday, hour, and minute and figure it out that way. This could work for simple displaying, but I'm also going to add a "status" (such as "open until x", "closing in y minutes", or "will open at z"). This means I'll either have to create NSDate objects to do the comparing, or I take the weekday, hour, and minute properties of the current NSDate.
Another option would be to store two NSDates per business (open and close), and ignore the actual date and only use the weekday, hour, and minute properties. I've tried this, but to be able to compare dates, I'd still have to manipulate NSDate objects.
These are the solutions I've come up with. Both require a lot of math and involve a bunch of ifs, buts, and maybes. It would be really easy to simply have some sort of "NSTime" object with which I can do everything, but that doesn't (seem to) exist.
Has anyone else had the same problems and found a better solution?
I think you're better off creating your own abstractions. That will better fit with the problem you're trying to solve. Some pointers for help:
Fowler's recurring events for calendars (pdf) patterns.
ice_cube: A ruby library for recurring events (for the design idea).
It would be really easy to simply have some sort of "NSTime" object
with which I can do everything, but that doesn't (seem to) exist.
One option is to use NSDateComponents, in which you can store just the parts of a date that you're interested in, like hours, minutes, and seconds.
Since you really just want to store a time of day, another option is to create your own Time class. NSDate stores moments in time as a single number: the number of seconds since a fixed time, the epoch. Your Time class could do nearly the same thing, except that it would use midnight as the reference point. You may run into problems, though, if you're not able to indicate times beyond the end of the day. For example, if a restaurant stays open until 2am, you might want to be able to represent that relative to the day when the restaurant opened. Perhaps a better option is to have your Time class use NSDate internally, but always with a fixed starting date.
I just HATE the UIDate and Time Picker that Apple supplies. Do you know of any other library that creates an equivalent UI element for picking time and date, that can be better customized at least? I'd hate to rediscover the weel.
Thanks!
Just for any others wondering about my conclusions...
I think it would look better to use a calendar to pick the date and keep a picker for the time so far.
For calendar there is a good implementation here:
https://github.com/klazuka/Kal
is there a way to "force" dojo to show date and time in DateTextBox and TimeTextBox widgets in UTC independently of the SO configuration?
Thanks.
It's a lot more than you want, but you could try requiring dojox.date.timezone and overriding the format to use a particular timezone (not sure offhand whether you could pass in a particular parameter through the widgets or if you'd have to do some monkey patching) That's the more general solution, but I don't know if it's been tested. The timezone code is still experimental.
You could probably fake something also by monkeypatching the method that does the display in the widget to subtract the offset from the time, but that wouldn't be "safe" for daylight savings, etc. , otherwise I think you'd need to go put conditionals in to use UTC accessors in the dojo.date code.
I've been trying my best to find some code examples on how to disable the datetimepicker dates in the future and also all the weekend dates but i am unable to find any! Only thing i can find is ASP.net code.
If anyone knows how to do this in VB then please do share! :o)
Thanks,
David
Set the DateTimePicker.MaxDate property. You'll have to reject weekend days by validating the user's selection. Use the DateTime.DayOfWeek property.