Skip to content

Commit 8fe43e2

Browse files
Per Hansenvalorkin
authored andcommitted
feat(chronos): add danish locale configuration (#3514)
added danish locale configuration
1 parent 7c52e38 commit 8fe43e2

File tree

4 files changed

+247
-2
lines changed

4 files changed

+247
-2
lines changed

demo/src/app/components/+datepicker/demo-datepicker.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { RouterModule } from '@angular/router';
66
import { defineLocale, LocaleData } from 'ngx-bootstrap/chronos';
77
import { BsDatepickerModule, DatepickerModule } from 'ngx-bootstrap/datepicker';
88
import {
9-
arLocale, csLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
9+
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
1010
huLocale, itLocale, jaLocale, koLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale, svLocale, thLocale,
1111
trLocale, zhCnLocale
1212
} from 'ngx-bootstrap/locale';
@@ -18,7 +18,7 @@ import { routes } from './demo-datepicker.routes';
1818
import { DEMO_COMPONENTS } from './demos';
1919

2020
const locales = [
21-
arLocale, csLocale, deLocale, enGbLocale, esLocale, esDoLocale, esUsLocale,
21+
arLocale, csLocale, daLocale, deLocale, enGbLocale, esLocale, esDoLocale, esUsLocale,
2222
frLocale, hiLocale, heLocale, huLocale, itLocale, jaLocale, koLocale, nlLocale,
2323
nlBeLocale, plLocale, ptBrLocale, svLocale, ruLocale, zhCnLocale, trLocale, thLocale
2424
];

src/chronos/i18n/da.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// tslint:disable:comment-format
2+
3+
import { LocaleData } from '../locale/locale.class';
4+
5+
//! moment.js locale configuration
6+
//! locale : Danish (Denmark) [da]
7+
//! author : Per Hansen : https://github.com/perhp
8+
9+
export const daLocale: LocaleData = {
10+
abbr: 'da',
11+
months : 'Januar_Februar_Marts_April_Maj_Juni_Juli_August_September_Oktober_November_December'.split('_'),
12+
monthsShort : 'Jan_Feb_Mar_Apr_Maj_Jun_Jul_Aug_Sep_Okt_Nov_Dec'.split('_'),
13+
weekdays : 'Søndag_Mandag_Tirsdag_Onsdag_Torsdag_Fredag_Lørdag'.split('_'),
14+
weekdaysShort : 'Søn_Man_Tir_Ons_Tor_Fre_Lør'.split('_'),
15+
weekdaysMin : 'Sø_Ma_Ti_On_To_Fr_Lø'.split('_'),
16+
longDateFormat : {
17+
LT : 'HH:mm',
18+
LTS : 'HH:mm:ss',
19+
L : 'DD/MM/YYYY',
20+
LL : 'D. MMMM YYYY',
21+
LLL : 'D. MMMM YYYY HH:mm',
22+
LLLL : 'dddd [d.] D. MMMM YYYY [kl.] HH:mm'
23+
},
24+
calendar : {
25+
sameDay : '[i dag kl.] LT',
26+
nextDay : '[i morgen kl.] LT',
27+
nextWeek : 'på dddd [kl.] LT',
28+
lastDay : '[i går kl.] LT',
29+
lastWeek : '[i] dddd[s kl.] LT',
30+
sameElse : 'L'
31+
},
32+
relativeTime : {
33+
future : 'om %s',
34+
past : '%s siden',
35+
s : 'få sekunder',
36+
m : 'et minut',
37+
mm : '%d minutter',
38+
h : 'en time',
39+
hh : '%d timer',
40+
d : 'en dag',
41+
dd : '%d dage',
42+
M : 'en måned',
43+
MM : '%d måneder',
44+
y : 'et år',
45+
yy : '%d år'
46+
},
47+
dayOfMonthOrdinalParse: /\d{1,2}\./,
48+
ordinal : '%d.',
49+
week : {
50+
dow : 1, // Monday is the first day of the week.
51+
doy : 4 // The week that contains Jan 4th is the first week of the year.
52+
}
53+
};
54+

src/chronos/test/locale/da.spec.ts

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// tslint:disable:max-line-length max-file-line-count prefer-const forin prefer-template one-variable-per-declaration newline-before-return
2+
// tslint:disable:binary-expression-operand-order comment-format one-line no-var-keyword object-literal-shorthand
3+
// tslint:disable:variable-name no-shadowed-variable
4+
5+
import { assert } from 'chai';
6+
import { moment } from '../chain';
7+
import { daLocale } from '../../i18n/da';
8+
9+
// localeModule('da');
10+
describe('locale: da', () => {
11+
beforeAll(() => {
12+
moment.locale(daLocale.abbr, daLocale);
13+
});
14+
15+
afterAll(() => {
16+
moment.locale(daLocale.abbr);
17+
});
18+
19+
it('parse', function () {
20+
var _tests = 'Januar Jan_Februar Feb_Marts Mar_April Apr_Maj Maj_Juni Jun_Juli Jul_August Aug_September Sep_Oktober Okt_November Nov_December Dec'.split('_'),
21+
i;
22+
23+
function equalTest(input, mmm, i) {
24+
assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
25+
}
26+
27+
let tests: string[][] = [];
28+
for (i = 0; i < 12; i++) {
29+
tests[i] = _tests[i].split(' ');
30+
equalTest(tests[i][0], 'MMM', i);
31+
equalTest(tests[i][1], 'MMM', i);
32+
equalTest(tests[i][0], 'MMMM', i);
33+
equalTest(tests[i][1], 'MMMM', i);
34+
equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
35+
equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
36+
equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
37+
equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
38+
}
39+
});
40+
41+
it('format', function () {
42+
var a = [
43+
['dddd, MMMM Do YYYY, h:mm:ss', 'Søndag, Februar 14. 2010, 3:25:50'],
44+
['ddd, h', 'Søn, 3'],
45+
['M Mo MM MMMM MMM', '2 2. 02 Februar Feb'],
46+
['YYYY YY', '2010 10'],
47+
['D Do DD', '14 14. 14'],
48+
['d do dddd ddd dd', '0 0. Søndag Søn Sø'],
49+
['DDD DDDo DDDD', '45 45. 045'],
50+
['w wo ww', '6 6. 06'],
51+
['h hh', '3 03'],
52+
['H HH', '15 15'],
53+
['m mm', '25 25'],
54+
['s ss', '50 50'],
55+
['LTS', '15:25:50'],
56+
['L', '14/02/2010'],
57+
['LL', '14. Februar 2010'],
58+
['LLL', '14. Februar 2010 15:25'],
59+
['LLLL', 'Søndag d. 14. Februar 2010 kl. 15:25'],
60+
['l', '14/2/2010'],
61+
['ll', '14. Feb 2010'],
62+
['lll', '14. Feb 2010 15:25'],
63+
['llll', 'Søn d. 14. Feb 2010 kl. 15:25']
64+
],
65+
b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
66+
i;
67+
for (i = 0; i < a.length; i++) {
68+
assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
69+
}
70+
});
71+
72+
it('format month', function () {
73+
var expected = 'Januar Jan_Februar Feb_Marts Mar_April Apr_Maj Maj_Juni Jun_Juli Jul_August Aug_September Sep_Oktober Okt_November Nov_December Dec'.split('_'),
74+
i;
75+
for (i = 0; i < expected.length; i++) {
76+
assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
77+
}
78+
});
79+
80+
it('format week', function () {
81+
var expected = 'Søndag Søn Sø_Mandag Man Ma_Tirsdag Tir Ti_Onsdag Ons On_Torsdag Tor To_Fredag Fre Fr_Lørdag Lør Lø'.split('_'),
82+
i;
83+
for (i = 0; i < expected.length; i++) {
84+
assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
85+
}
86+
});
87+
88+
it('from', function () {
89+
var start = moment([2007, 1, 28]);
90+
assert.equal(start.from(moment([2007, 1, 28]).add({ s: 44 }), true), 'få sekunder', '44 seconds = få sekunder');
91+
assert.equal(start.from(moment([2007, 1, 28]).add({ s: 45 }), true), 'et minut', '45 seconds = et minut');
92+
assert.equal(start.from(moment([2007, 1, 28]).add({ s: 89 }), true), 'et minut', '89 seconds = et minut');
93+
assert.equal(start.from(moment([2007, 1, 28]).add({ s: 90 }), true), '2 minutter', '90 seconds = 2 minutter');
94+
assert.equal(start.from(moment([2007, 1, 28]).add({ m: 44 }), true), '44 minutter', '44 minutes = 44 minutter');
95+
assert.equal(start.from(moment([2007, 1, 28]).add({ m: 45 }), true), 'en time', '45 minutes = en time');
96+
assert.equal(start.from(moment([2007, 1, 28]).add({ m: 89 }), true), 'en time', '89 minutes = en time');
97+
assert.equal(start.from(moment([2007, 1, 28]).add({ m: 90 }), true), '2 timer', '90 minutes = 2 timer');
98+
assert.equal(start.from(moment([2007, 1, 28]).add({ h: 5 }), true), '5 timer', '5 hours = 5 timer');
99+
assert.equal(start.from(moment([2007, 1, 28]).add({ h: 21 }), true), '21 timer', '21 hours = 21 timer');
100+
assert.equal(start.from(moment([2007, 1, 28]).add({ h: 22 }), true), 'en dag', '22 hours = en dag');
101+
assert.equal(start.from(moment([2007, 1, 28]).add({ h: 35 }), true), 'en dag', '35 hours = en dag');
102+
assert.equal(start.from(moment([2007, 1, 28]).add({ h: 36 }), true), '2 dage', '36 hours = 2 dage');
103+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 1 }), true), 'en dag', '1 day = en dag');
104+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 5 }), true), '5 dage', '5 days = 5 dage');
105+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 25 }), true), '25 dage', '25 days = 25 dage');
106+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 26 }), true), 'en måned', '26 days = en måned');
107+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 30 }), true), 'en måned', '30 days = en måned');
108+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 43 }), true), 'en måned', '43 days = en måned');
109+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 46 }), true), '2 måneder', '46 days = 2 måneder');
110+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 74 }), true), '2 måneder', '75 days = 2 måneder');
111+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 76 }), true), '3 måneder', '76 days = 3 måneder');
112+
assert.equal(start.from(moment([2007, 1, 28]).add({ M: 1 }), true), 'en måned', '1 month = en måned');
113+
assert.equal(start.from(moment([2007, 1, 28]).add({ M: 5 }), true), '5 måneder', '5 months = 5 måneder');
114+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 345 }), true), 'et år', '345 days = et år');
115+
assert.equal(start.from(moment([2007, 1, 28]).add({ d: 548 }), true), '2 år', '548 days = 2 år');
116+
assert.equal(start.from(moment([2007, 1, 28]).add({ y: 1 }), true), 'et år', '1 year = et år');
117+
assert.equal(start.from(moment([2007, 1, 28]).add({ y: 5 }), true), '5 år', '5 years = 5 år');
118+
});
119+
120+
it('suffix', function () {
121+
assert.equal(moment(30000).from(0), 'om få sekunder', 'prefix');
122+
assert.equal(moment(0).from(30000), 'få sekunder siden', 'suffix');
123+
});
124+
125+
it('now from now', function () {
126+
assert.equal(moment().fromNow(), 'få sekunder siden', 'now from now should display as in the past');
127+
});
128+
129+
it('fromNow', function () {
130+
assert.equal(moment().add({ s: 30 }).fromNow(), 'om få sekunder', 'om få sekunder');
131+
assert.equal(moment().add({ d: 5 }).fromNow(), 'om 5 dage', 'om 5 dage');
132+
});
133+
134+
it('calendar day', function () {
135+
var a = moment().hours(12).minutes(0).seconds(0);
136+
137+
assert.equal(moment(a).calendar(), 'i dag kl. 12:00', 'Today at 12:00');
138+
assert.equal(moment(a).add({ m: 25 }).calendar(), 'i dag kl. 12:25', 'Now plus 25 min');
139+
assert.equal(moment(a).add({ h: 1 }).calendar(), 'i dag kl. 13:00', 'Now plus 1 hour');
140+
assert.equal(moment(a).add({ d: 1 }).calendar(), 'i morgen kl. 12:00', 'tomorrow at the same time');
141+
assert.equal(moment(a).subtract({ h: 1 }).calendar(), 'i dag kl. 11:00', 'Now minus 1 hour');
142+
assert.equal(moment(a).subtract({ d: 1 }).calendar(), 'i går kl. 12:00', 'yesterday at the same time');
143+
});
144+
145+
it('calendar next week', function () {
146+
var i, m;
147+
for (i = 2; i < 7; i++) {
148+
m = moment().add({ d: i });
149+
assert.equal(m.calendar(), m.format('[på] dddd [kl.] LT'), 'Today + ' + i + ' days current time');
150+
m.hours(0).minutes(0).seconds(0).milliseconds(0);
151+
assert.equal(m.calendar(), m.format('[på] dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
152+
m.hours(23).minutes(59).seconds(59).milliseconds(999);
153+
assert.equal(m.calendar(), m.format('[på] dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
154+
}
155+
});
156+
157+
it('calendar last week', function () {
158+
var i, m;
159+
for (i = 2; i < 7; i++) {
160+
m = moment().subtract({ d: i });
161+
assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days current time');
162+
m.hours(0).minutes(0).seconds(0).milliseconds(0);
163+
assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days beginning of day');
164+
m.hours(23).minutes(59).seconds(59).milliseconds(999);
165+
assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days end of day');
166+
}
167+
});
168+
169+
it('calendar all else', function () {
170+
var weeksAgo = moment().subtract({ w: 1 }),
171+
weeksFromNow = moment().add({ w: 1 });
172+
173+
assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
174+
assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
175+
176+
weeksAgo = moment().subtract({ w: 2 });
177+
weeksFromNow = moment().add({ w: 2 });
178+
179+
assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
180+
assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
181+
});
182+
183+
it('weeks year starting sunday formatted', function () {
184+
assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
185+
assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
186+
assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
187+
assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
188+
assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
189+
});
190+
});

src/locale.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { arLocale } from './chronos/i18n/ar';
22
export { csLocale } from './chronos/i18n/cs';
3+
export { daLocale } from './chronos/i18n/da';
34
export { deLocale } from './chronos/i18n/de';
45
export { enGbLocale } from './chronos/i18n/en-gb';
56
export { esLocale } from './chronos/i18n/es';

0 commit comments

Comments
 (0)