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 7051833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:18:39+00:00 2026-05-28T03:18:39+00:00

I have some data about opening hours I’m trying to represent using Joda-Time. The

  • 0

I have some data about opening hours I’m trying to represent using Joda-Time.

The typical opening hours of day look like this:

Open from 9 to 12, and from 13 to 20.

My main reason for representing them in Joda-Time entities, is to validate them:

  • Check that opening hours are valid (9 is before 12, etc)
  • Check that no open-intervals overlap (“9-12 and 11-13” are illegal)

API-wise, the Joda-Time Interval class has the methods I need for doing this validation, but Intervals are pairs of instants in the date-time-continuum. I would like to represent them independent of absolute time, kind of like an Interval of two LocalTime partials. Is this possible?

  • 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-05-28T03:18:40+00:00Added an answer on May 28, 2026 at 3:18 am

    Here’s an attempt at a custom TimeInterval (pretty much like the solution Gray commented):

    import org.joda.time.*;
    
    public class TimeInterval {
        private static final Instant CONSTANT = new Instant(0);
        private final LocalTime from;
        private final LocalTime to;
    
        public TimeInterval(LocalTime from, LocalTime to) {
            this.from = from;
            this.to = to;
        }
    
        public boolean isValid() {
            try { return toInterval() != null; } 
            catch (IllegalArgumentException e) { return false;}
        }
    
        public boolean overlapsWith(TimeInterval timeInterval) {
            return this.toInterval().overlaps(timeInterval.toInterval());
        }
    
        /**
         * @return this represented as a proper Interval
         * @throws IllegalArgumentException if invalid (to is before from)
         */
        private Interval toInterval() throws IllegalArgumentException {
            return new Interval(from.toDateTime(CONSTANT), to.toDateTime(CONSTANT));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data about a day's events that I'm trying to visualise as
I have a PHP-generated page which is displaying some data about a set of
I have a table containing data about some users. Many of them use our
I have data about colors. Some of those colors consist of a number of
I have a sheet full of some raw data, about 20,000 rows and 50
I have a MySQL/Rails app that needs search. Here's some info about the data:
I have a data frame in R that has come about from running some
I have some data which my program discovers after observing a few things about
I have a program that needs to retrieve some data about a set of
I have some code that utilizes simplexml to retrieve some data. I perform about

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.