DEV Community

Roberto Luna
Roberto Luna

Posted on

Fixing the Date‑Offset Bug in Bluesky Payload Generation for My Content‑Automation Pipeline

Fixing the Date‑Offset Bug in Bluesky Payload Generation for My Content‑Automation Pipeline

TL;DR: I discovered that the automated script was writing the wrong date key in the Bluesky JSON payload, causing posts to appear a day early. By adjusting the date handling logic and adding a unit test, the payload now matches the intended publish date and the whole pipeline runs without manual fixes.


The Problem

My daily content‑automation repo creates a set of files (Medium markdown, Substack markdown, Bluesky JSON, etc.) from a single source of truth. On 2026‑11‑13 the generated bluesky_en.json looked like this:

[
  {
    "type": "progress",
    "text": "Finally got the Bluesky payload generation working in bluesky_en.json. After a messy merge I realized the date key was off by one day, s
Enter fullscreen mode Exit fullscreen mode

The text was truncated, but more importantly the date field (not shown in the diff) was being set to 2026‑11‑11 instead of 2026‑11‑12. The result? The post appeared on Bluesky a day before the intended schedule, breaking my “publish‑once‑every‑day” guarantee.

The symptom surfaced when the GitHub Actions workflow that pushes the JSON to Bluesky failed validation:

ERROR: payload validation failed – expected date "2026-11-12", got "2026-11-11"
Enter fullscreen mode Exit fullscreen mode

What I Tried First

My first instinct was to manually edit the JSON file after generation. I opened content/2026/11/12/content-automation/bluesky_en.json, corrected the date, and re‑ran the workflow. It worked, but the fix vanished on the next run because the generator overwrote the file.

I also tried a quick string replace in the generation script:

payload = payload.replace(/"date": "\d{4}-\d{2}-\d{2}"/, `"date": "${today}"`);
Enter fullscreen mode Exit fullscreen mode

Unfortunately today was computed using new Date() without timezone normalization, so on my local machine (UTC‑5) it still produced the previous day when the CI runner (UTC) executed it. The bug persisted.


The Implementation

1. Locate the generator

The script lives at scripts/generate-bluesky-payload.js. It reads the daily metadata from content/2026/11/12/content-automation/metadata.json and builds the JSON payload.

// scripts/generate-bluesky-payload.js
const fs = require('fs');
const path = require('path');

function loadMetadata(date) {
  const metaPath = path.join(__dirname, '..', 'content', date, 'content-automation', 'metadata.json');
  return JSON.parse(fs.readFileSync(metaPath, 'utf8'));
}
Enter fullscreen mode Exit fullscreen mode

2. Fix the date calculation

The original code used:

const today = new Date().toISOString().slice(0, 10); // e.g. "2026-11-11"
Enter fullscreen mode Exit fullscreen mode

Running in UTC caused the off‑by‑one error. I switched to a timezone‑aware library (date-fns-tz) and forced the date to America/Mexico_City (the timezone of my audience).

// Add at the top
const { utcToZonedTime, format } = require('date-fns-tz');

function getLocalDate() {
  const utcDate = new Date();
  const tz = 'America/Mexico_City';
  const zonedDate = utcToZonedTime(utcDate, tz);
  return format(zonedDate, 'yyyy-MM-dd');
}
Enter fullscreen mode Exit fullscreen mode

Now the payload builder uses getLocalDate():

const payload = {
  type: 'progress',
  text: `Finally got the Bluesky payload generation working in bluesky_en.json. After a messy merge I realized the date key was off by one day, so I fixed it.`,
  date: getLocalDate(),
};
Enter fullscreen mode Exit fullscreen mode

3. Update the CI step

The GitHub Action that runs the script (.github/workflows/publish-bluesky.yml) needed a small tweak to install the new dependency:

- name: Install deps
  run: npm install date-fns-tz
Enter fullscreen mode Exit fullscreen mode

4. Add a regression test

To prevent future regressions, I added a Jest test under tests/bluesky-payload.test.js:

const { getLocalDate } = require('../scripts/generate-bluesky-payload');

test('getLocalDate returns date in Mexico City timezone', () => {
  // Mock Date to a known UTC timestamp
  const MOCK_UTC = new Date('2026-11-12T04:00:00Z'); // 2026-11-12 00:00 MX time
  jest.spyOn(global, 'Date').mockImplementation(() => MOCK_UTC);
  expect(getLocalDate()).toBe('2026-11-12');
});
Enter fullscreen mode Exit fullscreen mode

Running npm test now fails if the timezone logic breaks.

5. Verify the output

After the changes, the generated file looks correct:

[
  {
    "type": "progress",
    "text": "Finally got the Bluesky payload generation working in bluesky_en.json. After a messy merge I realized the date key was off by one day, so I fixed it.",
    "date": "2026-11-12"
  }
]
Enter fullscreen mode Exit fullscreen mode

The diff added to the repo (commit 72d61d03) now includes the corrected JSON and the updated metadata.json flag:

@@ -12,8 +12,8 @@
   "pull_requests": 0,
   "releases": 0,
   "closed_issues": 0,
-  "medium_generated": false,
-  "substack_generated": false,
+  "medium_generated": true,
+  "substack_generated": true,
Enter fullscreen mode Exit fullscreen mode

The metadata.json change is unrelated to the bug but reflects that the Medium and Substack outputs were successfully generated that day.

6. Clean up the changelog

The daily changelog file (content/2026/11/12/content-automation/changelog.md) now records the fix:

## [2026-11-12] content-automation

### Fixed
- Date offset bug in Bluesky payload generation (was off by one day).
- Added timezone‑aware unit test.
Enter fullscreen mode Exit fullscreen mode

Key Takeaway

When generating time‑sensitive content in CI, never rely on the raw Date object. Always normalize to the target timezone and lock that logic behind a small utility function with unit tests. It eliminates off‑by‑one day bugs that are hard to spot until a post is already live.


What's Next

I plan to extract the entire payload generation into a reusable library (@vibecoding/content-payload) so other platforms (e.g., Mastodon, LinkedIn) can share the same timezone‑aware date logic. The next PR will also add a GitHub Action that validates the JSON schema before pushing to any external API.


Roberto Luna Osorio – Full Stack Developer & Project Lead

Playa del Carmen, México

vibecoding #buildinpublic #javascript #nodejs #ci #json #timezone #automation #devto


Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.

Repo: zaerohell/content-automation · 2026-11-13

#playadev #buildinpublic

Top comments (0)