• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

48 hours rule, pls recomment

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alone my assignment 48 hours rule, I implement my method here:



May be somebody can spot the problem? Thanx a lot.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo,

At first I think you should consider renaming your variable currentCalendar to something like lastDate, it is a little bit confusing as it.


According to your code and correct me if I am wrong, you can book a room only if:
Available date < current date + 2

And in another word:
Available date - 2 < current date

But I think this equation is not complete it misses the upper limit and it should be, you book only if:
Available date - 2 < current date < Available date

Not sure if that helps you, I hope so.
[ December 21, 2004: Message edited by: Omar Kalaldeh ]
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Omar:

At first I think you should consider renaming your variable currentCalendar to something like lastDate, it is a little bit confusing as it.



You are right, I'v modified my code.

But I think this equation is not complete it misses the upper limit and it should be, you book only if:
Available date - 2 < current date < Available date



Yes you are right. But I think the assignment only told us the book rule, not told us un-book rule. The condition: current date >= Available date, if this happen, I think the room will be remove from the available list by other program or by this 'delete' operation. So, I don't do this.

What do you think??
Thanx for reply.
 
Omar Kalaldeh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo,


Yes you are right. But I think the assignment only told us the book rule, not told us un-book rule. The condition: current date >= Available date, if this happen, I think the room will be remove from the available list by other program or by this 'delete' operation. So, I don't do this.


I am not sure if I get your point here, what do mean by the un-book rule.

If you are talking about some cleaning program, that will remove all impossible to book records, I think you are right, in real life there must be such program, but in the assignment it is not required from us to write it.
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Omar:

I'm sorry take you confuse. 'un-book' is mistake, I means that 'cann't book rule'. In other words, the assignment haven't told us which room cann't book. So, I think we only implements 'which room can book'.

By above words, if current date >= Available date, I also allow book it, because the assignment don't told us these room cann't book.

And in the read world, these rooms must be remove from the available list, should you display an outdated room to the user??

Thanx for reply.
 
Omar Kalaldeh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo,

In the assignment instructions they told us the following:

They take bookings only within 48 hours of the start of room occupancy




And that’s mean any try to book a room outside this period will be failed, the real question here when is that 48 period they are talking about.


Is it before 48 hour of the field Date available, or is it after 48 hour. Or is there is some another way to understand the 48 rule.

I am my self worked in the first assumption, witch is you can book only in the period fall between: before 48 hour Date available and the Date available.

