[GH-912] Discard (milliseconds) when counting create/update dates (#981)
* [GH-912] Discard (milliseconds) when counting create/update dates Card creation and update dates are displayed with hours and minutes only on the UI. When the full timestamp is used for counting unique values, this leads to a discrepancy because the (milli)second parts impact the count but are not visible to the user. This commit fixes creation and update timestamps to minutes accuracy before their values enter any calculation. Closes: #912 * Add parentheses to please the linter * Add 1s to test fixtures to cover bug scenario * Add dedicated unit tests for creation / update 1s and 1m apart Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
This commit is contained in:
parent
22bfe2da13
commit
0291052c1c
2 changed files with 42 additions and 2 deletions
|
@ -79,6 +79,20 @@ describe('components/calculations/calculation logic', () => {
|
|||
card5.fields.properties.property_person = ''
|
||||
card5.fields.properties.property_checkbox = ''
|
||||
|
||||
// clone of card 3 but created / updated 1 second later
|
||||
const card6 = TestBlockFactory.createCard(board)
|
||||
card6.createAt = 1625639401000
|
||||
card6.createdBy = 'user_id_2'
|
||||
card6.updateAt = 1625639401000
|
||||
card6.modifiedBy = 'user_id_2'
|
||||
|
||||
// clone of card 3 but created / updated 1 minute later
|
||||
const card7 = TestBlockFactory.createCard(board)
|
||||
card7.createAt = 1625639460000
|
||||
card7.createdBy = 'user_id_2'
|
||||
card7.updateAt = 1625639460000
|
||||
card7.modifiedBy = 'user_id_2'
|
||||
|
||||
const cards = [card1, card2, card3, card4]
|
||||
|
||||
const properties: Record<string, IPropertyTemplate> = {
|
||||
|
@ -188,6 +202,26 @@ describe('components/calculations/calculation logic', () => {
|
|||
})
|
||||
})
|
||||
|
||||
test('countUniqueValue for cards created 1 second apart', () => {
|
||||
const result = Calculations.countUniqueValue([card3, card6], properties.createdTime)
|
||||
expect(result).toBe('1')
|
||||
})
|
||||
|
||||
test('countUniqueValue for cards updated 1 second apart', () => {
|
||||
const result = Calculations.countUniqueValue([card3, card6], properties.updatedTime)
|
||||
expect(result).toBe('1')
|
||||
})
|
||||
|
||||
test('countUniqueValue for cards created 1 minute apart', () => {
|
||||
const result = Calculations.countUniqueValue([card3, card7], properties.createdTime)
|
||||
expect(result).toBe('2')
|
||||
})
|
||||
|
||||
test('countUniqueValue for cards updated 1 minute apart', () => {
|
||||
const result = Calculations.countUniqueValue([card3, card7], properties.updatedTime)
|
||||
expect(result).toBe('2')
|
||||
})
|
||||
|
||||
test('sum', () => {
|
||||
const result = Calculations.sum(cards, properties.number)
|
||||
expect(result).toBe('170')
|
||||
|
|
|
@ -18,13 +18,13 @@ function getCardProperty(card: Card, property: IPropertyTemplate): string | stri
|
|||
return card.createdBy
|
||||
}
|
||||
case ('createdTime'): {
|
||||
return card.createAt
|
||||
return fixTimestampToMinutesAccuracy(card.createAt)
|
||||
}
|
||||
case ('updatedBy'): {
|
||||
return card.modifiedBy
|
||||
}
|
||||
case ('updatedTime'): {
|
||||
return card.updateAt
|
||||
return fixTimestampToMinutesAccuracy(card.updateAt)
|
||||
}
|
||||
default: {
|
||||
return card.fields.properties[property.id]
|
||||
|
@ -32,6 +32,12 @@ function getCardProperty(card: Card, property: IPropertyTemplate): string | stri
|
|||
}
|
||||
}
|
||||
|
||||
function fixTimestampToMinutesAccuracy(timestamp: number) {
|
||||
// For timestamps that are formatted as hour/minute strings on the UI, we throw away the (milli)seconds
|
||||
// so that things like counting unique values work intuitively
|
||||
return timestamp - (timestamp % 60000)
|
||||
}
|
||||
|
||||
function cardsWithValue(cards: readonly Card[], property: IPropertyTemplate): Card[] {
|
||||
return cards.
|
||||
filter((card) => Boolean(getCardProperty(card, property)))
|
||||
|
|
Loading…
Reference in a new issue