Code Monkey home page Code Monkey logo

goodtimer's People

Contributors

dependabot[bot] avatar nickpalenchar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nick-nyllabs

goodtimer's Issues

Detects time units within string

d,h,m,s,ms will automatically parse that unit of time, even if not in the right order.

"3h" = 3:00:00
"40m3h = 3:40:00

If more numbers without units are added, they take the next unit of measurment

"3h30" = 3:30:00
"3h30:4 = 3:30:04

fmtTime for plural words

Ability to add words (usually a human name for the unit), that will automatically be pluralized if the value is anything but 1.

timer.fmtTime('%S {%s:second} left') // => "10 seconds left", "1 second left"

signature proposed

{%unit:WORD}

fmtTime options object

timeStrs are the abbreviations for full names (i.e., 'M' or 'minutes')

{
  round | floor | ceil: 'timeStr',
  exclude: 'timeStr', // remove all values up to and including timeStr, from end
}

Time class

"Time" is currently represented by an array of numbers (such as [10,0] for 10 mins). Comparing them is cumbersome.

Make a Time class that allows some additional functions such as:

math - add and subtract
compasinons - compare if time is greater, less than, or equal to another time.
UI - format string

where possible, methods should be similar in name to Dates

advanced time parsing

english-like parsing:

two years and seven days
10 minutes
1 second
3 second

Main qualities:

  • numbers can be ints or written out.
  • and can be added without interfearing

`onTime` functions

functions fire on onTimeout and onInterval, but OnTime should be added to allow users to add arbitrary events whenever they please.

As TimerOptions

new Timer("5:00", { 
  onTime: {
    "2:00": showRunningLowOnTime,
    "0:30": showVeryRunningLowOnTime
  }
});

As a method on a timer

const timer = new Timer("5:00");
timer.onTime("2:00", showRunningLowOnTime);
timer.onTime("0:30", showVeryRunningLowOnTime);
```js

## clearing `onTime` events.

```js
timer.clearOnTime("2:00");
// returns: true if a function existed and was removed, false otherwise

Changes

This effectively makes onTimeout a function for { onTime: "0:00" }, and should be refactored as such.

Add browser side version

Is your feature request related to a problem? Please describe.
Can be a good thing add also a client version.

Describe the solution you'd like
Add the javascript client side version.

Describe alternatives you've considered
Now I can only use goodtimer with node js and not within a browser...

Additional context
/

options object and corresponding options class method

divider , defalut ":" character used to seperate units in showUI methods

minute/hr/dayFunction: to invoke the function on each interval unit passed

immediateInterval( default false : immediately calls the interval function when the timer is instantiated. (sholdu this be default true??????)

UIPadding <second|minute|hour|day> : - zero padding (and zeros when no value remaning) defult true for seconds only.

protect default: false - prevents the new timer object from being destroyed via .destroy()

can also call these of the same name on Timer.options

Pass `this` to `onInterval`/`onTimeout` handler functions to allow arrow functions

only function declarations can be used for access to timer via, this. Arrow functions's lexical scoping breaks the relationship. But instead, timer can pass its self (this) to the callbacks first argument, which can allow arrow functions.

new Timer('1m', { onTimeout: function() {
    this.reset();
}});

can be

new Timer('1m', { onTimeout: (timer) => timer.reset() });

Max and min units in .toString

Enchance .toString() to be .toString(startingUnit?, endUnit?).

startingUnit takes the floor of that unit.

time.toString(); // -> "03:15.325"
time.toString('s'); // -> "03:15"

Passing a falsey value results in no starting unit.

endUnit adds any larger units to the end unit.

time.toString(); // "03:15.325"
time.toString(null, 's'); // "95.325"

cap timers at a unit of time.

we might want to display 30 hours as 30 hours rather than 1 day and 6 hours. Allow the ability to cap.

new Timer('30:00:00', { maxUnit: 'hours' });

the Time class has the same ability

new Time('30:00:00', { maxUnit: 'hours'});

Timers/Times can be dynamical adjusted with setMaxUnit

Other methods where its useful:

Timer.fmtTime('%h hours', {maxUnit: 'hours'});

able to override unit transfer in string

prevent rounding to the next appropriate unit with ! appended.

"70!" = :70
"100m!" = 100:00

! works only on largest unit, so all other places should be ignored and rounded.

10:60! = 11:00

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.