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

file: add doc on how to convert epoch seconds to datetime #53357

Merged
merged 1 commit into from Mar 7, 2019

Conversation

jborean93
Copy link
Contributor

SUMMARY

Add an example of how to convert a stat time output, or seconds since epoch to the datetime format expected by the file module.

ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

file

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. files Files category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Mar 5, 2019
file:
path: /etc/another_file
state: file
access_time: '{{ "%Y%m%d%H%M.%S" | strftime(stat_var.stat.atime) }}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think your strftime template is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it worked for me, what part do you think isn't correct?

Copy link
Member

@bcoca bcoca Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i always used '%s' .. won't the above print yearmonthdayhourminute. seconds?

also i think we did strftime wrong, i would expect dateortime|strftime('format')

Copy link
Member

@bcoca bcoca Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jborean93 i think you are doing the opposite transformation, you are turning 'seconds/epoch' into a date string

nvmd, its opposite of what user wanted to implement, but how we can get 'epoch' to work with current module ... took me a bit to square the circle .. moving on ... nothing to see...

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Mar 5, 2019
@jborean93 jborean93 merged commit 6e16877 into ansible:devel Mar 7, 2019
@jborean93 jborean93 deleted the file-datetime branch March 7, 2019 02:40
@fizista
Copy link

fizista commented Mar 8, 2019

In this way it is not possible to set the time with greater accuracy than a second. The strftime filter returns values with an accuracy of one second. The os.utime function is able to set the time with an accuracy of microseconds.

My previous patch allowed just such modifications.

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. files Files category module This issue/PR relates to a module. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants