Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nv-facutil-clock

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nv-facutil-clock

clock,date,generator,stream,cron

  • 1.0.16
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-98.53%
Maintainers
0
Weekly downloads
 
Created
Source

nv-facutil-clock

  • nv-facutil-clock simple date util
  • simplified version of jsnoz
  • Auto mode
  • Manual mode: stream/generator
  • simple Cron
  • without any dependancy
  • without README, uncompressd 8K

install

  • npm install nv-facutil-clock

usage

example

const {Auto,Manual,Cron} = require("nv-facutil-clock");

auto

var auto = new Auto()

> auto.zone
'+0800'
> auto.str()
'2021-03-05 23:55:04.322 +0800'
> auto.dict()
{
  y: 2021,
  m: 3,
  d: 5,
  h: 23,
  min: 55,
  s: 10,
  ms: 853,
  ts: 1614959710.853,
  mts: 1614959710853,
  zone: '+0800',
  soffset: 28800,
  msoffset: 28800000
}
> auto.sdict()
{
  y: '2021',
  m: '03',
  d: '05',
  h: '23',
  min: '55',
  s: '13',
  ms: '961',
  ts: 1614959713.961,
  mts: 1614959713961,
  zone: '+0800',
  soffset: 28800,
  msoffset: 28800000
}
>

manual

var manual = new Manual()

> manual
Manual [2021-03-05 23:57:06.937 +0800] {}
> manual
Manual [2021-03-05 23:57:06.937 +0800] {}
>
> manual.next_d()
'2021-03-06 23:57:06.937 +0800'
> manual
Manual [2021-03-06 23:57:06.937 +0800] {}
> manual.next_d()
'2021-03-07 23:57:06.937 +0800'
> manual
Manual [2021-03-07 23:57:06.937 +0800] {}
> manual.prev_d()
'2021-03-06 23:57:06.937 +0800'
> manual.prev_d()
'2021-03-05 23:57:06.937 +0800'
>

> manual.next_s()
'2021-03-05 23:57:07.937 +0800'
> manual
Manual [2021-03-05 23:57:07.937 +0800] {}
> manual.prev_s()
'2021-03-05 23:57:06.937 +0800'
> manual
Manual [2021-03-05 23:57:06.937 +0800] {}
>
> manual.prev_ms()
'2021-03-05 23:57:06.936 +0800'
>
> manual.prev_m()
'2021-02-05 23:57:06.936 +0800'
>
> manual.next_y()
'2022-02-05 23:57:06.936 +0800'
> manual.next_y()
'2023-02-05 23:57:06.936 +0800'
>

> manual.next_h(3)
'2023-02-06 02:57:06.936 +0800'
>

stream generator

var g = manual.nd_gen$$()
> g.next()
{ value: '2021-03-06 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-07 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-08 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-09 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-10 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-11 16:10:37.626 -0000', done: false }
>

var g = manual.nd_gen$$(5)
> g.next()
{ value: '2021-03-16 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-21 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-26 16:10:37.626 -0000', done: false }
>

var g = manual.pd_gen$$(3)
> g.next()
{ value: '2021-03-23 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-20 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-17 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-14 16:10:37.626 -0000', done: false }
> g.next()
{ value: '2021-03-11 16:10:37.626 -0000', done: false }
>

var c =0;
for(let each of manual) {
    if(c<10) {
        console.log(each)
    } else {

        break
    }
    c = c+1
}
/*
2021-03-11 16:13:38.322 -0000
2021-03-11 16:13:38.323 -0000
2021-03-11 16:13:38.324 -0000
2021-03-11 16:13:38.325 -0000
2021-03-11 16:13:38.326 -0000
2021-03-11 16:13:38.327 -0000
2021-03-11 16:13:38.328 -0000
2021-03-11 16:13:38.329 -0000
2021-03-11 16:13:38.330 -0000
2021-03-11 16:13:38.331 -0000

*/

Cron

const {Cron} = require("nv-facutil-clock")
var frequency =1000
function task_func(a,b,c) {
    console.log(a,b,c,(new Date()).getSeconds())
}
function cond_func(d) {
    /*
    d = {
      y: year,m: month,d: day,
      h: hour,min: minutes,s: seconds,ms: ms,
      ts: 1614959710.853,
      mts: 1614959710853,
    }
    */
    if(d.s % 7 === 0) {return(true)}
}

var cron = new Cron(frequency,cond_func,task_func,100,200,300)

> cron.launch()
undefined
> 100 200 300 56
100 200 300 0
100 200 300 7
100 200 300 14

()cron.clear100 200 300 21
undefined
> cron.clear()
undefined
>

stop watcher

    > var stop_watch = new StopWatch()
    undefined
    > stop_watch
    StopWatch [start_at:undefined  duration:undefined  end_at:undefined] {}
    >
    > var p = stop_watch.start()
    undefined
    > p
    Promise {
      <pending>,
      [Symbol(async_id_symbol)]: 68,
      [Symbol(trigger_async_id_symbol)]: 5,
      [Symbol(destroyed)]: { destroyed: false }
    }
    > stop_watch
    StopWatch [start_at:1639454327229  duration:7695  end_at:undefined] {}
    > stop_watch
    StopWatch [start_at:1639454327229  duration:9265  end_at:undefined] {}
    > stop_watch
    StopWatch [start_at:1639454327229  duration:10850  end_at:undefined] {}
    >
    > stop_watch
    StopWatch [start_at:1639454327229  duration:13856  end_at:undefined] {}
    > stop_watch.stop()
    { start_at: 1639454327229, end_at: 1639454350716, costed: 23487 }
    >
    > p
    Promise {
      { start_at: 1639454327229, end_at: 1639454350716, costed: 23487 },
      [Symbol(async_id_symbol)]: 68,
      [Symbol(trigger_async_id_symbol)]: 5,
      [Symbol(destroyed)]: { destroyed: false }
    }
    >  stop_watch
    StopWatch [start_at:1639454327229  duration:23487  end_at:1639454350716] {}
    >

METHODS

Auto

auto.dict                  auto.sdict
auto.str                   auto.zone

Manual

manual.dict                  manual.nd_gen$$              manual.next_d
manual.next_h                manual.next_m                manual.next_min              manual.next_ms
manual.next_s                manual.next_w                manual.next_y                manual.nh_gen$$
manual.nm_gen$$              manual.nmin_gen$$            manual.nms_gen$$             manual.ns_gen$$
manual.ny_gen$$              manual.pd_gen$$              manual.ph_gen$$              manual.pm_gen$$
manual.pmin_gen$$            manual.pms_gen$$             manual.prev_d                manual.prev_h
manual.prev_m                manual.prev_min              manual.prev_ms               manual.prev_s
manual.prev_w                manual.prev_y                manual.ps_gen$$              manual.py_gen$$
manual.sdict                 manual.str                   manual.zone

Cron

cron.clear                 cron.cond_func             cron.frequency             cron.is_running
cron.launch                cron.task_func             cron.zone

LICENSE

  • ISC

Keywords

FAQs

Package last updated on 21 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc