Jump to content

Yet another date calculator


Recommended Posts

On 03/09/2016 at 0:55 PM, MuppetGate said:

if I was excluding weekends and which pushed out the date to another weekend, then I wasn't accounting for the new weekend and pushing the date out even further.

 

From my reading of your code, I think the issue is that you jump straight to the end date, figure out which days should have been excluded, and then adjust the end date accordingly (which you then need to repeat ad infinitum on the new range).

 

Rather, I think the right way to handle excludes would be to increment/decrement the date one day at a time, ignore that date if it's excluded, and keep going until your count matches the requested delta:

delta = 10  # wanted difference in days
exclude = 'weekends'
count = 0  # current difference in days
current = start_date

while True:
    if is_excluded(current, exclude):  # some magic goes here
        continue

    if count == delta:  # got result
        break
 
    # increment counter and current date for next loop
    current += timedelta(days=1)
    count += 1

print(current)  # the requested end date

 

Link to comment
  • 1 year later...

Thank you very much for creating such a great workflow.

 

I have found a few things that do not work and how to fix them.

  • The contents of /usr/bin/osascript currently refer to Alfred 2, not Alfred 3: to get the workflow to work with Alfred 3, all instances of: tell application "Alfred 2", need to be replaced with: tell application "Alfred 3"
  • The first /usr/bin/osascript (the one linked to dcalc) has all escapings active. Removing all escapings should allow the workflow to work properly without throwing an error when the output is anything else than just a date. For example if the output of the workflow is "DATE at TIME" or anything else resulting for a calculation that is more than just a date (m MONTHS, w WEEKS, d DAYS, h HOURS) an error will be thrown currently.
  • dcalcset date and time: currently the call to this command doesn't work. The reason is that on line 26 of the file date_time_format_list.py the call to date_time = datetime.datetime.now() should be replaced with date_time = datetime.now()
  • I recommend activating "Automatically paste to frontmost app" in the "Copy to Clipboard" module that is connected to dcalc
Link to comment

 

Okay, I’ve scored a bit of time to revisit the date app and fix a few bugs. Not everything has been looked at because I’ve got to head off again for a while, but what I have done is:


–    Upgraded the workflow library
–    Fixed a few of the scripts that referred to Alfred 2 instead of Alfred 3 (I guess this means Alfred 2 is no longer supported).
–    A bit of a general code tidy up


The big piece of work though, is the restoration of the exclude functionality, which should work properly, but with limitations. To prevent it blowing things up if the search combination doesn’t produce a valid match, I’ve limited the workflow to about 300 attempts to look for a match. After that, I’ll throw an error.


So how does it work? Here’s a quick example.


Say you’re a busy project bod and you have a piece of work that’s going to take three weeks. So you enter the data expression:


dcalc today + 3w


And that gives you a date three weeks into the future. But hang on a sec: no one works weekends, so how long will it take if there are no weekends included:


dcalc today + 3w exclude weekends


So now the date will be further into the future because weekends are not counted as part of the project. (Another way to look at it is if people worked weekends then the project could be brought in at an earlier date).


You can exclude individual days:


dcalc today + 3w x weekends 28.10.2018 


This will exclude all weekends and also the 28th of October. Note that you can just use x or ex instead of exclude.
We can exclude other days:


dcalc today + 3w x Tuesdays Wednesdays Fridays


We can also do ranges:


dcalc today + 3w exclude Tuesdays 30.10.2018 to 05.11.2018 02.12.2018


This beast will exclude Tuesdays, all days between the 30.10.2018 and 05.11.2018, and it will also exclude 02.12.2018
We can also do:


dcalc today + 3w exclude all except tuesdays


Error checking is minimal, but this kind of stuff won’t work:


dcalc today + 3w ex all except wednesdays wednesdays
dcalc today + 3w x weekends weekdays

 

Because every day has been excluded.

 

The update can be found in the usual place:

 

http://www.packal.org/workflow/date-calculator

 

The usual disclaimers apply, so don't use this to schedule brain surgery.  Use a calendar.

 

Edited by MuppetGate
Link to comment
  • 3 years later...

I am using Alfred 4.6.4 with Python 2.7.18.

 

Lately, for this Workflow, when I start typing any argument I get web search option and the arguments are not passed to Workflow.

 

I am not sure if the Workflow is broken after the update or if its my system. Can you please help?

 

 

Alfred_Dcalc_Issue.gif

Link to comment
  • 2 months later...

@face This is due to macOS removing Python 2 from Monterey 12.3. You can read more about it here:

https://www.alfredapp.com/blog/guides-and-tutorials/python-2-workflows-on-macos-monterey-12-3/

 

Once you've reinstalled Python 2, grab the updated version of this workflow here:

https://github.com/alfredapp/updated-third-party-python2-workflows#readme

 

Cheers,
Vero

 

Link to comment

no i use (italian date format)

today 24th june 2022

i'd like to insert

24.6.2022

(now seem only possible to insert 24.06.2022 with 0 added)

 

and on 1st july 2022

i'd like to insert

1.7.2022

(now seem only possible to insert 01.07.2022 with 0 added)

 

is it possible to setup that format date ?

Link to comment
  • 3 weeks later...
On 6/24/2022 at 3:04 PM, giovanni said:

oh I see, I didn't test the calculations... this format needs a bit of a workaround, could you try this version? @face

That link has been removed. Is there any way to change how the date is displayed in Alfred? I see at least 3 different places to change the format in the workflow. Instead of:

dd.mm.yy

how do I change it to?

mm.dd.yy

 

I tried to edit the workflow but the output is the same. What do you think?

Screen Shot 2022-07-16 at 3.59.11 PM.png

Screen Shot 2022-07-16 at 3.51.53 PM.png

Link to comment

@giovanni when I go to type `dcalc now` or `dcalc tomorrow` for example it takes me to my default search list. When this happens I usually fix it by selecting "require an argument" in the dropdown list but its already selected.

 

Before the update the workflow seemed to work fine. Any ideas what I could be doing wrong?

Screen Shot 2022-07-18 at 10.14.32 AM.png

Screen Shot 2022-07-18 at 10.14.01 AM.png

Screen Shot 2022-07-18 at 10.17.29 AM.png

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