-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from saknarak/master
add thai locale
- Loading branch information
Showing
3 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import dayjs from 'dayjs' | ||
|
||
const locale = { | ||
name: 'th', | ||
weekdays: 'อาทิตย์_จันทร์_อังคาร_พุธ_พฤหัสบดี_ศุกร์_เสาร์'.split('_'), | ||
weekdaysShort: 'อา._จ._อ._พ._พฤ._ศ._ส.'.split('_'), | ||
months: 'มกราคม_กุมภาพันธ์_มีนาคม_เมษายน_พฤษภาคม_มิถุนายน_กรกฏาคม_สิงหาคม_กันยายน_ตุลาคม_พฤศจิกายน_ธันวาคม'.split('_'), | ||
monthsShort: 'ม.ค._ก.พ._มี.ค._เม.ย._พ.ค._มิ.ย._ก.ค._ส.ค._ก.ย._ต.ค._พ.ย._ธ.ค.'.split('_'), | ||
relativeTime: { | ||
future: 'อีก %s', | ||
past: '%s ที่ผ่านมา', | ||
s: 'ไม่กี่วิ', | ||
m: 'นาที', | ||
mm: '%d นาที', | ||
h: 'ชั่วโมง', | ||
hh: '%d ชั่วโมง', | ||
d: 'วัน', | ||
dd: '%d วัน', | ||
M: 'เดือน', | ||
MM: '%d เดือน', | ||
y: 'ปี', | ||
yy: '%d ปี' | ||
}, | ||
ordinal: n => `${n}.` | ||
} | ||
|
||
dayjs.locale(locale, null, true) | ||
|
||
export default locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../src' | ||
import th from '../src/locale/th' | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
const format = 'dddd D, MMMM' | ||
|
||
it('Uses Thai locale through constructor', () => { // not recommend | ||
expect(dayjs('2018-4-28', { locale: th }) | ||
.format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
expect(dayjs('2018-4-28', { locale: th }) | ||
.format('ddd D, MMM')) | ||
.toBe('ส. 28, เม.ย.') | ||
}) | ||
|
||
it('set locale for one instance only', () => { | ||
expect(dayjs('2018-4-28') | ||
.format(format)) | ||
.toBe('Saturday 28, April') | ||
|
||
expect(dayjs('2018-4-28') | ||
.locale(th).format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
|
||
expect(dayjs('2018-4-28') | ||
.format(format)) | ||
.toBe('Saturday 28, April') | ||
}) | ||
|
||
it('set locale for this line only', () => { | ||
expect(dayjs('2018-4-28').format(format, th)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
}) | ||
|
||
it('set global locale', () => { | ||
dayjs.locale('en') | ||
expect(dayjs('2018-4-28').format(format)) | ||
.toBe('Saturday 28, April') | ||
dayjs.locale(th) | ||
expect(dayjs('2018-4-28').format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
dayjs.locale('en') | ||
expect(dayjs('2018-4-28').format(format)) | ||
.toBe('Saturday 28, April') | ||
}) | ||
|
||
it('immutable instance locale', () => { | ||
dayjs.locale('en') | ||
const origin = dayjs('2018-4-28') | ||
expect(origin.format(format)) | ||
.toBe('Saturday 28, April') | ||
expect(origin.locale('th').format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
const changed = origin.locale('th') | ||
expect(changed.format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
expect(origin.format(format)) | ||
.toBe('Saturday 28, April') | ||
}) | ||
|
||
describe('Instance locale inheritance', () => { | ||
const thDayjs = dayjs('2018-4-28').locale(th) | ||
|
||
it('Clone', () => { | ||
expect(thDayjs.clone().format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
expect(dayjs(thDayjs).format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
}) | ||
|
||
it('StartOf EndOf', () => { | ||
expect(thDayjs.startOf('year').format(format)) | ||
.toBe('จันทร์ 1, มกราคม') | ||
expect(thDayjs.endOf('day').format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
}) | ||
|
||
it('Set', () => { | ||
expect(thDayjs.set('year', 2017).format(format)) | ||
.toBe('ศุกร์ 28, เมษายน') | ||
}) | ||
|
||
it('Add', () => { | ||
expect(thDayjs.add(1, 'year').format(format)) | ||
.toBe('อาทิตย์ 28, เมษายน') | ||
expect(thDayjs.add(1, 'month').format(format)) | ||
.toBe('จันทร์ 28, พฤษภาคม') | ||
expect(thDayjs.add(1, 'minute').format(format)) | ||
.toBe('เสาร์ 28, เมษายน') | ||
}) | ||
}) |