1.2.2 • Published 5 years ago

date-pt-br v1.2.2

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

date-pt-br

NPM Version Build Status license npm monthly npm downloads for date-pt-br Dependency Status

Get current date in pt-BR or format other dates to pt-BR.

Table of content


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
numbermonth
01Janeiro
02Fevereiro
03Março
04Abril
05Maio
06Junho
07Julho
08Agosto
09Setembro
10Outubro
11Novembro
12Dezembro

getShortMonth(date)

let val = date.getShortMonth() // => Jun
numbermonth
01Jan
02Fev
03Mar
04Abr
05Mai
06Jun
07Jul
08Ago
09Set
10Out
11Nov
12Dez

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
numberweekday
1Domingo
2Segunda-Feira
3Terça-Feira
4Quarta-Feira
5Quinta-Feira
6Sexta-Feira
7Sá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.

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago