date-pt-br
v1.2.2
Published
Get current date in pt-BR or format other dates to pt-BR.
Downloads
36
Maintainers
Readme
date-pt-br
Get current date in pt-BR or format other dates to pt-BR.
Table of content
- Installation
- Changelog
- Config Functions
- 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)
- getExtendedShortRegionDate(date)
- getExtendedCountryDate(date)
- getExtendedShortCountryDate(date)
- Current Locale Functions
- License
Installation
via npm:
npm i -S date-pt-br
Scripts
list all functions:
npm run list-functions
Usage
const DatePtBR = require('date-pt-br')
const date = new DatePtBR()
Changelog
see the update notes at CHANGELOG.
Config Functions
config(object)
delimiters and sep are used by the functions.
{string} delimiterDate - used to separate day, month and year
- default: ' / '
- e.g.: 02 / 11 / 2019
{string} delimiterTime - used to separate hours, minutes and seconds
- default: ' : '
- e.g.: 08 : 53 : 20
{string} sepDateTime - used to separate date and time
- default: ' , '
- e.g.: 02/01/2019 , 08:53:20
{string} sepDate - used to separate date
- default: ' de '
- e.g.: 02 de Janeiro de 2019
{string} sepTime - used to separate time
- default: ' e '
- e.g.: 08 horas e 53 minutos e 20 segundos
const DatePtBR = require('date-pt-br')
const date = new DatePtBR()
date.config({
delimiterDate: '/',
delimiterTime: ':',
sepDateTime: ', ',
sepDate: ' de ',
sepTime: ' e '
})
setDefaultConfig()
date.setDefaultConfig()
// delimiterDate: '/',
// delimiterTime: ':',
// sepDateTime: ', ',
// sepDate: ' de ',
// sepTime: ' e '
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.:
date.getDateTime('2012-01-26T13:51:50.417-07:00') // => 26/01/2012, 18:51:50
date.getTime('05/07/2019 08:54:32') // => 08:54:32
date.getDate('October 15, 1996 05: 35: 32') // => 15/10/1996
date.getExtendedWeekdayDate('2017-09-08T15:25:53Z') // => Sexta-Feira, 08 de Setembro de 2017
date.getMonthNumber('05 October 2011 14:48 UTC') // => 10
date.getDateTime('07/24/2015') // => 24/07/2018, 00:00:00
date.getWeekday('05 October 2011 14:48 UTC') // => Quarta-Feira
date.getExtendedTime('Wed Oct 05 2011 16:48:00 GMT+0200 (CEST)' // => 11 horas e 48 minutos e 00 segundos
date.getShortMonthYear('2011-10-05T14:48:00.000Z') // => Out/2011
date.getDay('24HJERH87LK4') // => Invalid Date
If the date passed is invalid the functions will return 'Invalid Date'.
getDay(date)
- returns day (01 a 31)
let val = date.getDay() // => 27
getMonthNumber(date)
- returns month number (01 a 12)
let val = date.getMonthNumber() // => 06
getMonth(date)
let val = date.getMonth() // => Junho
| number | month | | :----- | :-------- | | 01 | Janeiro | | 02 | Fevereiro | | 03 | Março | | 04 | Abril | | 05 | Maio | | 06 | Junho | | 07 | Julho | | 08 | Agosto | | 09 | Setembro | | 10 | Outubro | | 11 | Novembro | | 12 | Dezembro |
getShortMonth(date)
let val = date.getShortMonth() // => Jun
| number | month | | :----- | :-----| | 01 | Jan | | 02 | Fev | | 03 | Mar | | 04 | Abr | | 05 | Mai | | 06 | Jun | | 07 | Jul | | 08 | Ago | | 09 | Set | | 10 | Out | | 11 | Nov | | 12 | Dez |
getYear(date)
let val = date.getYear() // => 2019
getShortYear(date)
let val = date.getShortYear('07/18/2019') // => 19
getWeekdayNumber(date)
- returns the number of the week (1 a 7)
let val = date.getWeekdayNumber() // => 5
getWeekday(date)
let val = date.getWeekday() // => Quinta-Feira
| number | weekday | | :----- | :------------ | | 1 | Domingo | | 2 | Segunda-Feira | | 3 | Terça-Feira | | 4 | Quarta-Feira | | 5 | Quinta-Feira | | 6 | Sexta-Feira | | 7 | Sábado |
getDate(date)
let val = date.getDate() // => 27/06/2019
getExtendedDate(date)
let val = date.getExtendedDate() // => 27 de Junho de 2019
getExtendedWeekdayDate(date)
let val = date.getExtendedWeekdayDate() // => Quinta-Feira, 27 de Junho de 2019
getMonthNumberYear(date)
let val = date.getMonthNumberYear() // => 06/2019
getMonthYear(date)
let val = date.getMonthYear() // => Junho/2019
getShortMonthYear(date)
let val = date.getShortMonthYear() // => Jun/2019
getShortMonthShortYear(date)
let val = date.getShortMonthYear() // => Jun/19
getHour(date)
- return hours (01 a 23)
let val = date.getHour() // => 08
getExtendedHour(date)
let val = date.getExtendedHour() // => 08 horas
getMinute(date)
- return minutes (01 a 59)
let val = date.getMinute() // => 53
getExtendedMinute(date)
let val = date.getExtendedMinute() // => 53 minutos
getSecond(date)
- returns seconds (01 a 59)
let val = date.getSecond() // => 32
getExtendedSecond(date)
let val = date.getExtendedSecond() // => 32 segundos
getTime(date)
let val = date.getTime() // => 08:53:32
getExtendedTime(date)
let val = date.getExtendedTime() // => 08 horas e 53 minutos e 32 segundos
getHourMinute(date)
let val = date.getHourMinute() // => 08:53
getExtendedHourMinute(date)
let val = date.getExtendedHourMinute() // => 08 horas e 53 minutos
getDateTime(date)
let val = date.getDateTime() // => 27/06/2019 08:53:32
getExtendedDateTime(date)
let val = date.getExtendedDateTime() // => 27 de Junho de 2019, 08 horas e 53 minutos e 32 segundos
getExtendedCityDate(date)
asynchronous function
let val = await date.getExtendedCityDate() // => Marília, 22 de Julho de 2019
getExtendedRegionDate(date)
asynchronous function
let val = await date.getExtendedRegionDate() // => São Paulo, 22 de Julho de 2019
getExtendedShortRegionDate(date)
asynchronous function
let val = await date.getExtendedShortRegionDate() // => SP, 22 de Julho de 2019
getExtendedCountryDate(date)
asynchronous function
let val = await date.getExtendedCountryDate() // => Brazil, 22 de Julho de 2019
getExtendedShortCountryDate(date)
asynchronous function
let val = await date.getExtendedShortCountryDate() // => BR, 22 de Julho de 2019
Current Locale Functions
All functions bellow are asynchronous and returns current locale informations.
getCity()
asynchronous function
let val = await date.getCity() // => Marília
getRegion()
asynchronous function
let val = await date.getRegion() // => São Paulo
getShortRegion()
asynchronous function
let val = await date.getShortRegion() // => SP
getCountry()
asynchronous function
let val = await date.getCountry() // => Brazil
getShortCountry()
asynchronous function
let val = await date.getShortCountry() // => BR
getTimezone()
asynchronous function
let val = await date.getTimezone() // => America/Sao_Paulo
getZipcode()
asynchronous function
let val = await date.getZipcode() // => 17350-000
License
MIT License
Copyright ® 2019 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.