Skip to content

Commit

Permalink
implement time ago
Browse files Browse the repository at this point in the history
  • Loading branch information
moerdowo committed Feb 18, 2023
1 parent 7d12209 commit d58be8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@raycast/api": "1.38.1",
"@raycast/utils": "1.0.3",
"axios": "1.3.3",
"javascript-time-ago": "2.5.9",
"moment": "2.29.4"
},
"devDependencies": {
Expand Down
13 changes: 6 additions & 7 deletions src/mayar-balance-recent-transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { MenuBarExtra, getPreferenceValues } from "@raycast/api";
import { Key, useEffect, useState } from "react";
import axios from "axios";
import moment from "moment";
import TimeAgo from 'javascript-time-ago'
import id from 'javascript-time-ago/locale/id'

TimeAgo.addDefaultLocale(id)
const timeAgo = new TimeAgo("id-ID")

interface Data {
statusCode: number;
messages: string;
data: any;
}

function UnixTime( unixTime : number): string {
const formattedDate = moment(unixTime).format("D MMM HH:mm");
return formattedDate;
}

function formatRp(value: number): string {
const formatter = new Intl.NumberFormat("id-ID", {
style: "currency",
Expand Down Expand Up @@ -86,7 +85,7 @@ export default function Command() {
(dataTrx || []).map((trx: { id: Key | null | undefined; createdAt: number; credit: number; customer: { email: string; }; }) =>(
<MenuBarExtra.Item
key={trx.id}
title={UnixTime(trx.createdAt) + " - " + formatRp(trx.credit) + " - " + trx?.customer?.email}
title={timeAgo.format(trx.createdAt) + " - " + formatRp(trx.credit) + " - " + trx?.customer?.email}
onAction={() => {
console.log("transaction clicked");
}}
Expand Down

0 comments on commit d58be8c

Please sign in to comment.