And about they didn’t define and upper and lower limits, I think the word [B]within[B] must means there is specified period of time defined by upper and lower limits, do you agree with me in that.
[ December 21, 2004: Message edited by: Omar Kalaldeh ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I take it as before "within 48 hours of the start" means , the 2 days before the hotel listing date and thats how I implemented mine.
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Omar:

I agree with 'Is it before 48 hour of the field Date available'.

Now let's see this thread, take me confuse. Bharat Ruparel add 3 days to compare, why this?

Can somebody tell me??
Thanx.
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone clear me?
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think about the 48 hours rule again, at last get this new idea:

Because the date field don't support time, so I think '2004/12/22' equals '2004/12/22 00:00'. So, in order to 48 hours rule, you can do book within '2004/12/20 00:00' and '2004/12/22 00:00'. But, you should allow the customers to book the current day room, so the time scope is modified to '2004/12/20 00:00' and '2004/12/23 00:00'. In other words, date-2 < now < date+1.

So, I modify my code as following:



It's OK? Give me some advice please.
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made the mistake so much, I think I'm confused on time. So I give up the time, and modify my new code.



As you can see, I give up all the time and clear my idea, you can book the room during current date and current date + 2.

What do you think...
:roll:
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone give me some advice??

Where's Andrew, where's Philippe..
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Where's Andrew, where's Philippe..


Andrew might be too busy, as currently is X'mas holiday, be patient to wait for some more time.

About Phil, I am very very sorry to tell you that...
https://coderanch.com/t/2421/Ranch-Office/Memoriam-Philippe-Phil-Maquet

Nick
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Nicholas, I don't know this, this is very very very bad news. He is a good teacher, is good friend, ......

I want cry.....
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Leo Tien:
I made the mistake so much, I think I'm confused on time. So I give up the time, and modify my new code.



As you can see, I give up all the time and clear my idea, you can book the room during current date and current date + 2.

What do you think...
:roll:



This will not work properly over the end of year, try it next week. It is close though. Solutions involving 86400000 will not work properly over the change to and from daylight saving time. This is actually a difficult problem in Java, because its date and time code is quite sophisticated.

What you need to do is convert the date portion of the timestamp into a day number, similar to the astronomers "julian day" or the Microsoft Excel internal day numbers and then subtract the day numbers.

I use the Excel format since its easy to validate the conversion. The conversion is not valid for years before 1582 or after 4000. There are much better versions of this algorithm available that account for the year which the Gregorian calendar was adopted and for the adjustments after the year 4000.


Here's some partially tested code that does this.

 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi peter, thank you for your reply.

I think I don't understand your code fully,

This will not work properly over the end of year, try it next week.



I test my code in 2004/12/31, it can book the room '2004/12/31' and '2005/01/01' and '2005/01/02'. It seems enough.

Solutions involving 86400000 will not work properly over the change to and from daylight saving time.



I don't understand it, because in my country there isn't daylight saving time.

I use the Excel format since its easy to validate the conversion. The conversion is not valid for years before 1582 or after 4000. There are much better versions of this algorithm available that account for the year which the Gregorian calendar was adopted and for the adjustments after the year 4000.



I don't think this so deeply, it's so strange to me.
I think whether you mean I should convert my date to days number. Such as



and then I use days to compare??
I hope I don't waste your time.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I was wrong, your code will work since adding to DATE overflows into the YEAR field. Its the roll method that doesn't overflow. The code that uses 1000*24*60*60 will not work over the switch to daylight saving time, and even if you don't use it they do in California.

Use your Calendar solution, its better since it follows the rule of using JDK facilities where possible. I'm going to adopt a similar solution.

The code I posted is useful if you need to make day numbers that are compatible with either Microsoft or astronomers. Its also useful if you want to calculate the elasped days between 2 dates.

No one is expected to understand it, but here goes. Its based on the fact that years average nearly 365.25 days and centuries average 36524.25 days since the first year of 3 out of four centuries in not a leap year. See The Gregorian Calendar.

The stuff with the .41+30.6*month is a clever trick based on the pattern of month lengths in the year starting on march 1.

If you want it to work past 4000 you need to add a factor for 40 century periods that average 1460969 days.

If you want it to work before 1582 (or 1928 in China and 1752 in the British empire) you need to adjust for the days removed by Pope Gregory to resynch the calendar with the stars, October 5-14 1582 were deleted. This wasn't followed everywhere, in the British empire it happened in 1752 and in China in either 1911 or 1928.

If you want it to work before 1AD you need to account for the fact that there is no year 0.
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Peter, I will do my best to understand your code, but now, I will use my code yet, I'm not obstinacy, because your code is more complex.

In the assignment it said that

A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one,...


I think I'm a junior programmer, but I don't understand your code , so I will use my code and will write some word into choices.txt: "In my idea, I don't think about DST, because the assignment didn't tell me clear and in my country don't use it at all.".

Excuse me my foolish act, because it's what I can do
Thanks Peter again.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Leo Tien:
Thanks Peter, I will do my best to understand your code, but now, I will use my code yet, I'm not obstinacy, because your code is more complex.

In the assignment it said that

I think I'm a junior programmer, but I don't understand your code , so I will use my code and will write some word into choices.txt: "In my idea, I don't think about DST, because the assignment didn't tell me clear and in my country don't use it at all.".

Excuse me my foolish act, because it's what I can do
Thanks Peter again.



That's ok, especially since the approach you are taking leads to a small workable solution. As I said in my previous post, I intend to adopt a similar approach. The solution using GregorianCalendar has no problems with DST, its only those that use milliseconds that have that problem.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo,

Originally posted by Leo Tien:
Can someone give me some advice??

Where's Andrew, where's Philippe..



Sorry, I have been without internet access for the last week (and I only have 56k modem today ).

Phil and I both believed that this 48 hours rule over complicates the assignment. It gives people doing the hotel assignment a level of complexity not present in any of the other assignments.

I strongly recommend you go for a simple solution, then document that you have considered more complex issues (such as daylight savings) and decided that they were beyond scope. That way you should be covered.

From an earlier post of mine, and definately way beyond scope for this assignment:

When I used to live in Sydney, it was technically possible for me to fly to Honolulu on any day. The flight I would catch is QF 003, departing Sydney at 10am on 12 May, and arriving in Honolulu at 23.30 on 11th May.

So therefore, if I was booking the hotel room from my computer in Sydney, I would want to be able to book it for yesterday's date.

Do you really want to try and cater for �48 hours and daylight savings and all the other time and date related issues? It is just far too difficult.



Regards, Andrew
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Leo,

I went for the simplest solution regarding the 48 hours rule. I.e. not enforcing it at all. And I got an automatic failure first, but eventually passed. Several others have also passed without implementing it (although at least one other also first got an automatic failure).
I'll leave it up to you to decide, but if I had to do it all over again, I'd still not implement it.

Regards,
Dies
 
ice is for people that are not already cool. Chill with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic