Jump to content

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
Link to comment
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.

Link to comment

@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?

Link to comment
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),

 

Link to comment

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
Link to comment

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
Link to comment
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.

Link to comment
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.

Link to comment

@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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...