Skip to content

Commit

Permalink
Rossum Sheets: gracefully handle datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml committed Jan 8, 2024
1 parent adec3a3 commit 679edc7
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 6 deletions.
38 changes: 38 additions & 0 deletions src/rossum-sheets/src/__tests__/configs/currency.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @flow

import processRossumPayload from '../../processRossumPayload';
import createMockPayload from '../createMockPayload';

it('correctly deals with currencies', () => {
const config = {
sheets: {
headers: {
columns: { A: 'number_currency' },
formulas: [
{
fx: '=A1',
target: 'notes',
},
],
},
},
};
const payload = createMockPayload(config);
expect(processRossumPayload(payload)).toMatchInlineSnapshot(`
{
"automation_blockers": [],
"messages": [],
"operations": [
{
"id": 9999,
"op": "replace",
"value": {
"content": {
"value": "42",
},
},
},
],
}
`);
});
108 changes: 108 additions & 0 deletions src/rossum-sheets/src/__tests__/configs/datetime.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// @flow

import processRossumPayload from '../../processRossumPayload';
import createMockPayload from '../createMockPayload';

it('correctly replaces date values', () => {
const config = {
sheets: {
headers: {
columns: { A: 'number_date' },
formulas: [
{
fx: '=A1',
target: 'notes',
},
],
},
},
};
const payload = createMockPayload(config);
expect(processRossumPayload(payload)).toMatchInlineSnapshot(`
{
"automation_blockers": [],
"messages": [],
"operations": [
{
"id": 9999,
"op": "replace",
"value": {
"content": {
"value": "2024-1-24",
},
},
},
],
}
`);
});

it('correctly replaces datetime values', () => {
const config = {
sheets: {
headers: {
columns: { A: 'number_datetime' },
formulas: [
{
fx: '=A1',
target: 'notes',
},
],
},
},
};
const payload = createMockPayload(config);
expect(processRossumPayload(payload)).toMatchInlineSnapshot(`
{
"automation_blockers": [],
"messages": [],
"operations": [
{
"id": 9999,
"op": "replace",
"value": {
"content": {
"value": "2024-1-24",
},
},
},
],
}
`);
});

it('correctly replaces time values', () => {
const config = {
sheets: {
headers: {
columns: { A: 'number_time' },
formulas: [
{
fx: '=A1',
target: 'notes',
},
],
},
},
};
const payload = createMockPayload(config);

// TODO: this is a bit unspecified I'd say:
expect(processRossumPayload(payload)).toMatchInlineSnapshot(`
{
"automation_blockers": [],
"messages": [],
"operations": [
{
"id": 9999,
"op": "replace",
"value": {
"content": {
"value": "0.516666666666667",
},
},
},
],
}
`);
});
35 changes: 35 additions & 0 deletions src/rossum-sheets/src/__tests__/createMockPayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ export default function createMockPayload(
value: '1000',
},
},
{
id: 2000,
schema_id: 'number_currency',
content: {
value: '42USD',
},
},
{
id: 3000,
schema_id: 'number_percent',
content: {
value: '42USD',
},
},
{
id: 4000,
schema_id: 'number_date',
content: {
value: '2024-01-24',
},
},
{
id: 5000,
schema_id: 'number_datetime',
content: {
value: '2024-01-24 12:24',
},
},
{
id: 6000,
schema_id: 'number_time',
content: {
value: '12:24',
},
},
{
id: 9999,
schema_id: 'notes',
Expand Down
6 changes: 3 additions & 3 deletions src/rossum-sheets/src/createHyperFormulaInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const options = {
arrayColumnSeparator: ',',
arrayRowSeparator: ';',
caseSensitive: false,
currencySymbol: ['$', 'USD'],
dateFormats: ['MM/DD/YYYY', 'MM/DD/YY', 'YYYY/MM/DD'],
currencySymbol: ['$', 'USD'], // TODO: disable to prevent unexpected automatic detection (?)
dateFormats: ['MM/DD/YYYY', 'MM/DD/YY', 'YYYY/MM/DD'], // TODO: disable to prevent unexpected automatic detection (?)
decimalSeparator: '.',
evaluateNullToZero: false,
functionArgSeparator: ',',
Expand All @@ -36,7 +36,7 @@ const options = {
nullYear: 30,
smartRounding: true,
thousandSeparator: '',
timeFormats: ['hh:mm', 'hh:mm:ss.sss'],
timeFormats: ['hh:mm', 'hh:mm:ss.sss'], // TODO: disable to prevent unexpected automatic detection (?)
useArrayArithmetic: true,
useRegularExpressions: false,
useWildcards: true,
Expand Down
5 changes: 2 additions & 3 deletions src/rossum-sheets/src/processRossumPayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export default function processRossumPayload(
} else if (hide != null) {
operations.push(createReplaceOperation(targetDatapoint, null, false));
}
} else if (cellType === 'NUMBER_DATE') {
// Otherwise replace date value (as an ISO string)
// TODO: support other cell types as well?
} else if (cellType === 'NUMBER_DATE' || cellType === 'NUMBER_DATETIME') {
// Otherwise replace date value (as short ISO string)
const { year, month, day } = hfInstance.numberToDate(cellValue);
operations.push(createReplaceOperation(targetDatapoint, `${year}-${month}-${day}`));
} else {
Expand Down

0 comments on commit 679edc7

Please sign in to comment.