Wizardate
Wizardate provides a set of date formats for different locations. It allows you to create and register your own date formats and patterns.
Table of content
- Usage
- Locales and Formats
- Config Functions
- Registry Function
- Date Functions
- getDay(date)
- getMonthNumber(date)
- getMonth(date)
- getShortMonth(date)
- getYear(date)
- getShortYear(date)
- getWeekdayNumber(date)
- getWeekday(date)
- getDate(date)
- getExtendedDate(date)
- getExtendedWeekdayDate(date)
- getMonthNumberYear(date)
- getMonthYear(date)
- getShortMonthYear(date)
- getShortMonthShortYear(date)
- getHour(date)
- getExtendedHour(date)
- getMinute(date)
- getExtendedMinute(date)
- getSecond(date)
- getExtendedSecond(date)
- getTime(date)
- getExtendedTime(date)
- getHourMinute(date)
- getExtendedHourMinute(date)
- getDateTime(date)
- getExtendedDateTime(date)
- getExtendedCityDate(date)
- getExtendedRegionDate(date)
- getExtendedRegionCodeDate(date)
- getExtendedCountryDate(date)
- getExtendedCountryCodeDate(date)
- Current Locale Functions
- Format Pattern
- Changelog
- License
Usage
; const wizardate = pt_BR;wizardate; // => 17/07/2020
Locales and Formats
Date Formats
-
LittleEndian - dd/mm/yyyy or 22 April 2006
-
MiddleEndian - mm/dd/yyyy or April 22 2006
-
BigEndian - yyyy/mm/dd or 2006 April 22
Locales
All locales has your own default configuration
- pt_BR
- LittleEndian format
- date separator /
- time separator :
- en
- MiddleEndian format
- date separator -
- time separator :
- fr
- LittleEndian format
- date separator /
- time separator :
- es
- LittleEndian format
- date separator /
- time separator :
- de
- LittleEndian format
- date separator /
- time separator :
- it
- LittleEndian format
- date separator /
- time separator :
Config Functions
config(object)
Used to separate date and time
-
{string} sepDate - used to separate date
- e.g.: 02 / 11 / 2019
-
{string} sepTime - used to separate time
- e.g.: 08 : 53 : 20
; const wizardate = fr;wizardate
setDefaultConfig()
Set default config according to locale
; const wizardate = en;wizardate
setDateFormat(dateFormat)
; const wizardate = pt_BR;wizardate;
Registry Function
Wizardate allows you to create and register your own functions. Registered functions are stored in the funcs props
registry(funcName, func)
- {string} funcName - function name
- {function} func - function callback
; const wizardateBR = pt_BR; wizardateBR; console; // => Today is friday, 17/07/2020 const wizardateEN = en;wizardateEN; // Using Format PatternwizardateEN; console; // => BR, 2020-07-17
Date Functions
All functions below receive an optional date as a parameter. If no date is passed the function uses the current date.
- {string} date - accepts various formats (optional)
e.g.:
wizardate // => 26/01/2012 18:51:50 wizardate // => 08:54:32 wizardate // => 15/10/1996 wizardate // => monday, 08 september 2017 wizardate // => 10 wizardate // => 24/07/2018 00:00:00 wizardate // => friday wizardate
If the date passed is invalid the functions will return 'Invalid Date'.
getDay(date)
- returns day (1 ~ 31)
wizardate // => 17
getMonthNumber(date)
- returns month number (1 ~ 12)
wizardate // => 7
getMonth(date)
wizardate // => july
number | month |
---|---|
01 | january |
02 | february |
03 | march |
04 | april |
05 | may |
06 | june |
07 | july |
08 | august |
09 | september |
10 | october |
11 | november |
12 | december |
getShortMonth(date)
wizardate // => jul
number | month |
---|---|
01 | jan |
02 | feb |
03 | mar |
04 | apr |
05 | may |
06 | jun |
07 | jul |
08 | aug |
09 | sep |
10 | oct |
11 | nov |
12 | dec |
getYear(date)
wizardate // => 2020
getShortYear(date)
wizardate // => 20
getWeekdayNumber(date)
- returns the number of the week (1 a 7)
wizardate // => 5
getWeekday(date)
wizardate // => friday
number | weekday |
---|---|
1 | sunday |
2 | monday |
3 | tuesday |
4 | wednesday |
5 | thursday |
6 | friday |
7 | saturday |
getShortWeekday(date)
wizardate // => fri
number | weekday |
---|---|
1 | sun |
2 | mon |
3 | tue |
4 | wed |
5 | thu |
6 | fri |
7 | sat |
getDate(date)
wizardate // => 17/07/2020
getExtendedDate(date)
wizardate // => 17 july 2020
getExtendedWeekdayDate(date)
wizardate // => friday, 17 july 2020
getMonthNumberYear(date)
wizardate // => 07/2020
getMonthYear(date)
wizardate // => july/2020
getShortMonthYear(date)
wizardate // => jul/2020
getShortMonthShortYear(date)
wizardate // => jul/20
getHour(date)
- return hours (1 a 23)
wizardate // => 8
getExtendedHour(date)
wizardate // => 08 hours
getMinute(date)
- return minutes (1 a 59)
wizardate // => 53
getExtendedMinute(date)
wizardate // => 53 minutes
getSecond(date)
- returns seconds (1 a 59)
wizardate // => 32
getExtendedSecond(date)
wizardate // => 32 seconds
getTime(date)
wizardate // => 08:53:32
getExtendedTime(date)
wizardate // => 08 hours 53 minutes 32 seconds
getHourMinute(date)
wizardate // => 08:53
getExtendedHourMinute(date)
wizardate // => 08 hours 53 minutes
getDateTime(date)
wizardate // => 17/06/2020 08:53:32
getExtendedDateTime(date)
wizardate // => 17 july 2020 08 hours 53 minutes 32 seconds
getExtendedCityDate(date)
asynchronous function
await wizardate // => Marília, 17 july 2020
getExtendedRegionDate(date)
asynchronous function
await wizardate // => São Paulo, 17 july 2020
getExtendedRegionCodeDate(date)
asynchronous function
await wizardate // => SP, 17 july 2020
getExtendedCountryDate(date)
asynchronous function
await wizardate // => Brazil, 17 july 2020
getExtendedCountryCodeDate(date)
asynchronous function
await wizardate // => BR, 17 july 2020
Current Locale Functions
All functions bellow are asynchronous and returns current locale informations.
getCity()
asynchronous function
await wizardate // => Marília
getRegion()
asynchronous function
await wizardate // => São Paulo
getRegionCode()
asynchronous function
await wizardate // => SP
getCountry()
asynchronous function
await wizardate // => Brazil
getCountryCode()
asynchronous function
await wizardate // => BR
getTimezone()
asynchronous function
await wizardate // => America/Sao_Paulo
getZipcode()
asynchronous function
await wizardate // => 17350-000
Format Pattern
Use patterns to create your date format
pattern | output | desc |
---|---|---|
'date' | 17/07/2020 | full date |
'time' | 16:09:30 | full time |
'd' | 3 | day withou zero |
'dd' | 03 | day with zero |
'm' | 7 | month without zero |
'mm' | 07 | month with zero |
'mmm' | jul | short month |
'mmmm' | july | month |
'MMM' | Jul | capitalize short month |
'MMMM' | July | capitalize month |
'yy' | 20 | short year |
'yyyy' | 2020 | year |
'w' | 6 | weekday withou zero |
'ww' | 06 | weekday with zero |
'www' | fri | short weekday |
'wwww' | friday | weekday |
'WWW' | Fri | capitalize short weekday |
'WWWW' | Friday | capitalize weekday |
'h' | 5 | hour without zero |
'hh' | 05 | hour with zero |
'hhh' | 5 hour | hour without zero and desc |
'hhhh' | 05 hour | hour with zero and desc |
'HHH' | 5 Hour | hour without zero and capitalize desc |
'HHHH' | 05 Hour | hour with zero and capitalize desc |
'i' | 7 | minute without zero |
'ii' | 07 | minute with zero |
'iii' | 7 minutes | minute without zero and desc |
'iiii' | 07 minutes | minute with zero and desc |
'III' | 7 Minutes | minute without zero and capitalize desc |
'IIII' | 07 Minutes | minute with zero and capitalize desc |
's' | 1 | second without zero |
'ss' | 01 | second with zero |
'sss' | 1 second | second without zero and desc |
'ssss' | 01 second | second with zero and desc |
'SSS' | 1 Second | second without zero and capitalize desc |
'SSSS' | 01 Second | second with zero and capitalize desc |
'city' | Marília | city |
'region' | Sao Paulo | region |
'regionCode' | SP | region code |
'country' | Brazil | country |
'countryCode' | BR | country code |
Formats available only for pt_BR
pattern | output | desc |
---|---|---|
'wwwww' | sexta-feira | weekday |
'WWWWW' | Sexta-feira | capitalize weekday |
formatPattern(pattern, date)
- {string} pattern - string patter
- {string} date - accepts various formats (optional)
const myPattern = "'MMM' 'yyyy' - My Pattern" wizardate; // => Jul 2020 - My Pattern
Changelog
see the update notes at CHANGELOG.
License
MIT License
Copyright ® 2020 Victor Gianvechio
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.