Skip to content

Commit

Permalink
Use Moment for timestamp formatting (#67)
Browse files Browse the repository at this point in the history
I hadn't realized that Moment is officially available as part of the
Obsidian API. Use it instead of our own (blunt) timestamp formatting.
  • Loading branch information
jparise authored Oct 2, 2024
1 parent e029088 commit bb819df
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/notes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TFile, Vault, normalizePath } from "obsidian";
import { TFile, Vault, moment, normalizePath } from "obsidian";
import type InstapaperPlugin from "./main";
import type { InstapaperAccessToken, InstapaperBookmark, InstapaperHighlight } from "./api";

Expand Down Expand Up @@ -110,8 +110,5 @@ function contentForHighlight(highlight: InstapaperHighlight): string {
}

function formatTimestamp(timestamp: number): string {
const date = new Date(timestamp * 1000);
return `${date.getFullYear().toString().padStart(4, '0')}-`
+ `${(date.getMonth() + 1).toString().padStart(2, '0')}-`
+ `${date.getDate().toString().padStart(2, '0')}`;
return moment.unix(timestamp).utc().format("YYYY-MM-DD");
}

0 comments on commit bb819df

Please sign in to comment.