Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Locale ita #13

Merged
merged 3 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions DateFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { generateOffset, generateOffsetColon } = require('./lib/offset')
const Generator = require('./lib/formatterGenerator')
const localeEN = require('./lib/locales/en')
const localeDE = require('./lib/locales/de')
const localeIT = require('./lib/locales/it')

const formatSym = Symbol('fast-data-format.format')
const dayCountSym = Symbol('fast-data-format.dayCount')
Expand All @@ -22,6 +23,7 @@ class DateFormatter {
this[localesSym] = {}
this.addLocale('de', localeDE)
this.addLocale('en', localeEN)
this.addLocale('it', localeIT)
this.setLocale(options.locale || 'en')
this[formatSym] = buildFormatter(dateFormat, options).bind(this)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ suite
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ 'async': true })
.run({ async: true })
2 changes: 1 addition & 1 deletion benchmark/benchmarkCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ suite
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ 'async': true })
.run({ async: true })
25 changes: 25 additions & 0 deletions lib/locales/it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
weekdays: [
'Domenica',
'Lunedì',
'Martedì',
'Mercoledì',
'Giovedì',
'Venerdì',
'Sabato'
],
months: [
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre'
]
}
46 changes: 46 additions & 0 deletions test/locale.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict'

var t = require('tap')
var test = t.test
var DateFormatter = require('..')

test('MMMM', (t) => {
t.plan(1)
var date = new Date(2000, 2, 1, 3, 4, 5, 1)
var dateFormatter = new DateFormatter({ dateFormat: 'MMMM', locale: 'it' })

var formatted = dateFormatter.format(date)

t.strictEquals(formatted, 'Marzo')
})

test('dddd', (t) => {
t.plan(8)
testFormatDate(t, 'dddd', 0, 'Martedì', 'it')
testFormatDate(t, 'dddd', 1, 'Mercoledì', 'it')
testFormatDate(t, 'dddd', 2, 'Giovedì', 'it')
testFormatDate(t, 'dddd', 3, 'Venerdì', 'it')
testFormatDate(t, 'dddd', 4, 'Sabato', 'it')
testFormatDate(t, 'dddd', 5, 'Domenica', 'it')
testFormatDate(t, 'dddd', 6, 'Lunedì', 'it')
testFormatDate(t, 'dddd', 7, 'Martedì', 'it')
})

test('ddd', (t) => {
t.plan(8)
testFormatDate(t, 'ddd', 0, 'Mar', 'it')
testFormatDate(t, 'ddd', 1, 'Mer', 'it')
testFormatDate(t, 'ddd', 2, 'Gio', 'it')
testFormatDate(t, 'ddd', 3, 'Ven', 'it')
testFormatDate(t, 'ddd', 4, 'Sab', 'it')
testFormatDate(t, 'ddd', 5, 'Dom', 'it')
testFormatDate(t, 'ddd', 6, 'Lun', 'it')
testFormatDate(t, 'ddd', 7, 'Mar', 'it')
})

function testFormatDate (t, dateFormat, date1, h, locale) {
var date = new Date(2000, 2, date1, 1, 4, 5, 1)
var dateFormatter = new DateFormatter({ dateFormat, locale })
var formatted = dateFormatter.format(date)
t.strictEquals(formatted, h)
}