views:

55

answers:

2

Horribly worded question...I know.

I'm working on an application that processes data for the previous day. The problem is that I know the customer is going to eventually ask to it for every hour or some other arbitrary time interval. I know that languages such as Java or SQL have masks for defining dates. Well what about a way to define a time interval?

Let me ask it this way. If someone asked you to create a configurable piece of software how would you allow the user to specify the time intervals?

UPDATE

What I'm looking for is a textual representation. Imagine somethign that would be put into a config file.

+1  A: 

I'm not sure if I understand your question correctly. Are you asking for a way to input time intervals?

I don't know your environment, but most language frameworks offer some more or less sophisticated GUI components. Something like a calendar control may be what you are looking for?

Edit: Ah, command line (or config file) it is.

  • Can you parse an XML file? In this case, you could just serialize a timespan (most languages have a class like this). The use may edit the XML file, typically just replacing, say, the value of the <minutes> part. Deserializing this XML file to obtain a Timespan again is easy.

  • If you prefer plaintext or command line input, it is a bit less easy. However, many languages support some kind of Timespan.Parse (string text, string format). You should have a look if this concept is present in your environment.

  • Many environment offer some kind of sscanf(), that parses an input string. Sometimes there is a "time" format as well.

  • If the earlier ideas don't provide a solution, you can try to parse the date using regex. There should be many resources on this topic on this site as well as the web.

  • If you dislike regex, split the input string according to your own format rules. That's kind of an ugly solution though.

  • If you don't feel like splitting user input stringy by hand, use Random.NextInt(1000) and hope nobody notices. 0:-)

mafutrct
Good point...I wasn't all that clear. I'm looking for some textual means of defining intervals. Something that can then be parsed and interpreted as defining an interval.
gshauger
@Downvoter: I'd really like to know why this post was not helpful. Just drop me a note and I'll see if I can improve it.
mafutrct
It wasn't helpful because at no point did it suggest a text based method for configuring a scheduler. The post that I designated as having answered the question pointed me in the direction of Cron expressions which is EXACTLY in line with what I need. In fact I ended up using cron expressions with a slight tweak in my final implementation.
gshauger
I see. I don't agree, but thanks anyway.
mafutrct
You don't agree? Which solution did you post that would have worked for my problem?Granted I said in my original post that my question was poorly worded. I'm not saying you're ideas are bad just not applicable to my problem.
gshauger
I still don't get it, if they are targeted at your question and are not bad then why -1? :'( But alright, it's your decision, not going to whine any longer.
mafutrct
+1  A: 

Here's how Google App Engine's cron API is configured, it's a bit more user-friendly than cron:

http://code.google.com/appengine/docs/python/config/cron.html#The_Schedule_Format

Python (and Java?) source to implement it should be available in the SDK. Haven't looked to see how easy it would be to extract, but it should at least provide some ideas.

I think it'd be possible to add various things to the format as required - it's structured enough to be extensible. For example it's currently missing the ability to say "every hour at 4 minutes past", which is common in UNIX cron but not really relevant to GAE because although perhaps the engine could figure out which minutes are busy and which aren't, and balance load, the user certainly can't.

Obviously the major weakness of offering something that looks like natural language to the average user, is that they'll think your code is psychic, and expect it to also understand things like "every other Wednesday except the week after Easter", or "whenever the clocks change" ;-)

Steve Jessop