Skip to content

Commit fa02f3c

Browse files
authored
Merge pull request #454 from honyanya/fix/date-extract
2 parents daa32b4 + dd32366 commit fa02f3c

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

src/components/kusa/contributions/by-repo/comments.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
IssueClosedIcon,
1717
IssueOpenedIcon,
1818
} from '@primer/octicons-react';
19-
import { iso8601DateExtract } from '@lib/iso8601-date-extract';
19+
import { iso8601DateTimeExtract } from '@lib/iso8601-date-time-extract';
2020

2121
const withIssue = (
2222
value:
@@ -103,7 +103,7 @@ const Comments = ({ comments }: { comments: Summary['comments'] }) => {
103103
<li key={htmlUrl} className="flwx-wrap flex odd:bg-gray-100">
104104
<span className="ml-3">
105105
<CommentIcon size={20} />
106-
{iso8601DateExtract(updatedAt)}
106+
{iso8601DateTimeExtract(updatedAt)}
107107
<a target="_blank" rel="noreferrer" href={htmlUrl} className="text-blue-600 hover:underline">
108108
{withIssue(c) && c.issue && c.issue.state === 'open' ? (
109109
<span className="text-green-800">

src/components/kusa/contributions/by-repo/commits.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { CommitIcon, InfoIcon } from '@primer/octicons-react';
33
import { Summary } from '../types';
44
import { toHtmlUrl } from '@lib/to-html-url';
5-
import { iso8601DateExtract } from '@lib/iso8601-date-extract';
5+
import { iso8601DateTimeExtract } from '@lib/iso8601-date-time-extract';
66

77
const Commits = ({ commits }: { commits: Summary['commits'] }) => {
88
const count = Object.values(commits).reduce((acc, c) => acc + c.data.length, 0);
@@ -38,7 +38,7 @@ const Commits = ({ commits }: { commits: Summary['commits'] }) => {
3838
<li key={commit.sha} className="flex flex-wrap odd:bg-gray-100">
3939
<span className="basis-full sm:basis-1/6">
4040
<CommitIcon size={20} />
41-
{iso8601DateExtract(commit.date)}{' '}
41+
{iso8601DateTimeExtract(commit.date)}{' '}
4242
<a
4343
target="_blank"
4444
rel="noreferrer"

src/components/kusa/contributions/by-repo/pullrequests.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Summary } from '../types';
33
import { toHtmlUrl } from '@lib/to-html-url';
44
import { GitMergeIcon, GitPullRequestClosedIcon, GitPullRequestIcon, InfoIcon } from '@primer/octicons-react';
5-
import { iso8601DateExtract } from '@lib/iso8601-date-extract';
5+
import { iso8601DateTimeExtract } from '@lib/iso8601-date-time-extract';
66

77
const PullRequests = ({ pullRequests }: { pullRequests: Summary['pullRequests'] }) => {
88
const totalCount = Object.values(pullRequests).reduce((acc, prs) => acc + prs.data.length, 0);
@@ -70,7 +70,7 @@ const PullRequests = ({ pullRequests }: { pullRequests: Summary['pullRequests']
7070
<GitPullRequestIcon size={20} />
7171
</span>
7272
)}
73-
{iso8601DateExtract(pr.pull_request.updated_at)}
73+
{iso8601DateTimeExtract(pr.pull_request.updated_at)}
7474
<a
7575
target="_blank"
7676
rel="noreferrer"

src/components/kusa/contributions/contributions-simple.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
WatchEventPayload,
1515
} from './types';
1616
import { toHtmlUrl } from '@lib/to-html-url';
17-
import { iso8601DateExtract } from '@lib/iso8601-date-extract';
17+
import { iso8601DateTimeExtract } from '@lib/iso8601-date-time-extract';
1818

1919
type Props = {
2020
result: any;
@@ -155,7 +155,7 @@ const CommitCommentEvent = ({ payload }: { payload: CommitCommentEventPayload })
155155
<a className="text-blue-600 hover:underline" target="_blank" rel="noreferrer" href={payload.comment.html_url}>
156156
{payload.comment.commit_id?.substring(0, 6)}
157157
</a>{' '}
158-
at {payload.comment.updated_at.split('T')[1].replace('Z', '')}
158+
at {iso8601DateTimeExtract(payload.comment.updated_at, 1)}
159159
</div>
160160
);
161161
};
@@ -180,7 +180,7 @@ const ContributionsSimple = (props: Props) => {
180180
{props.result.map((row: GitHubEvent) => {
181181
return (
182182
<div key={row.id} className="flex flex-wrap text-sm odd:bg-gray-100">
183-
<div className="basis-1/4 sm:basis-1/12">{iso8601DateExtract(row.created_at)}</div>
183+
<div className="basis-1/4 sm:basis-1/12">{iso8601DateTimeExtract(row.created_at)}</div>
184184
<div className="basis-3/4 text-blue-600 hover:underline sm:basis-4/12">
185185
{row.repo.url ? (
186186
<a href={toHtmlUrl(row.repo.url)} target="_blank" rel="noreferrer">
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { iso8601DateExtract } from '../iso8601-date-extract';
1+
import { iso8601DateTimeExtract } from '../iso8601-date-time-extract';
22

33
describe('iso8601DateExtract', () => {
4+
const dateTime = "2022-09-22T11:26:19Z";
45
test('extraction date only', () => {
5-
expect(iso8601DateExtract("2022-09-22T11:26:19Z")).toBe("2022-09-22")
6+
expect(iso8601DateTimeExtract(dateTime)).toBe("2022-09-22")
7+
});
8+
test('extraction time only', () => {
9+
expect(iso8601DateTimeExtract(dateTime, 1)).toBe("11:26:19")
610
});
711
});

src/lib/iso8601-date-extract.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const iso8601DateTimeExtract = (datetime: string, index: number = 0) => {
2+
return index ? datetime.split('T')[index].replace('Z', '') : datetime.split('T')[index];
3+
};

0 commit comments

Comments
 (0)