Jump to content

Recommended Posts

Posted (edited)

Generate relative dates based on a simple input format and your own date formatting parameters (there are some default placeholders you can delete).

Supports multiple locales/languages.

demo.gif

Downloading

Get the workflow from GitHub.

Keywords

  • date — Generate a formatted date using the [input format][]
  • — Copy date to clipboard
  • ⌘+↩ — Copy date to clipboard and paste into frontmost app
  • datehelp — Open the help file
  • dateformats — View saved date formats
  • ⌘+↩ — Delete date format
  • dateadd — Add a new date format
  • — Save the date format
  • datereset — Reset the saved date formats to the defaults

Input format

(+/-)<NUM>(w|d|y) where w = week(s), d = day(s) and y = year(s)

You needn't specify a sign: + is understood as the default, so +1d and 1d mean the same thing.

Months are not supported, as it leads to ambiguity: what if today is the 31st, but the target month only has 30 days? Similarly, a year is naively defined as 365 days.

Examples

  • 0 = now = today — today's date
  • 1d — 1 day from now
  • 7d = 1w — 1 week from now
  • -21d = -3w — 3 weeks ago

Supported formats

The Workflow includes a few defaults for the locales en_US, en_GB and de_DE.

You can specify your own custom date formats using the formatting options listed at the below links, and you can also specify a language with the format lang=de or lang=de_DE if you want to use dates formatted for a language different to your system's.

For a list of the formatting options, please see the GitHub page or the Packal page.

Examples

  • %d/%m/%Y — e.g. 21/01/2014
  • %A %B %d %Y — e.g. Wednesday March 12 2014
  • %A %d. %B %Y lang=de — e.g. Mittwoch 12. März 2014

Bug reports, feedback

Report any issues or feature requests either on GitHub or in this thread.

Licensing, thanks etc.

This Workflow is released under the MIT Licence.

It uses the docopt library.

Edited by deanishe
  • 4 weeks later...
Posted

This is great.

 

Any chance you could add a way to calculate the number of days between dates?

 

eg. it's 04-Apr and I want to know the number of days between 21-Mar and 10-Apr.

Posted

Calculating the days between two dates has nothing in common with this workflow code-wise (this one cannot understand dates, for example), so no, that's very unlikely.

  • 4 weeks later...
Posted

Hi. Great Workflow!

 

I have two questions:

 

My Mac computer uses EN_US as the default locale, but all my work is done in spanish. Is there anyway I can change the default locale to spanish?

Also, does the Workflow supports time?

 

 

Thank you!

Posted

No, you can't set a default locale. You'll have to set all your formats individually using lang=es (or whatever).

As soon as you've added one custom format, you can delete all the default ones (if you delete all the formats, the defaults will be re-added).

The workflow doesn't currently support time, but I might consider adding it if there's sufficient demand for it.

  • 1 month later...
Posted

I'm getting dates in en_US style even though I should be getting en_UK ones; `locale` in the terminal shows en_GB and the main language setting is United Kingdom. Is there something that I need to do to get the workflow to pick this up?

Posted (edited)

Alfred doesn't use your shell environment, which is what you see when you run locale or echo $LANG in Terminal.
 
The workflow takes its default locale from your system settings with defaults read -g AppleLanguages (it grabs the first result).
 
On my system, which has the preferred language set to "British English", I get:

(
"en-GB",
de,
en,
fr,
"zh-Hans",
"zh-Hant",
ja,
es,
…
…
…
)

 
Either change your Preferred languages in System Preferences under Language & Region so that "British English" is at the top, or append lang=en_GB to each of your formats, e.g:

dateadd %x lang=en_GB

 will give you 19/06/2014. 

The Region you have set in Language & Region is ignored, as a lot of users have it set to where they live but have their system set to use English/British English. This results in unusable locales like en_DE or de_IT.

Edited by deanishe
Posted

