Skip to content

fix(payments): parse ISO 8601 time/expiry returned by LNbits >= 1.0 - #943

Merged
cameri merged 1 commit into
mainfrom
fix/lnbits-iso-dates
Oct 23, 2026
Merged

cameri merged 1 commit into
mainfrom
fix/lnbits-iso-dates

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

Cherry-picks Perlover's commit 5ffad56 from their fork (Perlover/nostream, branch fix/lnbits-iso-dates) onto current main. The contributor could not open the PR themselves — GitHub refused CreatePullRequest for their account — so this PR carries their work with authorship intact: the commit keeps Author: Perlover <perlover@perlover.com>, and the change is unmodified.

Closes #927

The bug

LNbits 1.x returns details.time and details.expiry as ISO 8601 strings; LNbits 0.x returned unix seconds. LNbitsPaymentsProcessor multiplied by 1000 unconditionally, so new Date(value * 1000) yielded Invalid Date against a 1.x server. Two consequences, both in the issue's reproduction:

  • confirmInvoice called confirmedAt.toISOString() → RangeError: Invalid time value, so a paid admission was never confirmed.
  • isExpiredInvoice() was false for an invalid expiresAt, so unpaid invoices were re-saved as pending on every maintenance pass and never retired.

The fix

A toDate helper accepting either shape, used for time/expiry in both getInvoice and createInvoice:

const toDate = (value: number | string): Date => (typeof value === 'number' ? new Date(value * 1000) : new Date(value))

This keeps LNbits 0.x working — the number branch is the old behaviour, unchanged.

Verification on this branch

Run in a clean worktree at e417437 (current main) with bun install:

Check Result
mocha test/unit/payments-processors/lnbits-payment-processor.spec.ts 5 passing
Same file with the source reverted to HEAD~1 2 failing — expected 'pending' to equal 'expired' and RangeError: Invalid time value
biome lint on both changed files clean
biome format clean
tsc --noEmit no errors in the changed file

The failing run reproduces both failures the issue describes, on the same two tests the commit adds, so the tests are shown to catch the bug rather than merely accompany the fix.

Credit

Original author: Perlover (https://github.com/Perlover) — commit 5ffad56, reported and diagnosed in #927. Thanks for the unit-level reproduction, which made this quick to confirm.

LNbits 1.x returns details.time and details.expiry as ISO 8601 strings
("2025-10-11T15:24:27+00:00") instead of unix seconds, so
`new Date(value * 1000)` produced Invalid Date. Paid admissions were
never confirmed (confirmInvoice throws RangeError on
confirmedAt.toISOString()) and expired invoices stayed pending forever.
Accept both unix seconds (LNbits < 1.0) and ISO strings.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116ucVjyUPmPdBqnQsWxEws
@changeset-bot

changeset-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c7de11d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds support for LNbits ISO 8601 dates while keeping Unix-second dates working.

  • LNbits invoice dates work with both old and new date formats.

Reviews (1) · Last reviewed commit: "fix(payments): parse ISO 8601 time/expir..." · Reviewed by Greptile

@cameri
cameri merged commit 17157d5 into main Oct 23, 2026
17 checks passed
@cameri
cameri deleted the fix/lnbits-iso-dates branch October 23, 2026 20:15
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 40017127422

Coverage increased (+0.004%) to 75.458%

Details

  • Coverage increased (+0.004%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (4 of 6 lines covered, 66.67%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
src/payments-processors/lnbits-payment-processor.ts 6 4 66.67%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/payments-processors/lnbits-payment-processor.ts 1 57.89%

Coverage Stats

Coverage Status
Relevant Lines: 11286
Covered Lines: 8906
Line Coverage: 78.91%
Relevant Branches: 5848
Covered Branches: 4023
Branch Coverage: 68.79%
Branches in Coverage %: Yes
Coverage Strength: 801.8 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LNbits >= 1.0: ISO 8601 time/expiry parsed as unix seconds, paid admissions never confirmed

4 participants