diff --git a/package.json b/package.json index 2f73768..7c063f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "miniseed", - "version": "0.2.0", + "version": "0.2.1", "type": "module", "scripts": { "build": "vite build", diff --git a/src/miniseed.ts b/src/miniseed.ts index aa7d81a..d7e2982 100644 --- a/src/miniseed.ts +++ b/src/miniseed.ts @@ -104,21 +104,24 @@ export function serialiseToMiniSEEDBuffer( view.writeString("MS"); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-2 - view.writeUint8(3); + // NOTE: The spec specifies little-endian=true for the others, and leaves it + // unspecified for Uint8's, so I'm assuming false + view.writeUint8(3, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-3 - view.writeUint8(metadata.flags); + view.writeUint8(metadata.flags, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-4 view.writeUint32(metadata.startTime.nanoSecond); view.writeUint16(metadata.startTime.year); view.writeUint16(metadata.startTime.dayOfYear); - view.writeUint8(metadata.startTime.hour); - view.writeUint8(metadata.startTime.minute); - view.writeUint8(metadata.startTime.second); + + view.writeUint8(metadata.startTime.hour, false); + view.writeUint8(metadata.startTime.minute, false); + view.writeUint8(metadata.startTime.second, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-5 - view.writeUint8(encodingInfo.code); + view.writeUint8(encodingInfo.code, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-6 view.writeFloat64(metadata.sampleRatePeriod); @@ -132,10 +135,10 @@ export function serialiseToMiniSEEDBuffer( view.writeUint32(0); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-9 - view.writeUint8(metadata.dataPublicationVersion); + view.writeUint8(metadata.dataPublicationVersion, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-10 - view.writeUint8(sourceIdentifier.length); + view.writeUint8(sourceIdentifier.length, false); // https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html#field-11 view.writeUint16(extraHeaders.length); diff --git a/tests/date-utils.test.ts b/tests/dates.test.ts similarity index 60% rename from tests/date-utils.test.ts rename to tests/dates.test.ts index 2b54da3..fd4d9f0 100644 --- a/tests/date-utils.test.ts +++ b/tests/dates.test.ts @@ -1,5 +1,6 @@ import { describe, it, expect } from "vitest"; -import { startTimeFromDate } from "../src/miniseed"; +import { startTimeFromDate, serialiseToMiniSEEDBuffer } from "../src/miniseed"; +import jDataView from "z-jdataview-temp-publish"; describe("Date utilities", () => { it("Works with a set date", () => { @@ -37,3 +38,27 @@ describe("Date utilities", () => { expect(startTime2.dayOfYear).toEqual(61); }); }); + +describe("Date serialisation", () => { + it("Sets date fields correctly", () => { + const date = new Date("21 September 1978 21:45:30"); + const view = new jDataView( + serialiseToMiniSEEDBuffer([1, 2, 3], { + sourceIdentifier: "https://zade.viggers.net/example", + startTime: startTimeFromDate(date), + }), + undefined, + undefined, + true + ); + + console.log(view.buffer); + + expect(view.getUint32(4)).toEqual(0); // nanosecond + expect(view.getUint16(8)).toEqual(1978); // year + expect(view.getUint16(10)).toEqual(264); // day of year + expect(view.getUint8(12, false)).toEqual(21); // hour + expect(view.getUint8(13, false)).toEqual(45); // minute + expect(view.getUint8(14, false)).toEqual(30); // second + }); +}); diff --git a/tests/vaid-files.test.ts b/tests/vaid-files.test.ts index 85a82aa..f8067fa 100644 --- a/tests/vaid-files.test.ts +++ b/tests/vaid-files.test.ts @@ -66,20 +66,6 @@ describe("Date validity", () => { }); await checkData(serialised, "date-0-auto"); }); - // it("Works with a manually set 0 date", async () => { - // const serialised = serialiseToMiniSEEDUint8Array([], { - // sourceIdentifier: "https://zade.viggers.net/example", - // startTime: { - // dayOfYear: 0, - // year: 0, - // hour: 0, - // minute: 0, - // second: 0, - // nanoSecond: 0, - // }, - // }); - // await checkData(serialised, "date-0-manual"); - // }); it("Works with a new date right now", async () => { const serialised = serialiseToMiniSEEDUint8Array([], { sourceIdentifier: "https://zade.viggers.net/example",