Giter Site home page Giter Site logo

eddiejibson / dubium Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 1.0 895 KB

Light Javascript date and time utilities (formatting, ranges e.t.c)

License: MIT License

JavaScript 100.00%
javascript time formatting ranges nodejs node moment dubium date-time date

dubium's Introduction


Light (1kb gzipped) Javascript date and time utilities (formatting, ranges e.t.c).

If you appreciate this project, please ๐ŸŒŸ it on GitHub.

Dubium works both in the browser and with node.

For browser use, either host the dubium.js file yourself (By downloading the current release here) or use a CDN (and, yes, it's free):

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dubium.min.js"></script>

As for NodeJS, it can be included like so:

const dubium = require("dubium");

Example

// In this example, if the date is not passed in, we'll pretend it's currently
// Febuary 1, 1970 19:30:00 UTC.

// .format returns the current date and/or time in a formatted manor
dubium.format("DD/MM/YYYY hh:mm:ss") // 01/02/1970 19:30:00
dubium.format("MM/DD/YYYY H:mm:ss a") // 02/01/1970 7:30:00 pm
dubium.format("DD/MMM/YY H:mm:ss A") // 01/Mar/70 7:30:00 PM
dubium.format("DD/MMMM/YY H:mm:ss A") // 01/March/70 7:30:00 PM

// You can also pass in a date to format:
dubium.format("DD/MM/YYYY hh:mm:ss", 1554159037369); // 01/04/2019 23:50:37
dubium.format("DD/MM/YYYY hh:mm:ss", "Fri, 02 Feb 1996 03:04:05 GMT"); // 02/02/1996 03:04:05

// You may unformat a string to get the epoch integer:
dubium.unformat("01/March/70 7:30:00 PM", "DD/MMMM/YY H:mm:ss A"); // 3163604400000

// You can get all the day value from a range of dates (inclusive of the ones being passed in)...
dubium.daysInRange(1554160761053, 1554333561053) // Array(3) [ 1554160761053, 1554247161053, 1554333561053 ]

// You can also get the range of the start of the week and end
dubium.getWeekRange() //Array [ 1554073200000, 1554677999999 ]
// Obviously you can pass an epoch value, too, if you want:
dubium.getWeekRange(3163604400000); // Array [ 3163446000000, 3161375999999 ]

// And, yeah, that's pretty much it... 
// These functions will be improved and added upon soon, too.

Benchmarks

Tested the speed of formatting and unformatting in Chrome 75 on Windows 10.

See it for yourself here on jsPerf.

Library Ops/sec
Dubium 197,278
DayJS 108,859
MomentJS 56,163

Development

Building dubium for browser:

npm run build

dubium's People

Contributors

eddiejibson avatar lierrmm avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

raulc27

dubium's Issues

IE11 syntax error

Hi,

The main property in the package json should point to the built version of the lib in the dist folder(dist/dubium.min.js), so I could import it directly.

Thank you

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.