Skip to content

Commit

Permalink
feat(datepicker): add Norwegian locale (valor-software#4634)
Browse files Browse the repository at this point in the history
  • Loading branch information
simjes authored and leo6104 committed Oct 10, 2019
1 parent 5548682 commit 3185d92
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 4 deletions.
8 changes: 4 additions & 4 deletions demo/src/app/components/+datepicker/demo-datepicker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { BsDatepickerModule, DatepickerModule } from 'ngx-bootstrap/datepicker';
import {
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
fiLocale, glLocale,
huLocale, idLocale, itLocale, jaLocale, koLocale, mnLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale,
roLocale, skLocale, slLocale, svLocale, thLocale, trLocale, zhCnLocale
huLocale, idLocale, itLocale, jaLocale, koLocale, mnLocale, nbLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale,
ruLocale, roLocale, skLocale, slLocale, svLocale, thLocale, trLocale, zhCnLocale
} from 'ngx-bootstrap/locale';
import { TabsModule } from 'ngx-bootstrap/tabs';

Expand All @@ -21,8 +21,8 @@ import { DEMO_COMPONENTS } from './demos';
const locales = [
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
fiLocale, glLocale,
huLocale, idLocale, itLocale, jaLocale, koLocale, mnLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale,
roLocale, skLocale, slLocale, svLocale, thLocale, trLocale, zhCnLocale
huLocale, idLocale, itLocale, jaLocale, koLocale, mnLocale, nbLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale,
ruLocale, roLocale, skLocale, slLocale, svLocale, thLocale, trLocale, zhCnLocale
];
locales.forEach((locale: LocaleData) => defineLocale(locale.abbr, locale));

Expand Down
56 changes: 56 additions & 0 deletions src/chronos/i18n/nb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// tslint:disable:comment-format
import { LocaleData } from '../locale/locale.class';

//! moment.js locale configuration
//! locale : Norwegian Bokmål [nb]
//! authors : Espen Hovlandsdal : https://github.com/rexxars
//! Sigurd Gartmann : https://github.com/sigurdga

export const nbLocale: LocaleData = {
abbr: 'nb',
months: 'januar_februar_mars_april_mai_juni_juli_august_september_oktober_november_desember'.split('_'),
monthsShort: 'jan._feb._mars_april_mai_juni_juli_aug._sep._okt._nov._des.'.split('_'),
monthsParseExact: true,
weekdays: 'søndag_mandag_tirsdag_onsdag_torsdag_fredag_lørdag'.split('_'),
weekdaysShort: 'sø._ma._ti._on._to._fr._lø.'.split('_'),
weekdaysMin: 'sø_ma_ti_on_to_fr_lø'.split('_'),
weekdaysParseExact: true,
longDateFormat: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY [kl.] HH:mm',
LLLL: 'dddd D. MMMM YYYY [kl.] HH:mm'
},
calendar: {
sameDay: '[i dag kl.] LT',
nextDay: '[i morgen kl.] LT',
nextWeek: 'dddd [kl.] LT',
lastDay: '[i går kl.] LT',
lastWeek: '[forrige] dddd [kl.] LT',
sameElse: 'L'
},
relativeTime: {
future: 'om %s',
past: '%s siden',
s: 'noen sekunder',
ss: '%d sekunder',
m: 'ett minutt',
mm: '%d minutter',
h: 'en time',
hh: '%d timer',
d: 'en dag',
dd: '%d dager',
M: 'en måned',
MM: '%d måneder',
y: 'ett år',
yy: '%d år'
},
dayOfMonthOrdinalParse: /\d{1,2}\./,
ordinal: '%d.',
week: {
dow: 1, // Monday is the first day of the week.
doy: 4 // The week that contains Jan 4th is the first week of the year.
}
};
1 change: 1 addition & 0 deletions src/chronos/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export { itLocale } from './i18n/it';
export { jaLocale } from './i18n/ja';
export { koLocale } from './i18n/ko';
export { mnLocale } from './i18n/mn';
export { nbLocale } from './i18n/nb';
export { nlLocale } from './i18n/nl';
export { nlBeLocale } from './i18n/nl-be';
export { plLocale } from './i18n/pl';
Expand Down
186 changes: 186 additions & 0 deletions src/chronos/test/locale/nb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// tslint:disable:max-line-length max-file-line-count prefer-const forin prefer-template one-variable-per-declaration newline-before-return
// tslint:disable:binary-expression-operand-order comment-format one-line no-var-keyword object-literal-shorthand
// tslint:disable:variable-name no-shadowed-variable

