bfg-common 1.4.402 → 1.4.404

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2203,10 +2203,13 @@
2203
2203
  "ioCountForPathSwitch": "Колькасць уводаў-вывадаў для пераключэння шляху",
2204
2204
  "byteCountForPathSwitch": "Колькасць байтаў для пераключэння шляху",
2205
2205
  "weight": "Вага",
2206
+ "seconds2": "секунд(ы)",
2207
+ "minutes2": "Хвілін(ы)",
2206
2208
  "hours2": "Час(ы)",
2207
2209
  "days2": "Дзень(ы)",
2208
2210
  "weeks2": "Тыдзень(ы)",
2209
- "months2": "Месяцы(ы)",
2211
+ "months2": "Месяц(ы)",
2212
+ "years2": "Год(ы)",
2210
2213
  "from2": "ад",
2211
2214
  "to2": "К",
2212
2215
  "resetToDefault": "Скінуць да стандартных",
@@ -2207,10 +2207,13 @@
2207
2207
  "byteCountForPathSwitch": "Byte count for path switch",
2208
2208
  "theValueEitherEmptyOrInvalid": "The value is either empty or invalid",
2209
2209
  "weight": "Weight",
2210
+ "seconds2": "Second(s)",
2211
+ "minutes2": "Minute(s)",
2210
2212
  "hours2": "Hour(s)",
2211
2213
  "days2": "Day(s)",
2212
2214
  "weeks2": "Week(s)",
2213
- "months2": "Months(s)",
2215
+ "months2": "Month(s)",
2216
+ "years2": "Year(s)",
2214
2217
  "from2": "from",
2215
2218
  "to2": "To",
2216
2219
  "resetToDefault": "Reset To Default",
@@ -2207,10 +2207,13 @@
2207
2207
  "byteCountForPathSwitch": "Բայթերի քանակը ուղու փոխարկիչի համար",
2208
2208
  "theValueEitherEmptyOrInvalid": "Այս արժեքը կամ դատարկ է, կամ անվավեր",
2209
2209
  "weight": "Քաշը",
2210
- "hours2": "Ժամ(ներ)",
2211
- "days2": "Օր(ներ)",
2210
+ "seconds2": "Վայրկյան(ներ)",
2211
+ "minutes2": "Րոպե(ներ)",
2212
+ "hours2": "Ժամ(եր)",
2213
+ "days2": "Օր(եր)",
2212
2214
  "weeks2": "Շաբաթ(ներ)",
2213
- "months2": "Ամիսներ(ներ)",
2215
+ "months2": "Ամիս(ներ)",
2216
+ "years2": "Տարի(ներ)",
2214
2217
  "from2": "ից",
2215
2218
  "to2": "Դեպի",
2216
2219
  "resetToDefault": "Վերականգնել լռելյայնին",
@@ -2206,10 +2206,13 @@
2206
2206
  "byteCountForPathSwitch": "Жолды ауыстыру үшін байт саны",
2207
2207
  "theValueEitherEmptyOrInvalid": "Мән бос немесе жарамсыз",
2208
2208
  "weight": "Салмағы",
2209
+ "seconds2": "Секунд(лар)",
2210
+ "minutes2": "Минут(лар)",
2209
2211
  "hours2": "Сағат(лар)",
2210
2212
  "days2": "Күн(лар)",
2211
2213
  "weeks2": "Апта(лар)",
2212
2214
  "months2": "Айлар(лар)",
2215
+ "years2": "Жыл(дар)",
2213
2216
  "from2": "бастап",
2214
2217
  "to2": "К",
2215
2218
  "resetToDefault": "Әдепкіге қайта орнату",
@@ -2208,10 +2208,13 @@
2208
2208
  "byteCountForPathSwitch": "Количество байт для переключения пути",
2209
2209
  "theValueEitherEmptyOrInvalid": "Значение либо пустое, либо недопустимое",
2210
2210
  "weight": "Вес",
2211
+ "seconds2": "Секунда(ы)",
2212
+ "minutes2": "Минута(ы)",
2211
2213
  "hours2": "Час(ы)",
2212
2214
  "days2": "День(ы)",
2213
2215
  "weeks2": "Неделя(ы)",
2214
- "months2": "Месяцы(ы)",
2216
+ "months2": "Месяц(ы)",
2217
+ "years2": "Год(ы)",
2215
2218
  "from2": "От",
2216
2219
  "to2": "До",
2217
2220
  "resetToDefault": "Сбросить настройки по умолчанию",
