-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api/frontend] Fix the timezone usage and migrate report published da…
…te (#551) * [api] Fix of timezone for day/month/year sub dates * [api/front] Fixing front date usage and introduce migration for reports publish date
- Loading branch information
1 parent
2a5bda8
commit 992ad43
Showing
7 changed files
with
83 additions
and
90 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
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 |
---|---|---|
@@ -1,66 +1,29 @@ | ||
import moment from 'moment-timezone'; | ||
import countdown from 'countdown'; | ||
|
||
const dayDateFormat = 'MMMM Do YYYY'; | ||
const timeDateFormat = 'HH:mm:ss'; | ||
const defaultDateFormat = 'YYYY-MM-DD'; | ||
const yearDateFormat = 'YYYY'; | ||
|
||
export const ONE_MINUTE = 60 * 1000; | ||
export const FIVE_SECONDS = 5000; | ||
export const TEN_SECONDS = FIVE_SECONDS * 2; | ||
export const ONE_SECOND = 1000; | ||
|
||
export const dayStartDate = () => { | ||
const start = new Date(); | ||
start.setHours(0, 0, 0, 0); | ||
return start; | ||
}; | ||
|
||
export const parse = (date) => moment(date); | ||
|
||
export const now = () => moment().format(); | ||
|
||
export const dayAgo = () => moment() | ||
.subtract(1, 'days') | ||
.format(); | ||
|
||
export const monthsAgo = (number) => moment() | ||
.subtract(number, 'months') | ||
.format(); | ||
|
||
export const dateMonthsAgo = (date, number) => moment(date) | ||
.subtract(number, 'months') | ||
.format(); | ||
export const dayAgo = () => moment().subtract(1, 'days').format(); | ||
|
||
export const dateMonthsAfter = (date, number) => moment(date) | ||
.add(number, 'months') | ||
.format(); | ||
export const monthsAgo = (number) => moment().subtract(number, 'months').format(); | ||
|
||
export const yearsAgo = (number) => moment() | ||
.subtract(number, 'years') | ||
.format(); | ||
|
||
export const dayFormat = (data) => (data && data !== '-' ? parse(data).format(dayDateFormat) : ''); | ||
export const yearsAgo = (number) => moment().subtract(number, 'years').format(); | ||
|
||
export const yearFormat = (data) => (data && data !== '-' ? parse(data).format(yearDateFormat) : ''); | ||
|
||
export const currentYear = () => yearFormat(now()); | ||
|
||
export const timeDiff = (start, end) => parse(start).diff(parse(end)); | ||
|
||
export const timeFormat = (data) => (data && data !== '-' ? parse(data).format(timeDateFormat) : ''); | ||
|
||
export const dateFormat = (data, specificFormat) => (data && data !== '-' | ||
? parse(data).format(specificFormat || defaultDateFormat) | ||
: ''); | ||
|
||
export const dateToISO = (date) => { | ||
const momentDate = parse(date); | ||
return momentDate.isValid() ? momentDate.format() : 'invalid-date'; | ||
}; | ||
|
||
export const dateFromNow = (dateString) => (dateString ? countdown(parse(dateString).toDate()).toString() : ''); | ||
|
||
export const convertToCountdown = (durationInMillis) => { | ||
if (durationInMillis === null) return '-'; | ||
const end = now(); | ||
const start = moment(end).subtract(durationInMillis, 'ms'); | ||
return countdown(start.toDate(), end.toDate()).toString(); | ||
}; | ||
|
||
export const logDate = () => now().format('HH:mm:ss.SSS'); |
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
42 changes: 42 additions & 0 deletions
42
opencti-platform/opencti-graphql/src/migrations/1583491791006-report-published-utc.js
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,42 @@ | ||
import { filter, map } from 'ramda'; | ||
import { Promise } from 'bluebird'; | ||
import { findAll } from '../domain/report'; | ||
import { dayFormat, executeWrite, updateAttribute } from '../database/grakn'; | ||
import { logger } from '../config/conf'; | ||
|
||
export const up = async next => { | ||
const reports = await findAll(); | ||
// For each report we need to force update | ||
if (reports && reports.edges) { | ||
const reportNodes = map(report => report.node, reports.edges); | ||
const reportsToModify = filter(r => { | ||
const expectedPublishedDay = dayFormat(r.published); | ||
const currentPublishedDay = r.published_day; | ||
return expectedPublishedDay === currentPublishedDay; | ||
}, reportNodes); | ||
logger.info(`[MIGRATION] report-published-utc > ${reportsToModify.length} reports to modify`); | ||
await Promise.map( | ||
reportsToModify, | ||
report => { | ||
return executeWrite(wTx => { | ||
return updateAttribute( | ||
report.id, | ||
'Report', | ||
{ | ||
key: 'published', | ||
value: [report.published] | ||
}, | ||
wTx, | ||
{ forceUpdate: true } // Need to force update because the impact is on sub dates of published | ||
); | ||
}); | ||
}, | ||
{ concurrency: 3 } | ||
); | ||
} | ||
next(); | ||
}; | ||
|
||
export const down = async next => { | ||
next(); | ||
}; |