import { assertEq } from '../test-helpers';
import { moment } from '../chain';
import { nbLocale } from '../../i18n/nb';

// localeModule('nb');
describe('locale: nb', () => {
beforeAll(() => {
moment.locale(nbLocale.abbr, nbLocale);
});

afterAll(() => {
moment.locale('en');
});

it('parse', function () {
var _tests = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'),
i;

function equalTest(input, mmm, i) {
assertEq(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
}

let tests: string[][] = [];
for (i = 0; i < 12; i++) {
tests[i] = _tests[i].split(' ');
equalTest(tests[i][0], 'MMM', i);
equalTest(tests[i][1], 'MMM', i);
equalTest(tests[i][0], 'MMMM', i);
equalTest(tests[i][1], 'MMMM', i);
equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
}
});

it('format', function () {
var a = [
['dddd, MMMM Do YYYY, h:mm:ss', 'søndag, februar 14. 2010, 3:25:50'],
['ddd, h', 'sø., 3'],
['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
['YYYY YY', '2010 10'],
['D Do DD', '14 14. 14'],
['d do dddd ddd dd', '0 0. søndag sø. sø'],
['DDD DDDo DDDD', '45 45. 045'],
['w wo ww', '6 6. 06'],
['h hh', '3 03'],
['H HH', '15 15'],
['m mm', '25 25'],
['s ss', '50 50'],
['LTS', '15:25:50'],
['L', '14.02.2010'],
['LL', '14. februar 2010'],
['LLL', '14. februar 2010 kl. 15:25'],
['LLLL', 'søndag 14. februar 2010 kl. 15:25'],
['l', '14.2.2010'],
['ll', '14. feb. 2010'],
['lll', '14. feb. 2010 kl. 15:25'],
['llll', 'sø. 14. feb. 2010 kl. 15:25']
],
b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
i;
for (i = 0; i < a.length; i++) {
assertEq(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
}
});

it('format month', function () {
var expected = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'),
i;
for (i = 0; i < expected.length; i++) {
assertEq(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
});

it('format week', function () {
var expected = 'søndag sø. sø_mandag ma. ma_tirsdag ti. ti_onsdag on. on_torsdag to. to_fredag fr. fr_lørdag lø. lø'.split('_'),
i;
for (i = 0; i < expected.length; i++) {
assertEq(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
}
});

it('from', function () {
var start = moment([2007, 1, 28]);
assertEq(start.from(moment([2007, 1, 28]).add({ s: 44 }), true), 'noen sekunder', '44 seconds = a few seconds');
assertEq(start.from(moment([2007, 1, 28]).add({ s: 45 }), true), 'ett minutt', '45 seconds = a minute');
assertEq(start.from(moment([2007, 1, 28]).add({ s: 89 }), true), 'ett minutt', '89 seconds = a minute');
assertEq(start.from(moment([2007, 1, 28]).add({ s: 90 }), true), '2 minutter', '90 seconds = 2 minutes');
assertEq(start.from(moment([2007, 1, 28]).add({ m: 44 }), true), '44 minutter', '44 minutes = 44 minutes');
assertEq(start.from(moment([2007, 1, 28]).add({ m: 45 }), true), 'en time', '45 minutes = an hour');
assertEq(start.from(moment([2007, 1, 28]).add({ m: 89 }), true), 'en time', '89 minutes = an hour');
assertEq(start.from(moment([2007, 1, 28]).add({ m: 90 }), true), '2 timer', '90 minutes = 2 hours');
assertEq(start.from(moment([2007, 1, 28]).add({ h: 5 }), true), '5 timer', '5 hours = 5 hours');
assertEq(start.from(moment([2007, 1, 28]).add({ h: 21 }), true), '21 timer', '21 hours = 21 hours');
assertEq(start.from(moment([2007, 1, 28]).add({ h: 22 }), true), 'en dag', '22 hours = a day');
assertEq(start.from(moment([2007, 1, 28]).add({ h: 35 }), true), 'en dag', '35 hours = a day');
assertEq(start.from(moment([2007, 1, 28]).add({ h: 36 }), true), '2 dager', '36 hours = 2 days');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 1 }), true), 'en dag', '1 day = a day');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 5 }), true), '5 dager', '5 days = 5 days');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 25 }), true), '25 dager', '25 days = 25 days');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 26 }), true), 'en måned', '26 days = a month');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 30 }), true), 'en måned', '30 days = a month');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 43 }), true), 'en måned', '43 days = a month');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 46 }), true), '2 måneder', '46 days = 2 months');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 74 }), true), '2 måneder', '75 days = 2 months');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 76 }), true), '3 måneder', '76 days = 3 months');
assertEq(start.from(moment([2007, 1, 28]).add({ M: 1 }), true), 'en måned', '1 month = a month');
assertEq(start.from(moment([2007, 1, 28]).add({ M: 5 }), true), '5 måneder', '5 months = 5 months');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 345 }), true), 'ett år', '345 days = a year');
assertEq(start.from(moment([2007, 1, 28]).add({ d: 548 }), true), '2 år', '548 days = 2 years');
assertEq(start.from(moment([2007, 1, 28]).add({ y: 1 }), true), 'ett år', '1 year = a year');
assertEq(start.from(moment([2007, 1, 28]).add({ y: 5 }), true), '5 år', '5 years = 5 years');
});

