开发者

Is there a way to formerly define a time interval for configuring a process?

开发者 https://www.devze.com 2022-12-24 22:35 出处:网络
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 s

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开发者_StackOverflow中文版 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.


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" ;-)


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:-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号