Giter Site home page Giter Site logo

timer-util's Introduction

timer-util

a simple tool to compute time: easy to config, and easy to use. a simple example:

use std::time::Duration;
use time::OffsetDateTime;
use timer_util::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // 定时器配置(timer configs):
    // every weekday or 1st..10st 15st..25st every month    每周六 或者每月的1号到9号、15号到24号
    // every hour   每小时
    // 0st/10st/20st/30st/40st/50st minuter 第0/10/20/30/40/50分钟
    // 0st/30st second  第0/30秒
    let conf = DayHourMinuterSecondConf::default_week_days(WeekDays::default_value(W6))
        .conf_month_days(MonthDays::default_range(D1..D10)?.add_range(D15..D25)?)
        .build_with_hours(Hours::default_all())
        .build_with_minuter(Minuters::default_array(&[M0, M10, M20, M30, M40, M50]))
        .build_with_second(Seconds::default_array(&[S0, S30]));

    // let next_seconds = conf.next()?;

    let handle = tokio::spawn(async move {
        loop {
            let off_seconds = conf.next().unwrap();
            println!("next seconds: {}", off_seconds);
            tokio::time::sleep(Duration::from_secs(off_seconds)).await;
            // println!("{:?}", OffsetDateTime::now_local().unwrap());
        }
    });
    handle.await.unwrap();
    Ok(())
}

timer-util's People

Contributors

jm-observer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.