• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Why is there no LocalTime#isEquals method?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

Does anyone know why there is no `LocalTime#isEquals` method, similar to that for LocalDate and LocalDateTime classes? I've googled a bit but can't find a reason why...

Thanks!
 
Saloon Keeper
Posts: 14309
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Different dates from different calendar systems may still point to the same actual day. For instance, January 29th 2020 in the Gregorian calendar refers to the same day as January 16th in the Julian calendar.

The LocalDate.isEqual() method checks to see if two dates refer to the same day, regardless of the calendar. LocalDate.equals() will only return true if the date that you compare it with is also a LocalDate, and not, for instance, a JapaneseDate or a ThaiBuddhistDate.

LocalTime doesn't need an isEqual() method, because all calendar systems are assumed to use the same time-of-day representation, namely the 24 hour clock.
 
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John -

I'm not an expert but here's what I found:


"The equals() method of a LocalTime class is used to compare this LocalTime object to the LocalTime passed as parameter and returns true when objects are equal else false. The comparison between both LocalTimes is based on timeline position of the local times within a day. The value to be returned by this method is determined as follows:

if both LocalTimes are equal, then true is returned
if both instances are not equal, then false is returned"

https://www.geeksforgeeks.org/localtime-equals-method-in-java-with-examples/

I was unable to locate "isEquals" but "equals" appears to do the comparison that you might be seeking?
 
John Xoop
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 Hey, thanks for the responses. We all know date and time management can be tricky! ;)

 @Stephan, I don't still get all the thing... So my understanding is:
 
  • Object equality: you use `LocalDate#equals(Object other)` to check that both objects holds the same representation, therefore a `localDate1` object will only equal another `localDate2`object with the same representation. Therefore an object with another representation (for example a Japanese date) won't be equal here even if both hold the same chronological date.

  •  
  • Chronological equality: you use `LocalDate#isEqual(ChronoLocalDate other)` to check that both objects holds the same chronological date regardless of the representation. Therefore two objects holding the LocalDate and the JapaneseDate for the day when mankind first stepped on the Moon will be equal here.


  •  Do you agree? Thanks!

     PS: by the way this would explain that `LocalTime` does not need the `isEqual()` method, since it works the same independently of the calendar...
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 14309
    321
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You've got it.
     
    I'm gonna teach you a lesson! Start by looking at this tiny ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic