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

Commit

Permalink
Merge pull request #13 from Eomm/locale-ita
Browse files Browse the repository at this point in the history
Locale ita
  • Loading branch information
SerayaEryn committed Jul 27, 2019
2 parents 1711302 + 9827a48 commit 6b82f88
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions DateFormatter.js
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
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
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
@@ -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
@@ -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)
}

0 comments on commit 6b82f88

Please sign in to comment.