Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit date range in Joda Time

I am using Joda Time library for parsing the string into dateTime using parseDateTime funtion in this library and noticed that date range supported for this library is -292,269,054 to 292,277,023.

Can anyone know on how to limit date range using this library.Especially with year (YYYY) to 9999?

Thanks.

like image 261
svp Avatar asked Oct 30 '14 05:10

svp


2 Answers

Interval Class

You can limit date ranges in Joda-Time with Interval.

You can then query whether a DateTime is within that interval/range.

like image 93
CharlieS Avatar answered Oct 05 '22 12:10

CharlieS


As MadProgrammer commented, limiting a date range is your job as the app developer. Joda-Time cannot know what you consider to be reasonable limits.

Bean Validation

To help with that chore of validating data, you might find the Bean Validation spec useful. Defined by JSR 303 (spec 1.0) and JSR 349 (spec 1.1).

With Bean Validation, you can conveniently use annotations to define rules such as a minimum and maximum value for a particular member variable in a class.

like image 28
Basil Bourque Avatar answered Oct 05 '22 12:10

Basil Bourque