I am developing a calendar application that needs to draw rectangles whose heights and vertical position are based on the start date of the event they represent. I am trying to test the layout system against dates and time zones with daylight saving. Specifically I want to account for the fact that in some regions daylight saving can remove/add an hour to the day.
Currently I'm stumped on how to write unit tests against daylight saving time.
See the NSTimeZone class reference. It has a handy BOOL property called -daylightSavingTime and related friends you may find useful. You can create a date with a specific time zone / date combination to get what you need and feed that instead of the system-provided time.
I'm not sure there's a way to change the system time (even in the simulator) programmatically, however. I haven't attempted anything like this but perhaps a creative use of some preprocessor macros and/or environment variables could let you toggle between test states.
Related
I'm using Optaplanner to automatically solve school timetables. After a timetable has been solved the user will manually change some lessons and will get feedback on how this affects the score via the following call:
scoreManager.updateScore(timetable);
This call takes some 200ms and will, I assume, do a complete evaluation. Im trying to optimize this and want to only pass in a Move object so that Optaplanner only has to recalculate the delta, like:
scoreManager.updateScore(previousTimetable,changeMove);
Is there a way to do this?
There really is no way how to do just a single move. You don't do moves - the solver does moves. You can only make external problem changes to the solution. You should look into the ProblemChange interface and its use in the SolverManager.
However, the problem change will likely reset the entire working solution anyway. And after the external change is done, you're not guaranteed that the solution will still make sense. (What if it breaks hard constraints now?) You simply need to expect and account for the fact that, after users submit their changes, the solver will need to run; possibly even for a prolonged period of time.
FaunaDB's At() function looks so nice! I wonder if I can log a time series of sensor data into one document, and draw a time series chart by At() function and change history of the document.
So, is there any way to get a change history of FaunaDB's documents? Thank you for your suggestion!
Events($ref) will give you the history of a document. The amount of retained history is configurable. The complete docs for Event is found here.
That said I'm not sure I'd choose to implement a sensor time series that way. I'd be more inclined to write a separate document per reading. Mostly because it's easier to work with first class values for time series and if you need to record quickly you won't run into conflicts.
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.
This is my first time I need to create a cutscene system. I have read a lot on the web about different ways to accomplish this task and have mixed them with my own ideas. Now, it is implementation time, but I need some info from other people with more experience than me in this field. Here we go:
1) Some years ago, I implemented a system that actions could be queued in a serial/parallel way, building a tree of actions that when executed created the final result. This can be sure used as the cutscene system director, but, wouldn't it be so much simple to just have a timeline with actions ran at a certain time? An example:
playMp3(0, "Song.mp3)
createObject(0, "Ogre", "Ogre1")
moveObject(1, "Ogre1", Vector3(100,100,1))
This way everything would be really simple to script. Serial actions are supported buy spreading them correctly in time and parallel actions just need to have shared time ranges.
One problem I have seen is that an action like Sync() (This just waits for all actions to finish before start the other that come afterwards) can't be used because we're using absolute time to trigger our actions. Anyway, a solution could be to have our actions layered based on last "sync()". I mean something like this:
playMp3(0, "Song.mp3)
createObject(0, "Ogre", "Ogre1")
moveObject(1, "Ogre1", Vector3(100,100,1))
sync()
moveObject(0,....);
createObject(1,....);
As you may notice, times after sync() starts again from 0, so, when a sync() is ran, and it determines all previous actions from last sync() are finished, timeLine elapsed time would be 0 again. This can be seen as Little cutscene action groups.
2) The previous explanation needs all actions to be added at the beginning of the cutscene playing. Is this how it usually is done? Or do you usually add actions to the timeline as they are needed?
Well, I could be wrong here, but I think this could be a nice & simple way to lay the actions for a cutscene. What do you think?.
Thanks in advance.
I've done a few of these systems. I'll tell you what I like to use I hope this will answer your questions.
One of the first cutscenes system I did used LISP dialect because it is just couple of hours work to get a parser working. It used to be something like...
(play "song1.mp3")
(set "ogre1" (create "ogre"))
(moveTo "ogre1" '(100, 100, 100))
(wait 1)
I created something like virtual machine (VM) that was processing my scripts. The VM didn't use separate thread instead it had update function that was executing X amount of instructions or until it hits some synchronization instruction like wait for 1 sec.
At that time this system had to work on J2ME device which didn't have XML parser and XML parser was too much code to add. These days I'm using XML for everything except sounds and textures.
These days I'm using keyframe systems as BRPocock suggested. The problem is that this will be harder to manage without proper tools. If you using already some 3D software for your models I'll suggest you to investigate the option to use that product. I use Blender for cutscenes for personal projects since it's free at my work place we use Maya and 3ds Max, but the idea is the same. I export to COLLADA and then I have my animation tracks with keyframes. The problem is that COLLADA format is not the simplest it is made to be flexible and require decent amount of work to extract what you need from it.
The problem you will have with your format is to describe the interpolation so you want to move the ogre from one position to another... how long is this going to take? The advantage of keyframe system is that you can specify the position of the ogre in time... but scripting for such system without a tool will be difficult. Still here is a simple suggestion for format:
(play 'song1.mp3')
(entity 'ogre'
(position (
0 (100 100 100)
2 (100 200 100)
5 (100 300 100)
7 (100 300 400)
8 (100 300 500))
(mood (
0 'happy'
7 'angry'))
(... more tracks for that entity if you need ...))
(entity 'human'
(position (.....)))
Now with format like this you can see at what time where the ogre has to be. So if you have time 1.5 sec in the cutscene you can interpolate between the keyframes with time 0 and 2 sec. Where mood can be something you don't interpolate just swich when the right tome comes. I think this format is going to be more flexible and will solve your sync issues but I wouldn't suggest you writing it by hand without tools for big scripts. If your cutscenes are going to be just few sec with a few entities then it may be good for your.
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.