bfg-common 1.4.402 → 1.4.403

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugins/date.ts +30 -1
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.403",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
package/plugins/date.ts CHANGED
@@ -1,5 +1,13 @@
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'
@@ -167,6 +175,27 @@ export default defineNuxtPlugin(() => {
167
175
  })
168
176
  }
169
177
 
178
+ // Определяем сколько времени осталось
179
+ // time = seconds; units = [seconds, minutes, hours, days, months, years]
180
+ const timeToTimeLeft = (time: number, units: string[]) => {
181
+ const seconds = Math.floor(time % 60)
182
+ const minutes = Math.floor((time / 60) % 60)
183
+ const hours = Math.floor((time / 60 / 60) % 24)
184
+ const days = Math.floor((time / 60 / 60 / 24) % 30)
185
+ const months = Math.floor((time / 60 / 60 / 24 / 30) % 12)
186
+ const years = Math.floor(time / 60 / 60 / 24 / 30 / 12)
187
+
188
+ let result = ''
189
+ if (seconds) result += `${seconds}${units[0]}`
190
+ if (minutes) result += `${minutes}${units[1]} `
191
+ if (hours) result += `${hours}${units[2]} `
192
+ if (days) result += `${days}${units[3]} `
193
+ if (months) result += `${months}${units[4]} `
194
+ if (years) result += `${years}${units[5]} `
195
+
196
+ return result
197
+ }
198
+
170
199
  return {
171
200
  provide: {
172
201
  isDate,