Date Calculations

Thank you Bill. Will work on it.

1 Like

Thank you so much for this post. Very easy to follow and have done so. The example you did gives me 21 days in advance. Have I missed something or how do I do 45 days in advance please?

Sorry Kirby. I went from email and not your post above. Trying again.

BRILLIANT. Just changed the 37 (21 days) to 59 (45 days) in your formula and it works. Yippee and thank you so much. Also sorted out how to insert date

Is there a way to use a specific start date instead of the current date? I would like to copy an ISO date to the clipboard and then output the ISO dates of the next 14 days separated by Tabs.

Scope this out:

Here's a simple way to do this with AppleScript:

------------------------------------------------------------
# ISO-Date of each of 14 days past theDate.
------------------------------------------------------------
set theDate to "5/4/2015 11:30"
set theDate to date theDate

set _collate to {}
repeat 14 times
  set theDate to (theDate + (1 * days))
  set end of _collate to theDate as «class isot» as string
end repeat

set AppleScript's text item delimiters to tab
set the clipboard to _collate as text
------------------------------------------------------------

-Chris

My previous post was a bit unclear. What I meant was, that I need to copy the highlighted iso date of a confluence document to the clipboard, then pres TAB, then paste the ISO date of the following day by typing and repeat that 14 times. Based on your link I tried to use ICUDateTimeFor, but I can’t get it to work:

Set Variable ‘sprintNextDate’ to Text
%ICUDateTimeFor%TIME(%Variable%sprintStartDateYear%, %Variable%sprintStartDateMonth%, %Variable%sprintStartDateDay%+1)%YYYY-MM-dd%

Insert Text by Typing
%Variable%sprintNextDate%

outputs %ICUDateTimeFor%TIME(2015, 10, 09+1)%YYYY-MM-dd% but not the parsed date, I would like to have. Am I missing something here?

Please provide an example of your input.

You don’t paste by typing.

Do you actually need to type the 14 created dates? Or can you paste them?

Are they going back into the confluence document?

Is the original string supposed to be retained or replaced?

-Chris

Manually I’m doing these steps:

  1. I create a new Confluence page based on a custom template which contains a table with 14 columns.
  2. I click into the header cell of the first column and type an certain ISO date (some point in the future).
  3. I press TAB to change the focus to the header cell of the next column.
  4. I type in the ISO date of the following day (based on the date from the previous header cell).
  5. Repeat that until all 14 header cells contain a date.

I would like to speed this up by just entering the first ISO date and then let do KM do the rest.

What app are you doing this in?

Please provide a proper example of the date-format you’re using.

-Chris

I’m in my browser editing a Confluence document (https://www.atlassian.com/software/confluence). As stated above the date needs to be ISO formated (YYYY-MM-dd) (https://en.wikipedia.org/wiki/ISO_8601).

:smile:

Unless you know about the Confluence web-collaboration tool then “a confluence document” can mean any number of things.

Just because you say ISO date doesn't mean you really are using one.

Providing real examples of real data is key to allowing others to help you efficiently.

There are a number of ways to go about this task, but this method was easiest for me to whip up.

-Chris


Insert Dates into Confluence.kmmacros (3.8 KB)

This one still uses AppleScript to create the dates, but it uses Keyboard Maestro to insert them into the Confluence document.

-Chris


Insert Dates into Confluence v1.1.kmmacros (6.4 KB)

Thank you. That’s exactly what I was looking for. Just curious, would that be possible without applescript at all, just using KM actions?

Edit: There is a little bug in the applescript which prevents some dates from being parsed correctly (for example christmas 2015-12-24). I just changed

tell _date to set _date to {text item **2**, text item **3**, text item 1}

to

tell _date to set _date to {text item **3**, text item **2**, text item 1}

and now it works perfectly.

Yes, but I don't want to take the time to figure out how to do the date math at the moment. The AppleScript was easy.

This isn't a bug per se – it has to do with how you have dates set up in your system prefs.

Which localization are you using?

-Chris

A solution and a question. The date arithmetic is simple (odd, but simple).

This seems to work. Cobbled together from some example's Peter has posted in various places, and some examples posted by others.
_Attempt to ({tab}, paste date + 1 day) fourteen times..kmmacros (4.2 KB)

Why does %ICUDateTimeFor%Time(Year,Month,Day)% return the date one day before Year,Month,Day? When I use "Day", the date is decreased by 1 day; when I use "Day+1" the date is kept the same. In this macro I used "Day+2", in order to increase the date by 1 day.

I don't understand this behavior.

Region: Austria
UI-Language: English
Format language: German
Date format: ISO format :smile:

That explains it.

On my U.S. system the standard date setup is MM/DD/YYYY, and AppleScript requires that format to turn a string into a date-object.

I prefer YYYY/MM/DD myself, but if I change the system to reflect this some of my software gets flakey.

-Chris

Hey Kirby,

I think you may have missed the fact that TIME(Y,M,D) takes a GMT date/time string and returns a localized date/time.

Checking the KM function against date in the Terminal:

%Calculate%TIME()%
1444595856

date -j -f "%s" "1444595856" "+%Y.%m.%d %H.%M.%S"
--> 2015.10.11 15.37.36 (correct local time)

%Calculate%TIME(2015,1,11)% (We're not giving it a time, so it assumes Midnight GMT.)
1420934400

date -j -f "%s" "1420934400" "+%Y.%m.%d %H.%M.%S"
--> 2015.01.10 18.00.00 (correctly handling dst)

So:

%ICUDateTimeFor%TIME(2015,10,11,0,0,0)%yyyy-MM-dd HH.mm.ss%

On my system produces:

2015-10-10 19.00.00

If I give it the proper time offset (-6 normally -5 for dst):

%ICUDateTimeFor%TIME(2015,10,11,6,0,0)%yyyy-MM-dd HH.mm.ss%

2015-10-11 01.00.00

If I'm not needing the time I can just use -6 and not have to worry about fiddling with dst.

This is why I didn't want to bother figuring out the KM date-math yesterday.

The AppleScript gives me a simple localized date, and I don't have to fool with it.

-----------------------------------------------
set dateStr to "1/1/1970"
set dateObject to date dateStr
set newDate to dateObject + 10 * days
set newDateStr to short date string of newDate
-----------------------------------------------

Date-math in AppleScript can get goofy under some circumstances, but stuff like this is simple.

-Chris

1 Like

Indeed, and what a partial world of difference. Thanks for your guidance here. I have pressed my forehead to the fortress wall and walked the perimeter until I found a skeleton key hanging from the lock in this portcullis:

Accepting the limitation implied by "will generally work anywhere since at midday GMT, the entire world (almost) is on the same date", the following emendation to my all-KM macro should work "generally": replace the final Action with:
<img src="/uploads/default/original/2X/1/115538b59fb56972624656d5dfe32558a357a310.png" width="699" height="151"

It remains to make this work globally. Does the KM Calculation "GMTOFFSET()" accept any argument? Is there a way with KM to determine the GMT offset for a given date?

My thanks again. I shall, given the chance, show others these paths.