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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:12:36+00:00 2026-05-11T08:12:36+00:00

I have an array of dates in a one week range stored in an

  • 0

I have an array of dates in a one week range stored in an unusual way.

The Dates are stored in this numeric format: 12150

From left to right:

1st digit represents day: 1 = sunday, 2 = monday, 3 = tuesday, …., 7 = saturday

next two digits represent hour in a 24 hour system: 00 = midnight, 23 = 11pm

next two digits represent minutes: 00-59

Given an input date and a start date and end date I need to know if the input date is between the start and end date.

I have an algorithm right now that I think works 100% of the time, but I am not sure.

In any case, I think there is probably a better and simpler way to do this and I was wondering if anybody knew what that algorithm was.

If not it would be cool if someone could double check my work and verify that it does actually work for 100% of valid cases.

What I have right now is:

if (startDate < inputDate &&      endDate > inputDate) {         inRange = yes;     } else if (endDate < startDate) {         if((inputDate + 72359) > startDate &&           (inputDate + 72359) < endDate) {           inRange = yes;          }         else if((inputDate + 72359) > startDate &&                (inputDate + 72359) < (endDate + 72359)) {           inRange = yes;            }  } 
  • 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. 2026-05-11T08:12:36+00:00Added an answer on May 11, 2026 at 8:12 am

    How about

    const int MAX = 72460; // Or anything more than the highest legal value inRange = (MAX + inputDate - startDate) % MAX <            (MAX + endDate - startDate) % MAX; 

    This assumes of course that all the dates are well formed (according to your specs).

    This addresses the case where the start is ‘after’ the end. (e.g. Friday is in range if start is Wednesday and end is Monday)

    It may take a second to see (which probably isn’t good, because readability is usually the most important) but I think it does work.

    Here’s the basic trick:

     Legend:     0: Minimum time   M: Maximum time    S: Start time   1,2,3: Input Time test points   E: End Time  The S  E => Not in range   2  In range   3 > E => Not in range  The S > E case                         0                 M   Original              -1--E----2---S--3--   Add Max               -------------------1--E----2---S--3--   Subtract StartDate    ------1--E----2---S--3--         % Max                 S--3--1--E----2----    1  In range   2 > E => Not in range   3  In range 

    If you really want to go nuts (and be even more difficult to decipher)

    const int MAX = 0x20000;  const int MASK = 0x1FFFF; int maxMinusStart = MAX - startDate; inRange = (maxMinusStart + inputDate) & MASK <            (maxMinusStart + endDate) & MASK; 

    which ought to be slightly faster (trading modulus for a bitwise and) which we can do since the value of MAX doesn’t really matter (as long as it exceeds the maximum well-formed value) and we’re free to choose one that makes our computations easy.

    (And of course you can replace the < with a <= if that’s what you really need)

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

Sidebar

Related Questions

No related questions found

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.