First of all many thanks to Kizitonwose for the original idea and already awesome library!
constdayInMillis=24*60*60*1000;// Represent a day in millisecondsIf you want to use the original files
importtimextfrom'../src/index';import*asufrom'../src/units';// Create by using constructor methodconstfiveCenturies=timext(5,u.CE);consttenDecades=timext(10,u.DC);consttwoYears=timext(2,u.Y);constoneWeek=timext(1,u.W);constthreeDays=timext(3,u.D);constelevenHours=timext(11,u.H);constsixMinutes=timext(6,u.M);constfiftySeconds=timext(50,u.S);consthundredMillis=timext(100,u.MS);// Convert to other time unitsconstoneDayInMillis=timext(1,u.D).inMillis();// Converts one day into millisecondsconsttwoWeeksInHours=timext(2,u.W).inHours();// Converts two weeks into hours// "operator" + - * /constduration=timext(1,u.D).plus(timext(6,u.H));constdifference=timext(34,u.M).minus(timext(420,u.S));constmultipliedDuration=timext(2,u.W).multiply(1.5);constdividedDuration=timext(2500,u.MS).divide(2);If you want to use the minified script from the releases
import'timext.min';// Create by using number extensionsconstfiveCenturies=Number(5).toCenturies();// returns timext(5, u.CE)consttenDecades=Number(10).toDecades();// returns timext(10, u.DC)consttwoYears=Number(2).toYears();// returns timext(2, u.Y)constoneWeek=Number(1).toWeeks();// returns timext(1, u.W)constthreeDays=Number(3).toDays();// returns timext(3, u.D)constelevenHours=Number(11).toHours();// returns timext(11, u.H)constsixMinutes=Number(6).toMinutes();// returns timext(6, u.M)constfiftySeconds=Number(50).toSeconds();// returns timext(50, u.S)consthundredMillis=Number(100).toMillis();// returns timext(100, u.MS)// Return in other time unitsconstoneDayInMillis=Number(1).toDays().inMillis();// Returns one day in milliseconds === 24 * 60 * 60 * 1e3consttwoWeeksInHours=Number(2).toWeeks().inHours();// Returns two weeks in hours === 2 * 7 * 24// Convert to other time unitsconstoneDayInMillis=Number(1).toDays().toHours();// Converts one day into timext(24, u.H)consttwoWeeksInHours=Number(120).toMinutes().toHours();// Converts 120 hours into timext(2, u.H)// add timext to date using date extensionsconstinFiveDays=Date.now.plus(Number(5).toDays());constthreeWeeksAgo=Date.now.minus(Number(3).toWeeks());Since version 0.6.0 TimeXt has new extensions for the long type to display this number value in a human readable string format. Since version 0.7.0 TimeXt supports decimal numbers. Since version 0.8.0 TimeXt has values for decades and centuries and more precise conversions
constreadableStringFromMillis=Number(34325055574).formatMillis()// 56 weeks, 5 days, 6 hours, 44 minutes, 15 seconds, 574 millisecondsconstreadableStringFromSeconds=Number(4350554).formatSeconds()// 7 weeks, 1 day, 8 hours, 29 minutes, 14 secondsconstreadableStringFromMinutes=Number(432555).formatMinutes()// 42 weeks, 6 days, 9 hours, 15 minutesconstreadableStringFromHours=Number(4574).formatHours()// 27 weeks, 1 day, 14 hoursconstreadableStringFromDays=Number(24.5).formatDays()// 3 weeks, 3 days, 12 hoursconstreadableStringFromWeeks=Number(24.5).formatWeeks()// 24 weeks, 3 days, 12 hours| Jonas Schubert |
TimeXt-JavaScript is distributed under the MIT license. See LICENSE for details.
MIT License
Copyright (c) 2018 - 2020 Jonas Schubert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
