1

I have the following problem. I have a quartz job that runs every 5 minutes and makes a web service call retrieving a large object. The purpose of this application is that it will loop through a List in the object and capture counts from a number of categories.

One specific requirement is that each category be assigned an arbitrary window, say 9am-12pm. If we are in that window the counts get added to a rolling count continued from previous jobs, if not it is ignored.

The questions. I am loading the configurable start time(in the format 9:00am EST) and an int duration(in minutes i.e. 180) from a .properties file.

The question is what is the best way to handle this. Right now I just convert the configurable start time to long when my business class is instantiated. I use Calendar to calculate the long value of the end time. Since these are both in 1970 time, When I want to find out if now is between those two times it requires some nastiness on my part. I take the current new Date() format it, strip out the year, use the Formatter again to parse() a date in 1970 then I can do a simple long comparison with my start and end time.

I know there has to be a less ugly way to approach this. Any thoughts?

asgs
  • 3,928
  • 6
  • 39
  • 54
nsfyn55
  • 14,875
  • 8
  • 50
  • 77
  • possible duplicate of [What is the Best Practice for manipulating and storing dates in Java?](http://stackoverflow.com/questions/2168374/what-is-the-best-practice-for-manipulating-and-storing-dates-in-java) – Basil Bourque Oct 29 '14 at 07:07

1 Answers1

7

You might want to look at Joda time (http://joda-time.sourceforge.net/), which contains a more sane API to deal with time.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140