@@ -2205,10 +2205,13 @@
2205
2205
  "byteCountForPathSwitch": "路径切换的字节数",
2206
2206
  "theValueEitherEmptyOrInvalid": "该值为空或无效",
2207
2207
  "weight": "重量",
2208
+ "seconds2": "第二次",
2209
+ "minutes2": "分钟)",
2208
2210
  "hours2": "小时)",
2209
2211
  "days2": "天)",
2210
2212
  "weeks2": "星期)",
2211
- "months2": "月份",
2213
+ "months2": "",
2214
+ "years2": "年)",
2212
2215
  "from2": "从",
2213
2216
  "to2": "到",
2214
2217
  "resetToDefault": "重置为默认值",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.4.402",
4
+ "version": "1.4.404",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
package/plugins/date.ts CHANGED
@@ -1,8 +1,17 @@
1
1
  import { defineNuxtPlugin } from '#app'
2
- import { format } from 'date-fns'
2
+ import {
3
+ format,
4
+ // differenceInYears,
5
+ // differenceInMonths,
6
+ // differenceInDays,
7
+ // differenceInHours,
8
+ // differenceInMinutes,
9
+ // differenceInSeconds,
10
+ } from 'date-fns'
3
11
  import * as localizations from 'date-fns/locale'
4
12
  import type { UI_T_DateFormat } from '~/lib/models/plugins/date/types'
5
13
  import type { UI_I_Dateformat } from '~/lib/models/plugins/date/interfaces'
14
+ import type { UI_I_ArbitraryObject } from '~/lib/models/interfaces'
6
15
 
7
16
  export default defineNuxtPlugin(() => {
8
17
  // Проверяем переданое является датой
@@ -167,6 +176,55 @@ export default defineNuxtPlugin(() => {
167
176
  })
168
177
  }
169
178
 
179
+ const correctRuUnit = (value: number, type: string): string => {
180
+ let result = ''
181
+
182
+ const forms: UI_I_ArbitraryObject<string[]> = {
183
+ second: ['Секунда', 'Секунды', 'Секунд'],
184
+ minute: ['Минута', 'Минуты', 'Минут'],
185
+ hour: ['Час', 'Часа', 'Часов'],
186
+ day: ['День', 'Дня', 'Дней'],
187
+ week: ['Неделя', 'Недели', 'Недель'],
188
+ month: ['Месяц', 'Месяца', 'Месяцев'],
189
+ year: ['Год', 'Года', 'Лет'],
190
+ }
191
+
192
+ const isFirstType = value % 10 === 1 && value % 100 !== 11
193
+ const isSecondType =
194
+ [2, 3, 4].includes(value % 10) && ![12, 13, 14].includes(value % 100)
195
+
196
+ if (isFirstType) {
197
+ result = forms[type][0]
198
+ } else if (isSecondType) {
199
+ result = forms[type][1]
200
+ } else {
201
+ result = forms[type][2]
202
+ }
203
+
204
+ return result
205
+ }
206
+
207
+ // Определяем сколько времени осталось
208
+ // time = seconds; units = [seconds, minutes, hours, days, months, years]
209
+ const timeToTimeLeft = (time: number, units: string[]) => {
210
+ const seconds = Math.floor(time % 60)
211
+ const minutes = Math.floor((time / 60) % 60)
212
+ const hours = Math.floor((time / 60 / 60) % 24)
213
+ const days = Math.floor((time / 60 / 60 / 24) % 30)
214
+ const months = Math.floor((time / 60 / 60 / 24 / 30) % 12)
215
+ const years = Math.floor(time / 60 / 60 / 24 / 30 / 12)
216
+
217
+ let result = ''
218
+ if (seconds) result += `${seconds}${units[0]}`
219
+ if (minutes) result += `${minutes}${units[1]} `
220
+ if (hours) result += `${hours}${units[2]} `
221
+ if (days) result += `${days}${units[3]} `
222
+ if (months) result += `${months}${units[4]} `
223
+ if (years) result += `${years}${units[5]} `
224
+
225
+ return result
226
+ }
227
+
170
228
  return {
171
229
  provide: {
172
230
  isDate,
@@ -176,6 +234,8 @@ export default defineNuxtPlugin(() => {
176
234
  formattedDate,
177
235
  formattedDatetime,
178
236
  getUnixByDate,
237
+ correctRuUnit,
238
+ timeToTimeLeft,
179
239
  },
180
240
  }
181
241
  })