Jump to content
mills

Modified date calc based on input

Recommended Posts

I have a workflow (here) which works well to take trigger a snippet with calculated days, however, I'd like to make it exclude weekends (or alternatively include only business days), but I'm unsure how to go about doing that. I am assuming a script filter would need to be placed between the initial input of "number of days ahead" and all calculations based on that input.

Edited by mills

Share this post


Link to post
38 minutes ago, mills said:

I'm unsure how to go about doing that

 

I'm pretty sure you'll need to write a script in Ruby or Python etc.

 

You can only do very naïve date calculations with Alfred: it doesn't have a concept of weekends or workdays.

 

It seems to me that for a correct calculation, your code would also have to know about public holidays. There are libraries for that, but if you're shipping across borders, the problem is suddenly rather complex.

Share this post


Link to post

@deanishe

 

That is awesome, thank you so much. I don't think the holiday thing is as relevant for this purpose, so this is fine.

I should probably learn python.

I did notice that I can add 0 days and get today's date, but adding 1 goes to Monday, which makes sense given the way the data is defined in main, but what would I need to do to parse that out? Basically so if someone said "I want to know when I'll get this if I order on Sunday" I would be able to get that answer.

 

Would I need to define a new function and pull the 'ordered' out so that it just adds date + n, no matter what day of the week?

Share this post


Link to post
15 minutes ago, mills said:

Would I need to define a new function and pull the 'ordered' out so that it just adds date + n, no matter what day of the week?

 

If orders can be placed on any day of the week, and weekdays/weekends are only a factor in the delivery time, then yeah. Change the line that says

'ordered': add_days(n),

to

'ordered': (date.today() + timedelta(days=n)).strftime(DATE_FMT),

 

Share this post


Link to post

Hang on, that's not right.

 

Presumably, an order placed on Saturday should have the same delivery date as one placed a day later (Sunday). (And the preceding Friday, too?)

 

Can you lay out the calculation logic in proper detail, so I can verify whether the script is following it?

Edited by deanishe

Share this post


Link to post

@deanishe

 

Oh right, that's true. Technically the Friday could still be a day earlier, so only Sat & Sunday should share the estimated result

Edited by mills

Share this post


Link to post

Try this new version.

 

I changed main so it always counts from the right start date:

start = date.today() + timedelta(days=n)
data = {
    'ordered': start.strftime(DATE_FMT),
    'd10': add_days(10, start),
    'd12': add_days(12, start),
}

Now it gives you the same delivery date for an order placed on Friday, Saturday or Sunday.

Edited by deanishe

Share this post


Link to post
37 minutes ago, mills said:

Technically the Friday could still be a day earlier, so only Sat & Sunday should share the estimated result

 

What do you mean "could"? The ball might get rolling on the same business day, or it might be a day later?

 

Presumably, that would also mean that Sat & Sun could share the same estimated delivery date as the following Monday.

 

I'm happy to help further, but you need to be a lot clearer about how you calculate your delivery dates.

Share this post


Link to post
3 hours ago, deanishe said:

I'm happy to help further, but you need to be a lot clearer about how you calculate your delivery dates.

 

Honestly, for the purpose of this expansion this is perfect. In theory an order could be placed early enough on a Friday and approved for production that it could go a day earlier, but it's not the most common; similarly an order placed Sunday may be submitted and shipped earlier than one placed Monday because of production workflows. All of the dates are provided as estimates, so seriously, thank you so much, and this will do exactly as necessary.

Share this post


Link to post

@deanishe

 

Okay so it's working as intended entirely, however I'm now curious if I could create ordinals in the formatting. My python being entirely atrocious, I'm unsure where to interject it. The modified workflow is here, if you'd be willing or able to help.

 

I did modify to output "Today" when N = 0 and another date by adding two variables, 'rawdays' & 'd7' respectively.

 

I did find this solution, but I was not able to see how it would be placed in the script.

Share this post


Link to post

You've deleted the Python script from that workflow.

 

The date is formatted on the lines that say .strftime(DATE_FMT). That's where you need to insert your new algorithm.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...