• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about how to write method to find right variable  RSS feed

 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code:

This Method is supposed to print out all Lectures that take place on the date of the datetime object day in parameter.

Now my question is, I have to accomplish this by ignoring years, months and the time (hours and minutes). this means that if I get the day at 00:30 hours, and there is a lecture on the same day but at say 8:15 hours, it has to print out this lecture information because it is on the same day. Only the day is concerned, and it has to print out all lectures that are saved in the TimeTable slots[] array for that day.

My first Idea was to say: Ok if that day Object is greater than any start date and smaller than any end date of the TimeTable objects, then it should work.
But that does not work.
Do you have any other ideas?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DateTime isn't a standard Java class so it is hard to know what methods are available.

Are there any methods to get the date as an integer?
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes there is, to get year, month and day in int. Even time.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post a link to the API for you DateTime class?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Von Valkenburgh wrote:Yes there is, to get year, month and day in int. Even time.

That's great. Forget about code for a minute. Can you write a few sentences describing how you would tell if date/time should count. For example, if I only cared about classes held this year in June, I'd say:
Check the year field is 2015 and the month field is 6. If so, it is a match.
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to compare time intervals (slots) to time intervals (the whole day). Then you shouldn't be using DateTime, because it models an instance of time, and not an interval of time.

It looks like you're using JodaTime. You can probably use the ReadableInterval class and its overlap() method to make this task easier.

You need to be more specific in how days should be compared without the context of years and months. Do they need to be the same day of the month? The same day of the week? You can define the distinction in your time slot class by using two Partials to define a "partial interval" for the time slot.
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think OP has got his own DateTime class. Look here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!