@luke-zhang-04/dateplus
Version:
A simple program to assist with date manipulation
114 lines (113 loc) • 4.11 kB
TypeScript
/**
* DatePlus A simple program to assist with date manipulation
*
* @license MIT
* @version 4.0.0-beta2
* @author Luke Zhang luke-zhang-04.github.io
* @copyright Copyright (C) 2020 - 2021 Luke Zhang
*/
import { daysReference, monthsReference } from "./values";
import type { YearObj } from "./conversions";
export declare type DateFormat = "y:m:d" | "y:d:m" | "m:d:y" | "m:y:d" | "d:m:y" | "d:y:m";
/**
* Add's 0s to date (e.g 2020/4/3 => 2020/04/03)
*
* @param date - String date to format
* @param seperator - Char the date is seperatred by
* @returns - Date with zeros
*/
export declare const addZeros: (date: string, seperator?: string) => string;
/**
* Format date into a string in the form YYYY{seperator}MM{seperator}DD
*
* @param date - Date object to format
* @param format - Format of string date
* @param seperator - String to seperate date values with
* @returns Formatted date
*/
export declare const formatDate: (date: Date, format?: DateFormat, seperator?: string) => string;
/**
* Gets date values and outputs an object
*
* @param date - Date to extract values from, months zero indexed
* @param format - Format of string date
* @param seperator - Seperator the date works with; leave auto for auto detection, limited to 1 char
* @returns Object with all values
*/
export declare const getDateValues: (date: string, format?: DateFormat, seperator?: string) => YearObj;
/**
* Converts numerical day of week into word form (e.g 0 => "Sunday")
*
* @param numerical - Numerical day of week, 0 indexed (0-6)
* @returns Stringed day of week
*/
export declare const getWordDay: (numerical: keyof typeof daysReference) => string;
/**
* Converts numerical month into word form (e.g 0 => "January")
*
* @param numerical - Numerical day of week, 0 indexed (0-11)
* @returns Stringed worded month
*/
export declare const getWordMonth: (numerical: keyof typeof monthsReference) => string;
/**
* Calculates number of elapsed days between date1 and date2
*
* @param date1 - Starting date object to calculate
* @param date2 - Ending date object to calculate
* @returns - Number of elapsed days
*/
export declare const getElapsedDays: (date1: Date, date2: Date) => number;
/**
* Calculates number of elapsed hours between date1 and date2
*
* @param date1 - Starting date object to calculate
* @param date2 - Ending date object to calculate
* @returns - Number of elapsed hours
*/
export declare const getElapsedHours: (date1: Date, date2: Date) => number;
/**
* Calculates number of elapsed minutes between date1 and date2
*
* @param date1 - Starting date object to calculate
* @param date2 - Ending date object to calculate
* @returns - Number of elapsed minutes
*/
export declare const getElapsedMinutes: (date1: Date, date2: Date) => number;
/**
* Calculates number of elapsed seconds between date1 and date2
*
* @param date1 - Starting date object to calculate
* @param date2 - Ending date object to calculate
* @returns - Number of elapsed seconds
*/
export declare const getElapsedSeconds: (date1: Date, date2: Date) => number;
/**
* Calculates number of elapsed milliseconds between date1 and date2
*
* @param date1 - Starting date object to calculate
* @param date2 - Ending date object to calculate
* @returns - Number of elapsed milliseconds
*/
export declare const getElapsedMs: (date1: Date, date2: Date) => number;
/**
* Calculates elapsed time between current and previous
*
* @param start- Start date
* @param end - End date
* @param approx - Text to append to values from days and on, e.g *about* 1 day aga
* @returns Time difference in string form, e.g "3 seconds ago"
*/
export declare const getElapsedString: (start: Date, end: Date, approx?: string) => string;
/**
* Convert a utc date to local
*
* @param date - Date to use. Note that the parameter will never be mutated.
* @returns A new date object with the time converted form UTC
*/
export declare const utcToLocal: <T extends Date>(date: T) => T;
/**
* Get the current UTC Time
*
* @returns UTC Time
*/
export declare const getUtcTime: () => number;