Jump to content

Yet another date calculator

Recommended Posts

Right, we're up to version 1.2 with clearer instructions regarding the addition of anniversaries.


I've also revamped the anniversary function so it doesn't choke if someone's birthday is on the 29th of February, but bear in mind that the next occurrence of this anniversary might be further away than you think.

Link to comment

And finally, version 1.3!


The big change is that the function call go at the end, so instead of this:


dcalc wn today


You now write this:


dcalc today wn


I made the change to save keystrokes mainly; you now don't have to tap your way back to the start of the command to change the function, and it's not really a function; it's a bit of formatting that should really happen at the end of the calculation


dcalc alfred + 1d wd


That will tell you the day of the week one day after Alfred's next anniversary.

Link to comment
  • 2 weeks later...

I found something seems like a bug, but it could be a not doing something right:





I enter a list item (iva) and when I did 


dcalc iva-^iva y


I expect the years between these two dates, in case of birthday I expect how much years the person will become at his birthday. What I've received is contradictory based on the output format:


dcalc iva-^iva y

29 years


dcalc iva-^iva ym

29 years, 12 months


dcalc iva-^iva ymd

29 years, 12 months, 4 days


dcalc iva-^iva long

29 years, 11 months, 29 days, 0 hours, 49 minutes, 41 seconds


What I expect is:

39 years, 0 months, 0 days, 0 hours, 0 minutes, 0 seconds

Link to comment

Quick question:


Did you mean '29 years' in your last example?


In any case you shouldn't have 12 months as part of any answer. I think this probably due to a rounding error in the calculation of the formats that are not 'long' (which is more accurate because it is calculated differently). 


I'll look into it.

Edited by MuppetGate
Link to comment

Right, that was a mostly a bug. Turns out that the decision to supply the current time to anniversaries was not a good one. 


I've tuned up the formatting stuff (ymwdhMs) but due to uneven months, it's never going to be as accurate as just going for 'long' as the format, which calculates the whole thing in one go.


A new version (1.4) is now up on Packal.


You should delete Iva's anniversary and create it again.




I've also added start_bst and end_bst for British Summer time.


For example:


dcalc start_bst

Edited by MuppetGate
Link to comment
  • 1 month later...
  • 1 month later...

Hi, this a great tool, thank you.  Any thoughts to expanding the time calcs?  I am constantly needing to do things like this:  3:15pm-6:45pm = 3.5 hrs




Hello there. Thanks very much; I'm glad you find it useful. 


Right, time calculations. 


dcalc 15:15 - 18:45  


gives you 0 days by the looks of it,  which looks like a bug somewhere.


But all is not lost!


If you try:


dcalc 15:15 - 18:45 h


That will give you:


3.500 hours


The 'h' is sort of like a formatting code and means 'give me the result in hours'


dcalc 15:15 - 18:45 hM


Gives the result in hours and minutes:


3 hours, 30.000 minutes




dcalc 15:15 - 18:45 hMs




3 hours, 30 minutes, 0.000 seconds


The workflow only understands the 24-hour clock, but I might make the 12-hour clock an option when I have a bit more time. (I'm trying to write a book at the moment!)

Edited by MuppetGate
Link to comment
  • 2 months later...

Hello, and happy new year!


Okay, I've been fiddling about with the date calculator to make it a little bit more versatile.


First up, it now supports the 12-hour clock for entering and formatting times. I'm not a big fan of this format because it requires more typing (it has to be in this format: xx:xxAM/PM) which I think is harder to work with than the 24 hour clock. The AM/PM indicators have to be in upper case, but I'll fix that this afternoon.


A Python wizard called Mike Taylor has a framework that can translate natural language into a date. I've dropped the framework in as a bit of an experiment, so if you surround the date expression in double quotes, the workflow will have a go at translating it for you.


dcalc "day after tomorrow"


dcalc "next tuesday"


dcalc "3 hours from now"


It really is a lot of fun!


Finally, I've added something to celebrate finishing the first draft of my book:


dcalc passover


will work out the date of the next passover.

Edited by MuppetGate
Link to comment
  • 5 weeks later...



Thanks for such a wonderful workflow.


I am trying to do below and not sure if it's supported

dcalc 10-15-2015 - 60d x weekends

From above, I want to get 60 days before date 10-15-2015 excluding weekends.


Am I writing it wrong or this isn't supported?



Link to comment

Hi! I've just discovered your workflow and it's really useful, thank you!


I'm a lawyer and I had been looking for a quick way to do a rough calculation of court days to calculate, for example, when a brief is due. 


I'm trying the following syntax but it's not working, am I doing something wrong?


dcalc today-25d exclude weekends


Thanks a lot!!!

Link to comment

Hi! I've just discovered your workflow and it's really useful, thank you!


I'm a lawyer and I had been looking for a quick way to do a rough calculation of court days to calculate, for example, when a brief is due. 


I'm trying the following syntax but it's not working, am I doing something wrong?


dcalc today-25d exclude weekends


Thanks a lot!!!



+1 for this question.


I tried "dcalc today+30d x weekends" with no success.


The "exclude weekends" feature would be very useful to me.

Link to comment



Interestingly enough, you're all trying to do the same thing.


There's actually two types of calculation: one returns  a time span, the other returns a date.


The 'exclude' only works on a timespan.


If you enter today + 30d, that will give you a date.


But today - 13.03.2015 will give you a timespan (1 month, 2 weeks, 4 days and a rogue second) which can be used with exclusions.


today - 13.03.2015 exclude weekends


The exclude function only works on functions returning timespans, not dates.


Unfortunately, some stuff I've done with formatting has made this far less useful, so I'm going to have to make some changes to it.


Sorry about that!


But yes, the exclusions only work on timespans, not calculations that deliver a final date. I'll have a think about that one.

Edited by MuppetGate
Link to comment

G'morning folks.


I've updated the workflow (again!) to tidy up a bit of the code and add a couple  of new small functions.


First up, the requested expansion to the exclude functionality. As well as working with timespans, you can now use it on functions that return absolute dates.


For example:


dcalc today + 60d x weekends


will give you a date 60 days from now that has been adjusted to discount any weekends that occur in the timespan.


The second change is the expansion to the week_number function.


You can already do this:


dcalc today wn


to find the current week. Great stuff, but then I ran into an odd one at college the other day. The lecturer said, "Final pieces need to be submitted by week 19."

And someone else said, "What date is that?"

And of course, no one knew.




dcalc wn 7


will give the date for week 7 of the current year. It will use the current day of the week you're sitting on as the baseline. So if I enter the command on Monday, it will give me the date of Monday week 7. That's not especially useful, so it's probably better to supply the day of week as well:


dcalc wn 7 sun


So that will give you the date on Sunday week 7


And of course, you might want to pick out a different year:


dcalc wn 2016 7 sun


will give the date on Sunday in the 7th week of 2016 (which is  the 21st of February apparently).


That's it for now. The new version can be found here.

Edited by MuppetGate
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...