Skip to content

Extract more information from duration/date/filesize objects #14469

@bew

Description

@bew

Related problem

Hello o/

I like to use nushell for date/duration/filesize conversions, but there is something that I need from time to time that seems to be unavailable at the moment:

  • converting to a subset of the value, like hours to milliseconds to get the total number of milliseconds in a number of hours (~ 1hr | get total_ms => 3_600_000ms)
  • getting a superset of the value, like seconds to hours to get the number of hours in a (potentially large) number of seconds (~ 123456sec | get total_hours => 34hr)

These example could be useful for duration but could also be useful for filesize or date objects 🤔

I've found that we can do 123456sec | into record to get as data the information in the humanized form 1day 10hr 17min 36sec but even here we are missing some fields like milliseconds or weeks that could be needed when manipulating unknown values.

Describe the solution you'd like

Something like this:
1wk | into record | get total_hours
(date now) - 2019-05-01 | into record | get total_days
12sec | into record | get hours (0)

Describe alternatives you've considered

I could handle all edge cases, do sums myself, but it feels like a huge pain for seemingly simple operations 🤔

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:datetime-handlingSemantics and implementation of the datetime/duration types and commandscategory:enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions