• Prime Mover (unregistered)

    Had a boss once whose skills lay in communication. That is: he was really good at talking. I mean, really really good. If there was an instant of time which needed to be decorated by the sound waves caused by the operation of his vocal apparatus, that occasion was risen to with aplomb. Basically, he never stopped blethering. I mean, whatever needed discussing in the universe, he could be relied upon to express his opinion, and most of what seemed to need to be discussed was the content of his lifestyle. Erm, hang on, I seem to be channeling him at the moment, sorry, let me start again.

    So, one day he decided he was going to descend into the code for some reason, so he logged into the machine, started diddling around, then decided someone needed his advice, so up he got and onto his mobile, and wandered around the building. At that point, our grandboss turned up, took at look at his screen, which he had left open, and said. "Good grief, he's coding. Don't let him code." And she expertly exited him no-save from the file he was editing, and logged him out of the system.

    "Sorry," she said, "apologise to him when he comes back, and remind him I told him he's not allowed to touch code." With which she walked off.

    Boss came back from his walkabout, still rabbiting away, sat back down at his machine, and carried on doing something else, unrelated to whatever he had decided to do earlier, and seemed to have completely forgotten he had wandered into the codebase.

    Fortunately he was given a much-deserved promotion soon after, and was replaced by someone totally different in every way.

  • Smithers (unregistered)

    If anyone works out what it actually does, be sure to post it in the comments

    The simplest way I can describe what it is doing is that it returns a DateTime that is the given number of months (for a 28-day value of "month") before dtTo, or up to a week longer, while being the same day of the week and time of the day as dtFrom. Or, more mathematically, in the range (dtTo - (4month+1) weeks, dtTo - (4month) weeks] and congruent to dtFrom modulo 1 week.

    Describing why it does this, however, is beyond me.

  • (nodebb) in reply to Smithers

    The only thing I can think of, he was trying to write some kind of scheduling, with repeating dates and what not. The requirements were, do something every N months, during the specific week M of that month.

    Addendum 2022-04-11 07:32: PS. Between those requirements, and some unknown amount of mushrooms, this code was born.

  • RLB (unregistered) in reply to Smithers

    I suspect the only way to work out why this does what it does, is to find out how it's used. If it's no longer used - and IME code like this often isn't - just eradicate it.

  • I like to stay anonymous (unregistered)

    The code might try to move the start date to accomodate a fixed time period for stuff to happen. Think along the lines of "we have a due date and we always need n weeks to produce the result due at the due date". Given the due date we have to figure out when we should have started to produce the result.

  • MaxiTB (unregistered)

    This code makes no sense.

  • IA (unregistered)

    In short (as others pointed out) it does return dtTo.AddDays(-28 * month); with some rounding.

  • see sharp (unregistered)

    Makes me think of the 13-month calendar (https://en.wikipedia.org/wiki/International_Fixed_Calendar) I encountered many years ago while working for Kodak. Because it's rarely used, not surprising it would require custom code like that. In that calendar, if I recall correctly, "months" are fixed 4 weeks / 28 days, with some arcane rules for adding an extra week as required to keep things in alignment.

  • Chris Gonnerman (unregistered)

    Converted it to Python out of curiosity. Doesn't seem that bad, until you give it some test data and run it... the results are maddeningly weird.

  • (nodebb)

    Frighteningly, they've moved into a more senior position elsewhere

    The "elsewhere" part tells me that "frighteningly" should really be "thankfully".

  • (nodebb) in reply to Smithers

    Thanks for that. I now understand the code. I think the biggest impediment was the month parameter, which I assumed represented a month e.g January, February etc.

  • (nodebb) in reply to Smithers

    Thanks for that. I now understand the code. I think the biggest impediment was the month parameter, which I assumed represented a month e.g January, February etc.

  • (nodebb) in reply to Jeremy Pereira

    The "elsewhere" part tells me that "frighteningly" should really be "thankfully".

    Well, except that because it's a more senior position, there's a good chance he will be able to do significantly more damage in the new position.

  • iWantToKeepAnon (unregistered)

    Then we take the month input and convert it into weeks, by simply multiplying by 4. That's… not accurate. I mean, it's the floor of the number of weeks per month, so maybe it's fine.

    ... or if you're dealing in lunar months.

  • Loren Pechtel (unregistered)

    Return the date x "months" before the end date, but then pick the date before that that is on the same day of the week as the "start" date. Do it very inefficiently.

  • tbo (unregistered)

    I didn't totally math it out, but this might work for a very restricted number of months, say, 0-2.

    But yeah, it's roughly "get the date closest to endDate that's x number of months after startDate on the same day."

  • Hmmm (unregistered)

    A month in this case is strictly 28 days, which corresponds to the amount of time for that virus from that movie to take over the globe.

    Starting with a deadline ("to" date) and a potential candidate ("from" date), see if the candidate is approximately the number of months away that you require (target). Adjust the "from" date by one month at a time until it's no more than one entire month off from the target range.

    So, given an end-of-days deadline, when would you need to start, within a wave's time, to have approximately "months" number of zombie waves across the globe. This could be used, along with a survival and immunity rate, to estimate the final population on Earth after so many waves.

  • Hmmm (unregistered) in reply to Hmmm

    Actually, the function does make sense for some real-worldpurposes.

    Let's say Freddy allocates charge codes for office projects only on the 13th of each month, but doesn't allocate for projects more than two two-week pay periods out. I've got something with N two-week pay periods' lead time and I need Freddy's time before that time range starts. So which date would I pick?

  • MaxiTB (unregistered)

    If your assumption is correct, the code without the 28-days magic would be like :

    public DateTime GetCorrectDate(DateTime from, DateTime to, int expectedMonths) => from.AddMonth(-expectedMonths + (to-from).Months);

  • Tim (unregistered)

    Maybe someone has finally discovered the way to calculate Easter or Eid?

  • MaxiTB (unregistered) in reply to Tim

    Easter is pretty simple, just use the algorithm by Carl Friedrich Gauß developed centuries ago: https://philosophy.hi7.co/carl-friedrich-gauss--easter-5716f3f7ec9a3.html ;-)

  • WTFGuy (unregistered)

    One thought ...

    Neer assume it's just bad code. Always assume it's illogical-to-insane business requirements badly coded.

  • Old timer (unregistered)
    Comment held for moderation.
  • kwick exchange (unregistered)
    Comment held for moderation.
  • David Mårtensson (unregistered) in reply to MaxiTB

    Yes, its a nice one ;)

    understanding it is quite another matter.

    But it actually does something similar to the example here.

    It calculates a base value then adjusts it back or forth depending to get the right value for the current year.

  • Gnasher729 (unregistered)

    I would suggest first to comment out the function and see where you get compiler/linker errors. In many languages that will tell you all callers. Then at each call site log the caller arguments and results.

    Hopefully most of the logic is never needed, and maybe much of it cannot be needed. Then we can start writing a replacement function that is well-documented and call it whenever possible. Trying to understand what the function does is probably pointless.

    I once had a highly complicated function that nobody could understand and that crashed occasionally. I refactored it (refactor = no change in behaviour) and after some hours it was quite readable except two lines looking like “if (complicated expression) crash();”. I deleted these two lines and everything worked fine.

  • Todd A. Weeks (unregistered)
    Comment held for moderation.
  • RobertCardenaswef (github)
    Comment held for moderation.
  • RobertCardenaswef (github)

    A dating site like DoULike, it often provides a user-friendly platform for singles in the USA to connect https://www.doulike.com/usa/singles.html . The site typically offers a variety of features and tools to help individuals find potential matches based on preferences, interests, and location. Users appreciate its straightforward interface and the ability to engage with others seeking similar relationships, whether for friendship, casual dating, or something more serious. As with any online platform, being mindful of safety and authenticity while interacting with others is important.

  • RobertCardenaswef (github)

    Local dating platforms like DoULike often offer a great way to connect with potential matches in your area. They focus on facilitating meaningful connections between individuals who share common interests or lifestyles. These platforms can streamline the dating process by emphasizing local connections, making it easier to meet people nearby. Features like location-based https://www.doulike.com/local-dating.html matching and personalized profiles can enhance the chances of finding compatible matches and creating genuine relationships within your community.

Leave a comment on “Starting Your Date”

Log In or post as a guest

Replying to comment #558454:

« Return to Article