deanishe Posted March 12, 2014 Posted March 12, 2014 (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.DownloadingGet 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 formatsThe 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, feedbackReport 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 March 21, 2014 by deanishe cands, vanderholm and parekh 3
gingerbeardman Posted April 4, 2014 Posted April 4, 2014 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.
deanishe Posted April 4, 2014 Author Posted April 4, 2014 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.
judas Posted April 30, 2014 Posted April 30, 2014 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!
deanishe Posted April 30, 2014 Author Posted April 30, 2014 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.
Tom Posted June 19, 2014 Posted June 19, 2014 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?
deanishe Posted June 19, 2014 Author Posted June 19, 2014 (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 June 19, 2014 by deanishe Tom 1
Tom Posted June 19, 2014 Posted June 19, 2014 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.
alwaysaugust Posted April 28, 2017 Posted April 28, 2017 Any chance of a sister workflow that treated time in the same way? Loving this one so far. Thank you so much.
deanishe Posted April 28, 2017 Author Posted April 28, 2017 Thanks. What do you mean by "treat[ing] time in the same way"? Like, if I added support for -2h or +90m?
alwaysaugust Posted May 2, 2017 Posted May 2, 2017 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.
xilopaint Posted May 3, 2017 Posted May 3, 2017 Would it be possible to add a feature for generating relative dates considering working days only? (e.g. date +18wd)
Vero Posted May 3, 2017 Posted May 3, 2017 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
deanishe Posted May 3, 2017 Author Posted May 3, 2017 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.
xilopaint Posted May 3, 2017 Posted May 3, 2017 @Vero, some people requested a working days calculation feature in the excellent MuppetGate's workflow but he couldn't find a way to implement the feature. So please, send my request to Andrew.
optimus1509 Posted March 22, 2022 Posted March 22, 2022 (edited) @deanisheAny chance this can be updated to python3? Edited March 22, 2022 by optimus1509 kisonay 1
Sticky Posted August 19, 2022 Posted August 19, 2022 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!
vitor Posted August 20, 2022 Posted August 20, 2022 @Sticky You have to follow the instructions in full and start by readding Python 2.
Sticky Posted August 22, 2022 Posted August 22, 2022 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
Stephen_C Posted August 23, 2022 Posted August 23, 2022 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: 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: and the Dialog Conditional like this: 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 vitor 1
vitor Posted August 23, 2022 Posted August 23, 2022 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. Stephen_C 1
Stephen_C Posted August 24, 2022 Posted August 24, 2022 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 JJJJ 1
Sticky Posted August 24, 2022 Posted August 24, 2022 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.
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