Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ for further information about branching and tagging conventions.
## [Unreleased]
#### Added
- Print error with meta in console
- Added `dayjs` to project instead `momentjs`
- New methods to `date.util.js` for not wrapped methods to using with dates

### Changed
- Wrapped all using methods for dates by `date.util.js`

### Removed
- Removed `date-helpers.js` from helpers
- Removed `moment` and `moment-timezone` from project

## [1.13.0-rc.3] - 2021-11-09
#### Fixed
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"d3-selection": "^1.4.1",
"d3-shape": "^1.3.7",
"d3-transition": "^1.3.2",
"dayjs": "^1.11.6",
"detect-browser": "5.1.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-chai-friendly": "^0.5.0",
Expand All @@ -48,8 +49,6 @@
"iban": "^0.0.14",
"iso-country-codes": "^0.0.5",
"lodash": "^4.17.20",
"moment": "^2.24.0",
"moment-timezone": "^0.5.28",
"normalize-url": "5.0.0",
"nprogress": "^0.2.0",
"qrcode.vue": "^1.7.0",
Expand Down
29 changes: 16 additions & 13 deletions src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import i18nextBrowserLanguageDetector from 'i18next-browser-languagedetector'

// TODO: make i18n.language and i18n.languages responsive

import moment from 'moment-timezone'

import _isObject from 'lodash/isObject'
import _get from 'lodash/get'
import _merge from 'lodash/merge'

import { MathUtil } from '@/js/utils'
import { MathUtil, DateUtil } from '@/js/utils'

class I18n {
constructor () {
Expand Down Expand Up @@ -170,20 +168,25 @@ class I18n {

switch (format.toLowerCase()) {
case 'date':
return moment(param)
.format(_get(lngConfig, 'date.presets.datetime'))
return DateUtil.format(
DateUtil.tz(param), _get(lngConfig, 'date.presets.datetime')
)
case 'dmy':
return moment(param)
.format(_get(lngConfig, 'date.presets.dmy'))
return DateUtil.format(
DateUtil.tz(param), _get(lngConfig, 'date.presets.dmy')
)
case 'dmyt':
return moment(param)
.format(_get(lngConfig, 'date.presets.dmyt'))
return DateUtil.format(
DateUtil.tz(param), _get(lngConfig, 'date.presets.dmyt')
)
case 'calendar':
return moment(param)
.calendar(null, _get(lngConfig, 'date.calendar'))
return DateUtil.toHuman(
DateUtil.tz(param), undefined, _get(lngConfig, 'date.calendar')
)
case 'calendar-inline':
return moment(param)
.calendar(null, _get(lngConfig, 'date.calendarInline'))
return DateUtil.toHuman(
DateUtil.tz(param), undefined, _get(lngConfig, 'date.calendarInline')
)
case 'money':
const value = (_isObject(param) ? param.value : param) || '0'
const defaultFormat =
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { i18n } from '@/i18n'
import moment from 'moment-timezone'
import { DateUtil } from '@/js/utils'

const mockEn = {
'config': {
Expand Down Expand Up @@ -87,7 +87,7 @@ const mockEn = {

describe('the i18n is properly configured', () => {
beforeEach(async () => {
moment.tz.setDefault('UTC') // Set timezone to 'UTC', so tests won't convert to local timezone
DateUtil.setDefaultTimezone('UTC') // Set timezone to 'UTC', so tests won't convert to local timezone
await i18n.init()
await i18n.changeLanguage('en')
i18n._appendResources('en', mockEn)
Expand Down
4 changes: 2 additions & 2 deletions src/js/formers/KycGeneralFormer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { KycGeneralRecord } from '@/js/records/entities/kyc-general.record'
import { KycRequestRecord } from '@/js/records/requests/kyc-request.record'
import { KycRecoveryRequestRecord } from '@/js/records/requests/kyc-recovery-request.record'
import { BlobRecord } from '@/js/records/entities/blob.record'
import { toRFC3339 } from '@/js/helpers/date-helpers'
import { createPrivateBlob, getCurrentAccId } from '@/js/helpers/api-helpers'
import { isUSResidence, buildKycRecoveryOp } from '@/js/helpers/kyc-helpers'
import { DateUtil } from '@/js/utils'
import { keyValues } from '@/key-values'
import get from 'lodash/get'

Expand Down Expand Up @@ -150,7 +150,7 @@ export class KycGeneralFormer extends Former {
const blobValue = JSON.stringify({
first_name: str(attrs.firstName),
last_name: str(attrs.lastName),
date_of_birth: toRFC3339(attrs.dateOfBirth),
date_of_birth: DateUtil.toRFC3339(attrs.dateOfBirth),
address: {
line_1: str(address.line1),
line_2: str(address.line2),
Expand Down
19 changes: 0 additions & 19 deletions src/js/helpers/date-helpers.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/js/records/entities/poll.record.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment'
import _get from 'lodash/get'
import { DateUtil } from '@/js/utils'

const STATES = Object.freeze({
open: 1,
Expand Down Expand Up @@ -52,16 +52,16 @@ export class PollRecord {
}

get isStarted () {
return moment().isSameOrAfter(this.startsAt)
return DateUtil.isSameOrAfter(undefined, this.startsAt)
}

get isEnded () {
return moment().isSameOrAfter(this.endsAt)
return DateUtil.isSameOrAfter(undefined, this.endsAt)
}

get isInProgress () {
return this.isOpen &&
moment().isBetween(this.startsAt, this.endsAt)
DateUtil.isBetween(undefined, this.startsAt, this.endsAt)
}

static get states () {
Expand Down
10 changes: 5 additions & 5 deletions src/js/records/entities/sale.record.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import moment from 'moment'
import _get from 'lodash/get'

import { SALE_DEFINITION_TYPES } from '@/js/const/sale-definition-types.const'
import { DateUtil } from '@/js/utils'

const STATES = {
Open: 1,
Expand Down Expand Up @@ -114,16 +114,16 @@ export class SaleRecord {
get isOpened () { return this._isInState(STATES.Open) }
get isClosed () { return this._isInState(STATES.Closed) }
get isCanceled () { return this._isInState(STATES.Canceled) }
get isUpcoming () { return moment(this.startTime).isAfter(moment()) }
get isUpcoming () { return DateUtil.isAfter(this.startTime) }

/** progress info: **/

get daysToGo () {
return moment(this.startTime).diff(moment(), 'days')
return DateUtil.diff(this.startTime, undefined, 'days')
}

get daysToEnd () {
return moment(this.endTime).diff(moment(), 'days')
return DateUtil.diff(this.endTime, undefined, 'days')
}

get daysAfterEnd () {
Expand All @@ -135,7 +135,7 @@ export class SaleRecord {
}

get startsIn () {
return moment(this.startTime).diff(moment().startOf('day'), 'days')
return DateUtil.diff(this.startTime, DateUtil.startOf('day'), 'days')
}

get hardCapProgress () {
Expand Down
Loading