Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:01:30+00:00 2026-06-09T00:01:30+00:00

Using JodaTime library (although I am a bit flexible). I realized some of the

  • 0

Using JodaTime library (although I am a bit flexible). I realized some of the inputs coming in are breaking Joda time because the days of the month are above 31 or below 1 (because of client-side code).

I am using the LocalDate object for calendar manipulation. Is there a library or method to easily sanitize the dates so the input doesn’t start throwing exceptions?

Some Scala code I am using now: EDIT: Fixed code

 val now = new LocalDate();
 val workingDate = now.withYear(y).withMonthOfYear(m).withDayOfMonth(d).withDayOfWeek(DateTimeConstants.SUNDAY)

 ymdStart = toTimestampAtStart( workingDate )

For clarification, the goal here is to convert the date to a proper date, so if a user submitted July 38, it would convert to August 7. There’s an incoming URL structure causing a lot of this and it looks like /timeline/2012/07/30.

For reasons of pure exercise (I agree normalization seems to be bad practice) I’m now just purely curious if there are libraries that deal with such a problem.

Thanks!

Final Update:

Like the answer points out, normalization was a poor idea. I did a lot of re-factoring on the client side to fix the incoming variables. This is the code I ended up using:

ymdStart = new Timestamp( toTimestampAtStart( new LocalDate(y,m,d).withDayOfWeek(1) ).getTime - 86400000 )
ymdEnd = new Timestamp( ymdStart.getTime + 691200000 )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:01:32+00:00Added an answer on June 9, 2026 at 12:01 am

    First of all, a LocalDate is immutable, so each chained with...() is creating a new date.

    Second, it is a well-known antipattern to update pieces of a date one at a time. The end result will depend on the current value of the date, the order in which you update the pieces, and whether or not the implementation “normalizes” dates.

    In other words NEVER update a date/time piecemeal.

    Assume for a minute that the implementation “normalizes” (i.e. corrects for overflow) invalid dates. Given your code, if today’s date was 31-Jan-2011 and you did

    now.setMonth(FEBRUARY);
    now.setDayOfMonth(12);
    

    the result will be 12-March-2011. The first statement sets the date to 31-February, which gets normalized to 03-March, then the day gets set to 12. Ah, you say, you can just set the day-of-month first. But that doesn’t work for different starting points (construction of which is left as an exercise).

    And from your question I surmise that JodaTime throws exceptions rather than normalize, which is anothe reason for not doing it this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Joda-Time library with Java. I'm having some difficulty trying to turn
I am using Joda-Time library to convert my String dates to a real date,
I want to compare(finding remaining days and time between two days) using joda time.
I'm using Hibernate & Joda Time, with support from the UserType library. I'm able
Using the joda-time-2.0 version library, I was wondering, which of this functions is better
I am using the joda time library in my grails project. I've installed the
I'm having trouble using Joda Time's PeriodFormatter. I want one to report days, hours,
I am using the Joda-Time library in Java, and have a date and time
i am coming back because i still have problem using JodaTime. After the previous
I have some data about opening hours I'm trying to represent using Joda-Time. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.