Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert tomorow and yesterday dates? #311

Closed
jrcacd opened this issue Jun 5, 2020 · 23 comments
Closed

How to insert tomorow and yesterday dates? #311

jrcacd opened this issue Jun 5, 2020 · 23 comments
Labels
RFNR Ready to be shipped in next release

Comments

@jrcacd
Copy link

jrcacd commented Jun 5, 2020

No description provided.

@federico-terzi
Copy link
Collaborator

Hey,

This could be a very useful feature indeed, I'll add it to the roadmap!

Cheers :)

@femtocept
Copy link

femtocept commented Jun 7, 2020

You can do it with shell integration if your system has the date program.

  - trigger: ";tomorrow"
    replace: "Tomorrow is {{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date -v+1d +%D"
  • The +1d is the time adjustment and can also take - for past times.
  • The +%D controls the formatting and allows you to do other things like make it say "Monday" with %A (look up the strftime codes for more options). As of writing this, tomorrow is Monday.
  • Also the framing text in the replacement is just for the demo but you can also just make it say {{output}} if you only want the date itself and no message.

I don't think this is helpful for windows users, though.

@mrjackphil
Copy link

For those who uses Windows10 with Linux Subsystem

  - trigger: ":1date"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "bash -c 'date +%Y-%m-%d -d +1day'"

@federico-terzi
Copy link
Collaborator

Hey @mrjackphil,
Thank you for pointing this out. To complement your answer, I'd like to say that since espanso 0.6.0 you can use WSL directly with the "wsl" parameter:

  - trigger: ":1date"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date +%Y-%m-%d -d +1day"
          shell: wsl

Cheers :)

@mrjackphil
Copy link

mrjackphil commented Jun 14, 2020

@federico-terzi Just tried it and it works not as I expected. Maybe because of Cyrillic symbols or different format. While my configuration returns:

2020-06-15

when tried yours I receive:

������� �������⨬�� ���.
������ ����� ���� (��-��-��): 

@federico-terzi
Copy link
Collaborator

Thank you for pointing that out @mrjackphil, this seems like a bug! Could you please tell me which language are you using? If I manage to reproduce it I might be able to get a solution :)

@mrjackphil
Copy link

I'm using a Windows 10 Home Edition. Russian language.

@federico-terzi
Copy link
Collaborator

All right, thank you @mrjackphil

@mrrcollins
Copy link

Just a heads up, date under macOS needs the -v argument, but that will cause date under Linux to give an error. If you use Espanso under both OSes, you'll probably need a script to use the correct version of date.

@federico-terzi
Copy link
Collaborator

@mrrcollins thanks for your feedback, I've opened an issue to make this handling more convenient #353

@federico-terzi
Copy link
Collaborator

Just wanted to let you know that the next release (0.7.0) will support this out of the box. In particular, you will be able to specify an offset parameter that takes the number of seconds of offset.
For example:

  - trigger: ":yesterday"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: -86400
  - trigger: ":tomorrow"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: 86400

@federico-terzi federico-terzi added the RFNR Ready to be shipped in next release label Aug 15, 2020
@jrcacd
Copy link
Author

jrcacd commented Aug 16, 2020

Very good!!!

@jczanfona
Copy link

PLS @mrjackphil
What is wrong here?...

  - trigger: ":fecha"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date /t"

It does nothing! (W10)

@federico-terzi
Copy link
Collaborator

federico-terzi commented Jan 1, 2021

@jczanfona You should be able to get it working by specifying the cmd shell:

  - trigger: ":fecha"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date /t"
          shell: cmd

By default espanso uses Powershell on Windows, which as far as I know does not support the date command

Cheers :)

@jczanfona
Copy link

jczanfona commented Jan 2, 2021

TX a lot @federico-terzi
Great sw !!!

@mhofherr
Copy link

Hi,

is there a good possibility to make this dynamic? On MAC OS I am using Keyboard Maestro to create a popup-box, enter a number X, and the output is the future date (today + X days). I would like to do something similar on Windows with espanso as well. Any ideas for that?

Thanks,
Matthias

Just wanted to let you know that the next release (0.7.0) will support this out of the box. In particular, you will be able to specify an offset parameter that takes the number of seconds of offset.
For example:

  - trigger: ":yesterday"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: -86400
  - trigger: ":tomorrow"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: 86400

@federico-terzi
Copy link
Collaborator

Hey @mhofherr,

is there a good possibility to make this dynamic?

Not out of the box, but you should be able to do so with a custom script :)

Here's something to get started:

Cheers :)

@mhofherr
Copy link

Thanks a lot for fast reply! Will have a look at the indicated examples.

@mhofherr
Copy link

Followup-question: I copled together the following:

# Test
  - trigger: ".mydate"
    replace: "{{mydate}}"
    vars:
    - name: form1
      type: form
      params:
        layout: |
          Add days {{name}}
    - name: newdate
      type: shell
      params:
       cmd: "(Get-Date).AddDays($ESPANSO_FORM1_NAME).ToString('yyyy-MM-dd')"
       shell: powershell

I know that "(Get-Date).AddDays(1).ToString('yyyy-MM-dd')" delivers today's date +1 on powershell. With the variable it does not work. Do you have any insights what I am doing wrong here (Windows 10; Powershell)?

Thanks,
Matthias

@federico-terzi
Copy link
Collaborator

Hey @mhofherr ,

I'm not a PowerShell expert, but according to this post you might want to use ${ESPANSO_FORM1_NAME} to access the variable, such as:

  - trigger: ".mydate"
    replace: "{{mydate}}"
    vars:
    - name: form1
      type: form
      params:
        layout: |
          Add days {{name}}
    - name: newdate
      type: shell
      params:
       cmd: "(Get-Date).AddDays(${ESPANSO_FORM1_NAME}).ToString('yyyy-MM-dd')"
       shell: powershell

Let me know if that helps!

Cheers :)

@mhofherr
Copy link

Almost, but your link did the trick => the following works for me:
cmd: "(Get-Date).AddDays(${env:ESPANSO_FORM1_NAME}).ToString('yyyy-MM-dd')"

Thanks again,
Matthias

@andrej1919
Copy link

Hey,

This code does not work. Maybe I am too optimistic when it comes to injecting variables?

    # calc days
  - trigger: "ddc"
    replace: "{{result_day}}"
    vars:
    - name: frm_day                       # get user input (number of days)
      type: form
      params:
        layout: |
         Enter number of days: [[days]]
    - name: calc_offset                   # calculate offset in seconds
      type: shell
      params:
       cmd: "echo '86400 * {{frm_day.days}}' | bc" 
    - name: result_day
      type: date
      params:
        offset: "{{calc_offset}}"         # this variable is not injected
        format: "%Y-%m-%d"

Thanks,
Andrej

@andrej1919
Copy link

Hey,

I found a solution:

    # calc days
  - trigger: "ddc"
    replace: "{{result_day}}"
    vars:
    - name: frm_day                       # get user input (number of days)
      type: form
      params:
        layout: |
          Enter number of days: [[days]]
    - name: result_day                   # calculate offset in shell
      type: shell
      params:
       cmd: "date -d \"{{frm_day.days}} days\" -u +%Y-%m-%d" 

But I am still curious to know whether offset parameter can receive an injected variable.

Cheers,
Andrej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFNR Ready to be shipped in next release
Projects
None yet
Development

No branches or pull requests

8 participants