Skip to content

Feature request: Range iterator with Step for NaiveDateTime #971

@seongs1024

Description

@seongs1024

Iterating over time range will give a great experience!

NaiveDate has iter_days() and iter_weeks() functions. But in case of NaiveDateTime, it seems necessary to set step_by() to use UNIX timestamps because the period is unknown when iterating over the range.

The request is as follows:

let ts_fmt = "%Y-%m-%d %H:%M";
let start = NaiveDateTime::parse_from_str("2023-02-22 00:00", ts_fmt).unwrap();
let end = NaiveDateTime::parse_from_str("2023-02-23 00:00", ts_fmt).unwrap();
let step = Duration::minutes(15);

// HERE
let lists = (start..end)
    .step_by(step)
    .map(|ts| {
        format!("HELLO: {}", ts);
    })
    .collect();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions