Skip to content

Commit

Permalink
docs: improve samples for sending DATE, DATETIME and TIMESTAMP with W…
Browse files Browse the repository at this point in the history
…rite API
  • Loading branch information
alvarowolfx committed Feb 26, 2024
1 parent ab4ab10 commit 81d6d54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions samples/append_rows_proto2.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ function main(
serializedRows = [];

// Row 7
const days = new Date('2019-02-07').getTime() / (1000 * 60 * 60 * 24);
row = {
rowNum: 7,
dateCol: 1132896,
dateCol: days, // The value is the number of days since the Unix epoch (1970-01-01)
};
serializedRows.push(SampleData.encode(row).finish());

Expand Down Expand Up @@ -172,10 +173,10 @@ function main(
serializedRows.push(SampleData.encode(row).finish());

// Row 12
const timestamp = 1641700186564;
const timestamp = new Date('2022-01-09T03:49:46.564Z').getTime();
row = {
rowNum: 12,
timestampCol: timestamp,
timestampCol: timestamp * 1000, // The value is given in microseconds since the Unix epoch (1970-01-01)
};
serializedRows.push(SampleData.encode(row).finish());

Expand Down
6 changes: 4 additions & 2 deletions samples/append_rows_table_to_proto2.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ function main(
rows = [];

// Row 7
const days = new Date('2019-02-07').getTime() / (1000 * 60 * 60 * 24);
row = {
row_num: 7,
date_col: 1132896,
date_col: days, // The value is the number of days since the Unix epoch (1970-01-01)
};
rows.push(row);

Expand Down Expand Up @@ -165,9 +166,10 @@ function main(
rows.push(row);

// Row 12
const timestamp = new Date('2022-01-09T03:49:46.564Z').getTime();
row = {
row_num: 12,
timestamp_col: 1641700186564,
timestamp_col: timestamp * 1000, // The value is given in microseconds since the Unix epoch (1970-01-01)
};
rows.push(row);

Expand Down
4 changes: 2 additions & 2 deletions samples/test/writeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('writeClient', () => {
assert.deepInclude(rows, [{float64_col: 987.6539916992188}, {row_num: 4}]);
assert.deepInclude(rows, [{int64_col: 321}, {row_num: 5}]);
assert.deepInclude(rows, [{string_col: 'octavia'}, {row_num: 6}]);
assert.deepInclude(rows, [{date_col: '5071-10-07'}, {row_num: 7}]);
assert.deepInclude(rows, [{date_col: '2019-02-07'}, {row_num: 7}]);
assert.deepInclude(rows, [
{datetime_col: '2019-02-17T11:24:00'},
{row_num: 8},
Expand All @@ -340,7 +340,7 @@ describe('writeClient', () => {
]);
assert.deepInclude(rows, [{time_col: '18:00:00'}, {row_num: 11}]);
assert.deepInclude(rows, [
{timestamp_col: '1970-01-20T00:01:40.186564000Z'},
{timestamp_col: '2022-01-09T03:49:46.564Z'},
{row_num: 12},
]);
assert.deepInclude(rows, [{int64_list: [1999, 2001]}, {row_num: 13}]);
Expand Down

0 comments on commit 81d6d54

Please sign in to comment.