Skip to content

Commit 2763ffd

Browse files
jcpsimmonsDr.Jjoe-ayoub-segmentsgwcollins
authored
Preserve decimal Customer.io timestamps (#3656)
* Preserve decimal Customer.io timestamps * update comment to mention decimal fractional timestamps --------- Co-authored-by: Dr.J <[email protected]> Co-authored-by: Joe Ayoub <[email protected]> Co-authored-by: sgwcollins <[email protected]>
1 parent e9157c8 commit 2763ffd

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

packages/destination-actions/src/destinations/customerio/__tests__/utils.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolveIdentifiers, isIsoDate } from '../utils'
1+
import { convertValidTimestamp, resolveIdentifiers, isIsoDate } from '../utils'
22

33
describe('isIsoDate', () => {
44
it('should return true for valid ISO date with fractional seconds from 1-9 digits', () => {
@@ -79,3 +79,9 @@ describe('resolveIdentifiers', () => {
7979
expect(resolveIdentifiers({})).toBeUndefined()
8080
})
8181
})
82+
83+
describe('convertValidTimestamp', () => {
84+
it('should leave decimal unix timestamps unchanged', () => {
85+
expect(convertValidTimestamp('1712345678.123')).toBe('1712345678.123')
86+
})
87+
})

packages/destination-actions/src/destinations/customerio/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ export enum AccountRegion {
3939

4040
export const convertValidTimestamp = <Value = unknown>(value: Value): Value | number => {
4141
// Timestamps may be on a `string` field, so check if the string is only
42-
// numbers. If it is, ignore it since it's probably already a unix timestamp.
42+
// digits (optionally with a fractional part). If it is, ignore it since
43+
// it's probably already a unix timestamp (integer or decimal).
4344
// DayJS doesn't parse unix timestamps correctly outside of the `.unix()`
4445
// initializer.
45-
if (typeof value !== 'string' || /^\d+$/.test(value)) {
46+
if (typeof value !== 'string' || /^\d+(\.\d+)?$/.test(value)) {
4647
return value
4748
}
4849

0 commit comments

Comments
 (0)