mills Posted January 13, 2018 Share Posted January 13, 2018 (edited) 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 January 13, 2018 by mills Link to comment
deanishe Posted January 13, 2018 Share Posted January 13, 2018 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 Posted January 13, 2018 Share Posted January 13, 2018 Here's a version of your workflow that ignores weekends. It doesn't know anything about public holidays, though. mills 1 Link to comment
mills Posted January 13, 2018 Author Share Posted January 13, 2018 @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
deanishe Posted January 13, 2018 Share Posted January 13, 2018 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), mills 1 Link to comment
mills Posted January 13, 2018 Author Share Posted January 13, 2018 @deanishe Perfection, thank you very much for (basically doing this) the help. Link to comment
deanishe Posted January 13, 2018 Share Posted January 13, 2018 (edited) 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 January 13, 2018 by deanishe Link to comment
mills Posted January 13, 2018 Author Share Posted January 13, 2018 (edited) @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 January 13, 2018 by mills Link to comment
deanishe Posted January 13, 2018 Share Posted January 13, 2018 (edited) 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 January 13, 2018 by deanishe mills 1 Link to comment
mills Posted January 13, 2018 Author Share Posted January 13, 2018 @deanishe Okay, that is magical. Link to comment
deanishe Posted January 13, 2018 Share Posted January 13, 2018 Be sure to test it well to make sure it's really giving you the right dates. mills 1 Link to comment
deanishe Posted January 13, 2018 Share Posted January 13, 2018 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
mills Posted January 14, 2018 Author Share Posted January 14, 2018 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 Posted January 14, 2018 Share Posted January 14, 2018 Right you are. I suppose it's not a huge chore to edit the odd snippet by hand. But like I said, be sure to give it a good test before you use it. Link to comment
mills Posted January 19, 2018 Author Share Posted January 19, 2018 @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
deanishe Posted January 20, 2018 Share Posted January 20, 2018 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now