it('suffix', function () {
assertEq(moment(30000).from(0), 'om noen sekunder', 'prefix');
assertEq(moment(0).from(30000), 'noen sekunder siden', 'suffix');
});

it('now from now', function () {
assertEq(moment().fromNow(), 'noen sekunder siden', 'now from now should display as in the past');
});

it('fromNow', function () {
assertEq(moment().add({ s: 30 }).fromNow(), 'om noen sekunder', 'in a few seconds');
assertEq(moment().add({ d: 5 }).fromNow(), 'om 5 dager', 'in 5 days');
});

it('calendar day', function () {
var a = moment().hours(12).minutes(0).seconds(0);
assertEq(moment(a).calendar(), 'i dag kl. 12:00', 'Today at 12:00');
assertEq(moment(a).add({ m: 25 }).calendar(), 'i dag kl. 12:25', 'Now plus 25 min');
assertEq(moment(a).add({ h: 1 }).calendar(), 'i dag kl. 13:00', 'Now plus 1 hour');
assertEq(moment(a).add({ d: 1 }).calendar(), 'i morgen kl. 12:00', 'tomorrow at the same time');
assertEq(moment(a).subtract({ h: 1 }).calendar(), 'i dag kl. 11:00', 'Now minus 1 hour');
assertEq(moment(a).subtract({ d: 1 }).calendar(), 'i går kl. 12:00', 'yesterday at the same time');
});

it('calendar next week', function () {
var i, m;
for (i = 2; i < 7; i++) {
m = moment().add({ d: i });
assertEq(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time');
m.hours(0).minutes(0).seconds(0).milliseconds(0);
assertEq(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
m.hours(23).minutes(59).seconds(59).milliseconds(999);
assertEq(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
}
});

it('calendar last week', function () {
var i, m;
for (i = 2; i < 7; i++) {
m = moment().subtract({ d: i });
assertEq(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days current time');
m.hours(0).minutes(0).seconds(0).milliseconds(0);
assertEq(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day');
m.hours(23).minutes(59).seconds(59).milliseconds(999);
assertEq(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days end of day');
}
});

it('calendar all else', function () {
var weeksAgo = moment().subtract({ w: 1 }),
weeksFromNow = moment().add({ w: 1 });
assertEq(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
assertEq(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
weeksAgo = moment().subtract({ w: 2 });
weeksFromNow = moment().add({ w: 2 });
assertEq(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
assertEq(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
});

it('weeks year starting sunday formatted', function () {
assertEq(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
assertEq(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
assertEq(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
assertEq(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
assertEq(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
});
});
1 change: 1 addition & 0 deletions src/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { itLocale } from './chronos/i18n/it';
export { jaLocale } from './chronos/i18n/ja';
export { koLocale } from './chronos/i18n/ko';
export { mnLocale } from './chronos/i18n/mn';
export { nbLocale } from './chronos/i18n/nb';
export { nlLocale } from './chronos/i18n/nl';
export { nlBeLocale } from './chronos/i18n/nl-be';
export { plLocale } from './chronos/i18n/pl';
Expand Down
1 change: 1 addition & 0 deletions src/locale/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { itLocale } from 'ngx-bootstrap/chronos';
export { jaLocale } from 'ngx-bootstrap/chronos';
export { koLocale } from 'ngx-bootstrap/chronos';
export { mnLocale } from 'ngx-bootstrap/chronos';
export { nbLocale } from 'ngx-bootstrap/chronos';
export { nlLocale } from 'ngx-bootstrap/chronos';
export { nlBeLocale } from 'ngx-bootstrap/chronos';
export { plLocale } from 'ngx-bootstrap/chronos';
Expand Down

0 comments on commit 3185d92

Please sign in to comment.