Skip to content

Commit

Permalink
convert bn locale to TypeScript (date-fns#2881)
Browse files Browse the repository at this point in the history
  • Loading branch information
fturmel authored Dec 28, 2021
1 parent 927d34a commit 2d4231d
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 247 deletions.
106 changes: 0 additions & 106 deletions src/locale/bn/_lib/formatDistance/index.js

This file was deleted.

113 changes: 113 additions & 0 deletions src/locale/bn/_lib/formatDistance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import type { FormatDistanceFn, FormatDistanceLocale } from '../../../types'
import { numberToLocale } from '../localize/index'

type FormatDistanceTokenValue =
| string
| {
one: string
other: string
}

const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
lessThanXSeconds: {
one: 'প্রায় ১ সেকেন্ড',
other: 'প্রায় {{count}} সেকেন্ড',
},

xSeconds: {
one: '১ সেকেন্ড',
other: '{{count}} সেকেন্ড',
},

halfAMinute: 'আধ মিনিট',

lessThanXMinutes: {
one: 'প্রায় ১ মিনিট',
other: 'প্রায় {{count}} মিনিট',
},

xMinutes: {
one: '১ মিনিট',
other: '{{count}} মিনিট',
},

aboutXHours: {
one: 'প্রায় ১ ঘন্টা',
other: 'প্রায় {{count}} ঘন্টা',
},

xHours: {
one: '১ ঘন্টা',
other: '{{count}} ঘন্টা',
},

xDays: {
one: '১ দিন',
other: '{{count}} দিন',
},

aboutXWeeks: {
one: 'প্রায় ১ সপ্তাহ',
other: 'প্রায় {{count}} সপ্তাহ',
},

xWeeks: {
one: '১ সপ্তাহ',
other: '{{count}} সপ্তাহ',
},

aboutXMonths: {
one: 'প্রায় ১ মাস',
other: 'প্রায় {{count}} মাস',
},

xMonths: {
one: '১ মাস',
other: '{{count}} মাস',
},

aboutXYears: {
one: 'প্রায় ১ বছর',
other: 'প্রায় {{count}} বছর',
},

xYears: {
one: '১ বছর',
other: '{{count}} বছর',
},

overXYears: {
one: '১ বছরের বেশি',
other: '{{count}} বছরের বেশি',
},

almostXYears: {
one: 'প্রায় ১ বছর',
other: 'প্রায় {{count}} বছর',
},
}

const formatDistance: FormatDistanceFn = (token, count, options) => {
let result

const tokenValue = formatDistanceLocale[token]
if (typeof tokenValue === 'string') {
result = tokenValue
} else if (count === 1) {
result = tokenValue.one
} else {
result = tokenValue.other.replace('{{count}}', numberToLocale(count))
}

if (options?.addSuffix) {
if (options.comparison && options.comparison > 0) {
return result + ' এর মধ্যে'
} else {
return result + ' আগে'
}
}

return result
}

export default formatDistance
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import type { FormatLong } from '../../../types'
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index'

var dateFormats = {
const dateFormats = {
full: 'EEEE, MMMM do, y',
long: 'MMMM do, y',
medium: 'MMM d, y',
short: 'MM/dd/yyyy'
short: 'MM/dd/yyyy',
}

var timeFormats = {
const timeFormats = {
full: 'h:mm:ss a zzzz',
long: 'h:mm:ss a z',
medium: 'h:mm:ss a',
short: 'h:mm a'
short: 'h:mm a',
}

var dateTimeFormats = {
const dateTimeFormats = {
full: "{{date}} {{time}} 'সময়'",
long: "{{date}} {{time}} 'সময়'",
medium: '{{date}}, {{time}}',
short: '{{date}}, {{time}}'
short: '{{date}}, {{time}}',
}

var formatLong = {
const formatLong: FormatLong = {
date: buildFormatLongFn({
formats: dateFormats,
defaultWidth: 'full'
defaultWidth: 'full',
}),

time: buildFormatLongFn({
formats: timeFormats,
defaultWidth: 'full'
defaultWidth: 'full',
}),

dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: 'full'
})
defaultWidth: 'full',
}),
}

export default formatLong
12 changes: 0 additions & 12 deletions src/locale/bn/_lib/formatRelative/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/locale/bn/_lib/formatRelative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { FormatRelativeFn } from '../../../types'

const formatRelativeLocale = {
lastWeek: "'গত' eeee 'সময়' p",
yesterday: "'গতকাল' 'সময়' p",
today: "'আজ' 'সময়' p",
tomorrow: "'আগামীকাল' 'সময়' p",
nextWeek: "eeee 'সময়' p",
other: 'P',
}

const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) =>
formatRelativeLocale[token]

export default formatRelative
Loading

0 comments on commit 2d4231d

Please sign in to comment.