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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:31+00:00 2026-05-17T20:43:31+00:00

I have debugged this legacy code, and would like a sanity check on it.

  • 0

I have debugged this legacy code, and would like a sanity check on it.

The purpose of it is to allow someone to choose a delivery frequency for shipping a product. If someone wants their product Every Other Week, the system needs to determine if they should get an order next week, or two weeks from now. We call it A week, or B Week.

Keep in mind I did not write this, I am just trying to make sense of it and would like some help evaluating its accuracy:

if (date("l") == "Monday" ) {
            $start = 0;
        } else if (date("l") == "Tuesday" || date("l") == "Wednesday" || date("l") == "Thursday" || date("l") == "Friday" || date("l") == "Saturday"|| date("l") == "Sunday") {
        $start = -1;
    }

    // if changing to every other week set to next week's a/b-ness
    $a_week_tid = 34;
    $b_week_tid = 35;

    $every_other_week_frequency_id = 32;

    if ($delivery_frequency == $every_other_week_frequency_id) {
        $julian = (int) (strtotime('Monday +' . $start . ' week') / 86400);
        $julian_week = ($julian-4) / 7;
        if ($julian_week % 2) {
            $today_a_or_b = $b_week_tid;
            $next_week_a_or_b = $a_week_tid;
            $a_or_b_week_string = '(A Week)';
        } else {
            $today_a_or_b = $a_week_tid;
            $next_week_a_or_b = $b_week_tid;
            $a_or_b_week_string = '(B Week)';
        }
    } else {
        $next_week_a_or_b = NULL;
        $a_or_b_week_string = NULL;
    }

This code is not commented or documented. The part that confuses me is:

  1. Why is 4 subtracted from Julian, then divided by 7?
  2. If today is Monday, $julian_week is 2129, and 2129 % 2 evaluates TRUE. Is that correct?
  3. Is this even how it should be done? Can’t I rewrite this using date(‘w’) a lot easier?
  • 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-17T20:43:31+00:00Added an answer on May 17, 2026 at 8:43 pm

    Yeah using date would totally be easier, plus it takes into account leap years, daylight saving time, all that extra stuff you don’t want to have to deal with.

    if (date('W')%2==1)
    

    That’s SOOOO much easier to maintain than the above.

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

Sidebar

Related Questions

So I have all this code that I have debugged and it seems to
I have a code. like this: int functionA (){ Foo(**,**,**); return 0; } Foo()
I see a lot of legacy .Net 1.1-style code at work like in example
I have this code here: case 'resource_list': if(file_exists('content.php')){ include('../ajax/content.php'); } else { die('does not
I have some (legacy embedded c) code which produces a .csv file by means
I have debugged my java code.It doesn't seem to have any syntactical or LOGICAL
I have an entity that is mapped with a <join> element like this: <class
I have successfully debugged my own memory leak problems. However, I have noticed some
Is rails debugging supported on Aptana Studio 3. I have earlier debugged Rails applications
Both Ruby and Python have the ability of calling the debugger from code (

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.