Thanks. After checking with `defaults read -g AppleLanguages` I discovered that I didn't have British English set as my language at all, but only the region as United Kingdom. Once I changed that everything was fine, as you might expect.

  • 2 years later...
Posted

Basically the same thing as this but using time:

 

Have multiple time formatting selections like you have date formats here.

 

Allow for time calculations like "now 36h" to show 36 hours from current time,etc. To be honest this seems like it would be less useful with time but who knows.

Posted

I'm just popping my head into this thread to let you all know that in the next Alfred release (3.4), there'll be date arithmetics added to snippets, making it possible to calculate dates (e.g. {date +7d +3h:long} to paste the date seven days and three hours from now in long format)

 

While @deanishe is very generous with his time, this might be a case where it's worth waiting til the next pre-release - of course, unless Dean fancies adding that to the workflow as well, as it's a convenient way to add these on the fly! :)

 

Cheers,

Vero

Posted
10 minutes ago, Vero said:

unless Dean fancies adding that to the workflow as well

 

No plans to spend any time on this workflow at the moment, tbh. I rarely use it any more.

  • 1 year later...
  • 3 years later...
  • 4 months later...
Posted

I downloaded the updated version of this (https://github.com/alfredapp/updated-third-party-python2-workflows/raw/main/Workflows/Relative Dates.alfredworkflow) but whenever I try to do anything the debugger shows:

 

ERROR: Relative Dates[Script Filter] Code 127: /Users/xxxxxxxxx/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/B3A19111-A2B7-4B4E-8420-C45346CCD9D0: line 2: python: command not found

 

Any ideas? I finally took the plunge to Monterey and so far all has gone pretty well. I just have this and one other workflow to try to get working again. Everything else I have figured out on my own.  Thanks!

Posted

Oh I see. I installed Python 3 but not Python 2. I thought the updated version used Python 3, which is why I was confused. I'll either add Python 2 or just bail on it. Thanks

Posted

I rather hesitate to post this pretty basic workflow here but it demonstrates (albeit with far less sophistication than the workflow under discussion) what you can do with date arithmetic in Alfred—and without any external dependence (in other words, you don't need Python, for example). Do note there's no evaluation of the validity of the input so you need to make sure you're using the date commands correctly (see Date arithmetic on this Alfred help page).

 

The workflow looks like this:

 

Workflow.thumb.jpg.d8a8ba5a17e7df45b3e29e35f15c58bb.jpg

 

The Keyword action simply responds to the date keyword and expects a <space> and an argument (e.g., -1Y -17D)—with the subtext giving examples of the correct fornat for the date arithmetic. The Arg & Vars utility is set up like this:

 

679703437_Argvars.thumb.jpg.a2cf09f35593bcaa0b9c096db434eb2e.jpg

 

and the Dialog Conditional like this:

 

Dialog.thumb.jpg.af5c9e1bd0094bcb2150ff2a3d0a87cf.jpg

 

After that it's merely a matter of noting that, of course, what you want to send to the clipboard is {var:newDate}. The notification simply confirms the relative date has been copied to the clipboard (rather than just letting the workflow die quietly leaving you wondering if it has actually done anything).

 

Stephen

Posted
10 hours ago, Stephen_C said:

I rather hesitate to post this pretty basic workflow

 

You shouldn’t hesitate, that’s an ingenious solution!

 

It’s always your choice, but I think you should start posting downloads of your Workflows. You may find them simple but they are well constructed and can serve as good starting points to others.

Posted
11 hours ago, vitor said:

t’s always your choice, but I think you should start posting downloads of your Workflows.

OK - you’ve pushed me off the diving board into deep water! 😀 With everything crossed (which, of course, doesn't add survival in the deep water!) the workflow is now available on Github.

 

Stephen

Posted

Thank you so much Stephen! I just downloaded several of your workflows and I'll keep an eye out for others in the future. Much appreciated.

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