swcombine.js 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -173,7 +173,7 @@ const _SwcTimestamp = class _SwcTimestamp {
173
173
  const seconds = Math.floor(msSinceSwcStart / 1e3);
174
174
  return new _SwcTimestamp({
175
175
  year,
176
- day,
176
+ day: day + 1,
177
177
  hour,
178
178
  minute,
179
179
  second: seconds
@@ -253,6 +253,20 @@ const _SwcTimestamp = class _SwcTimestamp {
253
253
  const endTime = otherTimestamp.toUnixTimestamp("sec");
254
254
  return secondsToDuration(endTime - startTime);
255
255
  }
256
+ /**
257
+ * Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
258
+ * @param format 'full' = Year 25, Day 60, 12:45:21, 'short' = 'Y26 D60, 12:45:21', 'day' = 'Y26 D60'.
259
+ */
260
+ toString(format = "full") {
261
+ switch (format) {
262
+ case "full":
263
+ return `Year ${this.year} Day ${this.day}, ${this.hour}:${this.minute}:${this.second}`;
264
+ case "short":
265
+ return `Y${this.year} D${this.day}, ${this.hour}:${this.minute}:${this.second}`;
266
+ case "day":
267
+ return `Y${this.year} D${this.day}`;
268
+ }
269
+ }
256
270
  /**
257
271
  * @returns {number}
258
272
  * @private
@@ -265,13 +279,13 @@ const _SwcTimestamp = class _SwcTimestamp {
265
279
  let msSinceSwcStart = 0;
266
280
  msSinceSwcStart += this.year * msPerYear;
267
281
  msSinceSwcStart += (this.day - 1) * msPerDay;
268
- msSinceSwcStart += (this.hour + 1) * msPerHour;
282
+ msSinceSwcStart += this.hour * msPerHour;
269
283
  msSinceSwcStart += this.minute * msPerMinute;
270
284
  msSinceSwcStart += this.second * 1e3;
271
285
  return msSinceSwcStart;
272
286
  }
273
287
  };
274
- __publicField(_SwcTimestamp, "swcStart", new Date(1998, 11, 3, 7, 0, 0));
288
+ __publicField(_SwcTimestamp, "swcStart", new Date(Date.UTC(1998, 11, 3, 7, 0, 0)));
275
289
  let SwcTimestamp = _SwcTimestamp;
276
290
  const durationToSeconds = (duration) => (duration.years || 0) * 365 * 24 * 60 * 60 + (duration.days || 0) * 24 * 60 * 60 + (duration.hours || 0) * 60 * 60 + (duration.minutes || 0) * 60 + (duration.seconds || 0);
277
291
  const secondsToDuration = (seconds) => {
@@ -493,7 +507,7 @@ function findPrivilege(privileges, groupName, privilegeName) {
493
507
  return !!privilege && privilege.value === "true";
494
508
  }
495
509
  function mapSwcLocation(location) {
496
- var _a, _b, _c, _d;
510
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
497
511
  if (!location)
498
512
  return void 0;
499
513
  return {
@@ -507,19 +521,19 @@ function mapSwcLocation(location) {
507
521
  planet: !((_c = location.planet) == null ? void 0 : _c.value) ? void 0 : { uid: new SwcUid(location.planet.attributes.uid), name: location.planet.value },
508
522
  city: !((_d = location.city) == null ? void 0 : _d.value) ? void 0 : { uid: new SwcUid(location.city.attributes.uid), name: location.city.value },
509
523
  coordinates: {
510
- galaxy: { x: location.coordinates.galaxy.attributes.x, y: location.coordinates.galaxy.attributes.y },
511
- system: parseCoords(location.coordinates.system.attributes.x, location.coordinates.system.attributes.y),
512
- surface: parseCoords(location.coordinates.surface.attributes.x, location.coordinates.surface.attributes.y),
513
- ground: parseCoords(location.coordinates.ground.attributes.x, location.coordinates.ground.attributes.y)
524
+ galaxy: parseCoords((_e = location.coordinates.galaxy.attributes) == null ? void 0 : _e.x, (_f = location.coordinates.galaxy.attributes) == null ? void 0 : _f.y),
525
+ system: parseCoords((_g = location.coordinates.system.attributes) == null ? void 0 : _g.x, (_h = location.coordinates.system.attributes) == null ? void 0 : _h.y),
526
+ surface: parseCoords((_i = location.coordinates.surface.attributes) == null ? void 0 : _i.x, (_j = location.coordinates.surface.attributes) == null ? void 0 : _j.y),
527
+ ground: parseCoords((_k = location.coordinates.ground.attributes) == null ? void 0 : _k.x, (_l = location.coordinates.ground.attributes) == null ? void 0 : _l.y)
514
528
  }
515
529
  };
516
530
  }
517
531
  function parseCoords(x, y) {
518
- if (x === null || y === null)
532
+ if (x === null || x === void 0 || y === null || y === void 0)
519
533
  return { x: null, y: null };
520
- const intX = Number.parseInt(x, 10);
521
- const intY = Number.parseInt(y, 10);
522
- if (Number.isNaN(intX) || Number.isNaN(intY))
534
+ const intX = typeof x === "number" ? x : Number.parseInt(x, 10);
535
+ const intY = typeof y === "number" ? y : Number.parseInt(y, 10);
536
+ if (!Number.isFinite(intX) || !Number.isFinite(intY))
523
537
  return { x: null, y: null };
524
538
  return { x: intX, y: intY };
525
539
  }
package/dist/index.d.ts CHANGED
@@ -440,6 +440,11 @@ export declare class SwcTimestamp {
440
440
  */
441
441
  subtract(duration: Partial<Duration>): SwcTimestamp;
442
442
  getDurationTo(otherTimestamp: SwcTimestamp): Duration;
443
+ /**
444
+ * Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
445
+ * @param format 'full' = Year 25, Day 60, 12:45:21, 'short' = 'Y26 D60, 12:45:21', 'day' = 'Y26 D60'.
446
+ */
447
+ toString(format?: 'full' | 'short' | 'day'): string;
443
448
  /**
444
449
  * @returns {number}
445
450
  * @private
package/dist/index.esm.js CHANGED
@@ -171,7 +171,7 @@ const _SwcTimestamp = class _SwcTimestamp {
171
171
  const seconds = Math.floor(msSinceSwcStart / 1e3);
172
172
  return new _SwcTimestamp({
173
173
  year,
174
- day,
174
+ day: day + 1,
175
175
  hour,
176
176
  minute,
177
177
  second: seconds
@@ -251,6 +251,20 @@ const _SwcTimestamp = class _SwcTimestamp {
251
251
  const endTime = otherTimestamp.toUnixTimestamp("sec");
252
252
  return secondsToDuration(endTime - startTime);
253
253
  }
254
+ /**
255
+ * Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
256
+ * @param format 'full' = Year 25, Day 60, 12:45:21, 'short' = 'Y26 D60, 12:45:21', 'day' = 'Y26 D60'.
257
+ */
258
+ toString(format = "full") {
259
+ switch (format) {
260
+ case "full":
261
+ return `Year ${this.year} Day ${this.day}, ${this.hour}:${this.minute}:${this.second}`;
262
+ case "short":
263
+ return `Y${this.year} D${this.day}, ${this.hour}:${this.minute}:${this.second}`;
264
+ case "day":
265
+ return `Y${this.year} D${this.day}`;
266
+ }
267
+ }
254
268
  /**
255
269
  * @returns {number}
256
270
  * @private
@@ -263,13 +277,13 @@ const _SwcTimestamp = class _SwcTimestamp {
263
277
  let msSinceSwcStart = 0;
264
278
  msSinceSwcStart += this.year * msPerYear;
265
279
  msSinceSwcStart += (this.day - 1) * msPerDay;
266
- msSinceSwcStart += (this.hour + 1) * msPerHour;
280
+ msSinceSwcStart += this.hour * msPerHour;
267
281
  msSinceSwcStart += this.minute * msPerMinute;
268
282
  msSinceSwcStart += this.second * 1e3;
269
283
  return msSinceSwcStart;
270
284
  }
271
285
  };
272
- __publicField(_SwcTimestamp, "swcStart", new Date(1998, 11, 3, 7, 0, 0));
286
+ __publicField(_SwcTimestamp, "swcStart", new Date(Date.UTC(1998, 11, 3, 7, 0, 0)));
273
287
  let SwcTimestamp = _SwcTimestamp;
274
288
  const durationToSeconds = (duration) => (duration.years || 0) * 365 * 24 * 60 * 60 + (duration.days || 0) * 24 * 60 * 60 + (duration.hours || 0) * 60 * 60 + (duration.minutes || 0) * 60 + (duration.seconds || 0);
275
289
  const secondsToDuration = (seconds) => {
@@ -491,7 +505,7 @@ function findPrivilege(privileges, groupName, privilegeName) {
491
505
  return !!privilege && privilege.value === "true";
492
506
  }
493
507
  function mapSwcLocation(location) {
494
- var _a, _b, _c, _d;
508
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
495
509
  if (!location)
496
510
  return void 0;
497
511
  return {
@@ -505,19 +519,19 @@ function mapSwcLocation(location) {
505
519
  planet: !((_c = location.planet) == null ? void 0 : _c.value) ? void 0 : { uid: new SwcUid(location.planet.attributes.uid), name: location.planet.value },
506
520
  city: !((_d = location.city) == null ? void 0 : _d.value) ? void 0 : { uid: new SwcUid(location.city.attributes.uid), name: location.city.value },
507
521
  coordinates: {
508
- galaxy: { x: location.coordinates.galaxy.attributes.x, y: location.coordinates.galaxy.attributes.y },
509
- system: parseCoords(location.coordinates.system.attributes.x, location.coordinates.system.attributes.y),
510
- surface: parseCoords(location.coordinates.surface.attributes.x, location.coordinates.surface.attributes.y),
511
- ground: parseCoords(location.coordinates.ground.attributes.x, location.coordinates.ground.attributes.y)
522
+ galaxy: parseCoords((_e = location.coordinates.galaxy.attributes) == null ? void 0 : _e.x, (_f = location.coordinates.galaxy.attributes) == null ? void 0 : _f.y),
523
+ system: parseCoords((_g = location.coordinates.system.attributes) == null ? void 0 : _g.x, (_h = location.coordinates.system.attributes) == null ? void 0 : _h.y),
524
+ surface: parseCoords((_i = location.coordinates.surface.attributes) == null ? void 0 : _i.x, (_j = location.coordinates.surface.attributes) == null ? void 0 : _j.y),
525
+ ground: parseCoords((_k = location.coordinates.ground.attributes) == null ? void 0 : _k.x, (_l = location.coordinates.ground.attributes) == null ? void 0 : _l.y)
512
526
  }
513
527
  };
514
528
  }
515
529
  function parseCoords(x, y) {
516
- if (x === null || y === null)
530
+ if (x === null || x === void 0 || y === null || y === void 0)
517
531
  return { x: null, y: null };
518
- const intX = Number.parseInt(x, 10);
519
- const intY = Number.parseInt(y, 10);
520
- if (Number.isNaN(intX) || Number.isNaN(intY))
532
+ const intX = typeof x === "number" ? x : Number.parseInt(x, 10);
533
+ const intY = typeof y === "number" ? y : Number.parseInt(y, 10);
534
+ if (!Number.isFinite(intX) || !Number.isFinite(intY))
521
535
  return { x: null, y: null };
522
536
  return { x: intX, y: intY };
523
537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swcombine.js",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "swcombine",