@c-time/frelio-data-json-generator 1.4.6 → 1.4.7

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/cli.js CHANGED
@@ -423,7 +423,7 @@ function formatValue(value, type, options2 = {}) {
423
423
  case "string":
424
424
  return String(value);
425
425
  case "date":
426
- return formatDate(value, options2.format);
426
+ return formatDate(value, options2.format, options2.timezone);
427
427
  case "number":
428
428
  return formatNumber(value, options2.format);
429
429
  case "escape":
@@ -461,15 +461,52 @@ function formatValue(value, type, options2 = {}) {
461
461
  return value;
462
462
  }
463
463
  }
464
- function formatDate(value, format) {
464
+ function parseOffsetMinutes(timezone) {
465
+ if (timezone === "Z") return 0;
466
+ const m = /^([+-])(\d{2}):(\d{2})$/.exec(timezone);
467
+ if (!m) return null;
468
+ const sign = m[1] === "-" ? -1 : 1;
469
+ return sign * (parseInt(m[2], 10) * 60 + parseInt(m[3], 10));
470
+ }
471
+ function offsetLabel(offsetMin) {
472
+ const sign = offsetMin < 0 ? "-" : "+";
473
+ const abs = Math.abs(offsetMin);
474
+ const hh = String(Math.floor(abs / 60)).padStart(2, "0");
475
+ const mm = String(abs % 60).padStart(2, "0");
476
+ return `${sign}${hh}:${mm}`;
477
+ }
478
+ function formatDate(value, format, timezone) {
465
479
  const date = value instanceof Date ? value : new Date(String(value));
466
480
  if (isNaN(date.getTime())) {
467
481
  return String(value);
468
482
  }
483
+ const offsetMin = timezone ? parseOffsetMinutes(timezone) : null;
469
484
  if (!format) {
470
- return date.toISOString();
485
+ if (offsetMin === null) {
486
+ return date.toISOString();
487
+ }
488
+ const shifted = new Date(date.getTime() + offsetMin * 6e4);
489
+ const base = shifted.toISOString().replace(/\.\d{3}Z$/, "");
490
+ return `${base}${offsetLabel(offsetMin)}`;
491
+ }
492
+ let year, month, day, hour, minute, second;
493
+ if (offsetMin === null) {
494
+ year = date.getFullYear();
495
+ month = date.getMonth() + 1;
496
+ day = date.getDate();
497
+ hour = date.getHours();
498
+ minute = date.getMinutes();
499
+ second = date.getSeconds();
500
+ } else {
501
+ const shifted = new Date(date.getTime() + offsetMin * 6e4);
502
+ year = shifted.getUTCFullYear();
503
+ month = shifted.getUTCMonth() + 1;
504
+ day = shifted.getUTCDate();
505
+ hour = shifted.getUTCHours();
506
+ minute = shifted.getUTCMinutes();
507
+ second = shifted.getUTCSeconds();
471
508
  }
472
- return format.replace(/YYYY/g, String(date.getFullYear())).replace(/MM/g, String(date.getMonth() + 1).padStart(2, "0")).replace(/DD/g, String(date.getDate()).padStart(2, "0")).replace(/HH/g, String(date.getHours()).padStart(2, "0")).replace(/mm/g, String(date.getMinutes()).padStart(2, "0")).replace(/ss/g, String(date.getSeconds()).padStart(2, "0"));
509
+ return format.replace(/YYYY/g, String(year)).replace(/MM/g, String(month).padStart(2, "0")).replace(/DD/g, String(day).padStart(2, "0")).replace(/HH/g, String(hour).padStart(2, "0")).replace(/mm/g, String(minute).padStart(2, "0")).replace(/ss/g, String(second).padStart(2, "0"));
473
510
  }
474
511
  function formatNumber(value, format) {
475
512
  const num = typeof value === "number" ? value : parseFloat(String(value));
@@ -595,21 +632,21 @@ function compareValues(a, b) {
595
632
  if (typeof a === "number" && typeof b === "number") {
596
633
  return a - b;
597
634
  }
598
- if (typeof a === "string" && typeof b === "string") {
599
- return a.localeCompare(b);
600
- }
601
635
  if (a instanceof Date && b instanceof Date) {
602
636
  return a.getTime() - b.getTime();
603
637
  }
604
638
  if (typeof a === "string" && typeof b === "string") {
605
- const dateA = Date.parse(a);
606
- const dateB = Date.parse(b);
607
- if (!isNaN(dateA) && !isNaN(dateB)) {
608
- return dateA - dateB;
639
+ if (isIsoDateOrDateTime(a) && isIsoDateOrDateTime(b)) {
640
+ return Date.parse(a) - Date.parse(b);
609
641
  }
642
+ return a.localeCompare(b);
610
643
  }
611
644
  return 0;
612
645
  }
646
+ var ISO_DATE_OR_DATETIME_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?([+-]\d{2}:\d{2}|Z))?$/;
647
+ function isIsoDateOrDateTime(value) {
648
+ return ISO_DATE_OR_DATETIME_REGEX.test(value);
649
+ }
613
650
 
614
651
  // src/transform/relation-expander.ts
615
652
  async function expandRelationList(field, content, context) {
@@ -674,16 +711,17 @@ async function applyCustomFields(data, customFields, content, context) {
674
711
  const expanded = await expandRelationList(field, content, context);
675
712
  result[field.field] = expanded;
676
713
  } else {
677
- const transformed = applyTransformField(field, content, result);
714
+ const transformed = applyTransformField(field, content, result, context.defaultTimezone);
678
715
  result[field.field] = transformed;
679
716
  }
680
717
  }
681
718
  return result;
682
719
  }
683
- function applyTransformField(field, content, currentData) {
720
+ function applyTransformField(field, content, currentData, defaultTimezone) {
684
721
  const sourceValue = resolveSourceExpression(field.source, content, currentData);
685
722
  return formatValue(sourceValue, field.type, {
686
723
  format: field.format,
724
+ timezone: field.timezone ?? defaultTimezone,
687
725
  length: field.length,
688
726
  suffix: field.suffix,
689
727
  separator: field.separator,
@@ -1218,7 +1256,8 @@ ${formatZodErrors(recipeValidation.errors)}`);
1218
1256
  outputRootPath,
1219
1257
  errors,
1220
1258
  warnings,
1221
- logLevel
1259
+ logLevel,
1260
+ defaultTimezone: recipe.outputTimezone
1222
1261
  };
1223
1262
  const outputs = [];
1224
1263
  for (const [contentTypeId, contentTypeRecipe] of Object.entries(recipe.contentTypes)) {