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

  • Home
  • SEARCH
  • 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 9147287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:57:06+00:00 2026-06-17T10:57:06+00:00

I have an array of words and each word is valid from 5PM that

  • 0

I have an array of words and each word is valid from 5PM that day until 5PM the next day, then the next word is valid. Except on weekends in which a word for Friday lasts until Monday at 5PM.

Now what I am trying to do is determine if the users inputted word is valid for that period of time. I have a working example which works fine, but my problem is the weekends mess everything up. And I can’t seem to figure out how to make them work.

I got a function to figure out how many weekends occur between two timestamps

// Figure out how many weekends occured between two dates
function weekends($date1, $date2) {
    $d1 = new DateTime('@' . $date1);
    $d2 = new DateTime('@' . $date2);

    // Compare the two dates
    $diff = $d1->diff($d2);

    // Get number of days between them
    $days = $diff->format('%a');

    // Find out day of the week we start on
    $start = $d1->format('w');

    // Verify we are not on a weekend
    if($start == 0 || $start == 6)
        return false;

    // Number of days until weekend
    $until_weekend = 7 - $start; // (6 is Saturday but we are counting today)

    // Find out how many days are left between the first weekend and the end
    $left = $days - $until_weekend;

    // How many weekends
    $weekends = floor($left / 7) + 1;

    return $weekends;
}

And then I got a function to determine if the word is valid for that date range

// Keyword Validation
function keyword_validate($keywords = array()) {
    if(empty($keywords)) return false;

    // Break into values
    $keyword = $keywords['keyword'];
    $contest = $keywords['contest'];
    $keywords = $contest['keywords'];

    // Get some dates
    $now = new DateTime('now');
    $start = new DateTime('@' . $contest['start_time']);
    $s1 = new DateTime('@' . $contest['start_time']); // value for timestamps
    $s2 = new DateTime('@' . $contest['end_time']); // value for timestamps
    $end = new DateTime('@' . $contest['end_time']);

    // Verify keyword exists
    if(in_array($keyword, $keywords) === FALSE)
        return false;

    // Get index
    $index = array_search($keyword, $keywords);

    // See if we somehow got more then one keyword
    if(count($index) != 1)
        return false;

    // get number of weekends
    $weekends = weekends($start->getTimestamp(), $end->getTimestamp());

    // Based on index get the two container timestamps
    $s = $s1->add(new DateInterval('P' . $index + $weekends . 'D'));

    // Verify start doesn't equal Friday or a Weekend

    $e = $s2->add(new DateInterval('P' . $index + $weekends + 1 . 'D'));

    if($s === FALSE || $e === FALSE)
        return false; // Something really bad happened

    // Based on dates find out if the keyword works.

    print $s->getTimestamp();
    print $e->getTimestamp();
    // Get the current time

}

As you can seem the keyword function doesn’t work atm. What I am doing atm is matching the index of the keyword to day, but if it is say Tuesday (2 weekends after) how can I make it so the index is increased by 4. Sorry if this doesn’t make any sense, I’m a little lost.

  • 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-17T10:57:07+00:00Added an answer on June 17, 2026 at 10:57 am

    Try redefining the problem to make it simpler. Instead of trying to do math with funny exceptions to figure out which item is associated with which day, perhaps try creating a new array with a value of the word for each day. It could look like this:

    array(
        'cake',
        'pie',
        'pudding',
        'happy', //friday
        'happy', //saturday
        'happy', //sunday
        'nothappy',
        ...
    );
    

    Building this array should be simpler than the things you’re trying to do now. Once you have this array, checking should be trivial.

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

Sidebar

Related Questions

I have a list of words (object) in an array. Each word has a
I have a program that takes input from a file, saves each word in
I am newbie to python. I have an array of words and each word
I have an function that creates an array of words from a string, counts
I have an array of ushorts, with each ushort representing a 12-bit word. This
Hi I have an array of words that I want to do a couple
I have a question simple like that: Let user enter some words from keyboard,one
I have a word file with 3 words. I need to read each word
I have a multidimensional array that contains a variable number of sub arrays. Each
I have seven words in the array: string[7] = {x,x,x,x,x,x,x}; the x is generated

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.