Giter VIP home page Giter VIP logo

Comments (3)

Falc avatar Falc commented on June 28, 2024

At the moment it allows:

  • Total number, using uppercase: {S} will print "63" seconds.
  • Rest, using lowercase: {s} will print "3" seconds, this allows to represent the value with multiple units (63 seconds -> 1 minute and 3 seconds.
  • Units without leading zeros, using a single letter: {s} will print "3" seconds.
  • Units with leading zeros, using double letters: {ss} will print "03" seconds.

It is difficult to add more formatting options while keeping it simple. It could create conflicts since a format option would force leading zeros and another one would truncate. I recommend you to do it in two steps inside on_tick(): first of all get the data and then process it the way you like:

on_tick(): function() {
    var mins = timer1.lap('{mm}');
    var secs = timer1.lap('{ss}');
    var ms = timer1.lap('{ll}').substring(0,1);
    document.querySelector('#timer').innerHTML = mins + ":" + secs + "." + ms;
}

Does this help you?

from tock.js.

sergeevabc avatar sergeevabc commented on June 28, 2024

Your solution works perfectly fine, Aitor!
Thank you for verbose feedback as well.

from tock.js.

sergeevabc avatar sergeevabc commented on June 28, 2024

As an addendum.
It seems timer1.lap('{ll}')[0];or timer1.lap('{ll}').charAt(0); are faster* than substring(0,1);

*Test3, Test52

from tock.js.

Related Issues (4)

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.