1.0.33 β€’ Published 1 year ago

@myno_21/time v1.0.33

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@Fetch/time

πŸ’­ Easiest way to do things like formatting-converting with some really unique options.

@myno_21/time

Version Downloads

GitHub Actions

Update πŸ‘‹

  • There was a issue going on with the package. A lot of typescript users were having some problems that they cannot use the package. So in the latest patch, the types is now created. So you can freely use the package with TypeScript so as with the normal JavaScript

What's new? πŸ”—

Added some more features:

  • getFormattedMilliseconds (Formats milliseconds into an object containing days, hours, minutes, seconds and milliseconds) ~
  • Added the "isValidDate" function to the package.
  • Added the "formatAsPercentage" function to the package.
  • getCurrentFormattedTime (Formats the current time in a bit cleaner manner)
  • Timer (Sets a complete timer for you. With events.)
  • Seconds To Duration (Converts seconds to a duration.)

Features πŸ“£

  • Converts localized time to Unix-Epoch timestamps.
  • Converts a Unix-Epoch timestamp to a human readable time.
  • Get a timezone of a country by it's capital city/country name.
  • Get the time in a localized format -> "in xyz seconds"/"xyz seconds ago"
  • Get a formatted time.
  • Converts number to percentage.
  • Get the current in a formatted manner with some cool options.
  • Sets a timer for your. With the timer events.
  • Converts seconds to a proper formatted duration.

❔Installation

$ npm install @myno_21/time

Unix-Converter

//CommonJS
const { getUnix } = require("@myno_21/time");

//ECMAScript/ESM
import { getUnix } from "@myno_21/time";

getUnix(`4 days`); // β†’ 1649923729

Timezone

//CommonJS
const { getTimezone } = require("@myno_21/time");

//ECMAScript/ESM
import { getTimezone } from "@myno_21/time";

getTimezone("India" || "New Delhi"); // β†’ Asia/Kolkata 4/10/2022, 1:40:14 PM, India/IN

Formatted Time

// CommonJS
const { getFormattedTime } = require("@myno_21/time");
// ECMAScript
import { getFormattedTime } from "@myno_21/time";

console.log(getFormattedTime("2022-12-01Z00:00:00.000")); // Default ➟ 05:30 AM
console.log(getFormattedTime(`2022-12-01Z00:00:00.000`), { longFormat: true }); // longFormat ➟ Thursday, 05:30 AM

Epoch-Timestamp/MIlliseconds to Date

//CommonJS
const { getHumanReadableTime } = require("@myno_21/time");

//ECMAScript/ESM
import { getHumanReadableTime } from "@myno_21/time";

getHumanReadableTime("1649923729", { Lengthy: true }); // β†’ April 14th 2022, 1:38:49 pm

Time From Now

const { getTimeFromNow } = require("@myno_21/time");

//ECMAScript/ESM
import { getTimeFromNow } from "@myno_21/time";

const agoData = getTimeFromNow(`2020-04-04`);
const inData = getTimeFromNow("2030-04-04");

console.log(agoData); // ➟ 2 years ago
console.log(inData); // ➟ in 8 years

Formatted-Milliseconds

const { getFormattedMilliseconds } = require("@myno_21/time");

//ECMAScript/ESM
import { getFormattedMilliseconds } from "@myno_21/time";

const data = getFormattedMilliseconds(103680000); // The return form is in a object so you can also target a property like: getFormattedMilliseconds(103680000).days || hours || minutes || seconds

console.log(data); // ➟ { days: 2, hours: 18, minutes: 43, seconds: 12, milliseconds: 0 }

β˜… CurrentFormattedTime

// CommonJS
const { getCurrentFormattedTime } = require("@myno_21/time");
// ECMAScript
import { getCurrentFormattedTime } from "@myno_21/time";
// Default Option
const _resultDefault = getCurrentFormattedTime();
// Option 1
const _resultshowInShortManner = getCurrentFormattedTime({
  showInShortManner: true,
});
// Option 2
const _resultWithshowTimeOnly = getCurrentFormattedTime({
  showTimeOnly: true,
});
// Default:
console.log(_resultDefault); //--> September 05, Monday 01:11 PM
// With the option "showInShortManner"
console.log(_resultshowInShortManner); //--> Sep 05, Mon 01:11 PM
// With the option "showTimeOnly"
console.log(_resultWithshowTimeOnly); // --> 01:11 PM

β˜… Timer

// CommonJS
const { Timer } = require("@myno_21/time");
// ECMAScript
import { Timer } from "@myno_21/time";
const timer = new Timer("2minutes"); //Setting the timer.

timer.on("setTime", (timeObject, remainingTime) => {
  // Do something with it.
  console.log("The timer is now set!"); // Logging when the timer is set.
});
timer.on("timeEnd", (timeObject, setOn) => {
  // Do something with it.
  console.log("The time is now over!"); // Logging when the timer is ended.
});
  • β˜… Seconds To Duration

// CommonJS
const { secondsToDuration } = require("@myno_21/time");
// ECMAScript
import { secondsToDuration } from "@myno_21/time";

const timeInHours = secondsToDuration(3640);
const timeInSeconds = secondsToDuration(20);
const timeinMinutes = secondsToDuration(610);

console.log(timeInHours); // --> 01 : 00 : 40
console.log(timeInSeconds); // --> 00 : 20
console.log(timeinMinutes); // --> 10 : 10
  • β˜… Format Number

// CommonJS
const { formatNumbers } = require("@myno_21/time");
// ECMAScript
import { formatNumbers } from "@myno_21/time";

const result = formatNumbers(2234);

print(result);
// Result --> 2.2K
function print(query) {
  console.log(query);
}
  • β˜… Valid Date

// CommonJS
const { isValidDate } = require("@myno_21/time");
// ECMAScript
import { isValidDate } from "@myno_21/time";

console?.log(isValidDate("2021-01-24")); //--> true
console?.log(isValidDate("2020-02-24")); //--> true
console?.log(isValidDate("2030-02-90")); //--> false
  • β˜… Number To Percentage

// CommonJS
const { formatAsPercentage } = require("@myno_21/time");
// ECMAScript
import { formatAsPercentage } from "@myno_21/time";

const formattedPercentage = formatAsPercentage(31);

console?.log(formatAsPercentage); // Output --> 31.00%

β˜… Previous Packages