Skip to content

Commit

Permalink
add show time function in all page of job
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam3245 committed Aug 25, 2024
1 parent 206233d commit 1246662
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/components/all-jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PaginationPages } from './ui/paginator';
import Icon from './ui/icon';
import { formatSalary } from '@/lib/utils';
import Link from 'next/link';
import daysAgo from '@/lib/show-time';
type PaginatorProps = {
searchParams: JobQuerySchemaType;
};
Expand Down Expand Up @@ -47,6 +48,9 @@ const AllJobs = async ({ searchParams }: PaginatorProps) => {
? `${formatSalary(job.minSalary)}-${formatSalary(job.maxSalary)}`
: 'Not disclosed'}
</span>
<span className="flex items-center gap-0.5">
{daysAgo(job.postedAt)}
</span>
</div>
<p className="flex gap-0.5 items-center text-muted-foreground text-xs">
<Icon icon="description" size={12} />
Expand Down
9 changes: 2 additions & 7 deletions src/components/job-landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Link from 'next/link';
import Icon from './ui/icon';
import { JobType } from '@/types/jobs.types';
import { DEFAULT_PAGE } from '@/config/app.config';
import daysAgo from '@/lib/show-time';

export const JobLanding = async () => {
const jobs = await getAllJobs({
Expand All @@ -26,13 +27,7 @@ export const JobLanding = async () => {
};

const JobCard = ({ job }: { job: JobType }) => {
const daysAgo = (jobDate:Date)=>{
const postDate = new Date(jobDate);
const now = new Date();
const differenceInMilles = now.getTime() - postDate.getTime();
const differenceInDays = Math.floor(differenceInMilles / (1000 * 60 * 60 * 24))
return differenceInDays === 0 ? 'Today': `${differenceInDays} day${differenceInDays > 1 ? 's' : ''} ago`;
}

return (
<Link href={`/jobs/${job.id}`}>
<div className="flex flex-col items-start gap-4 rounded-lg border p-3 text-left text-sm transition-all hover:bg-accent bg-background">
Expand Down
4 changes: 4 additions & 0 deletions src/components/job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { JobType } from '@/types/jobs.types';
import Icon from './ui/icon';
import { formatSalary } from '@/lib/utils';
import { Button } from './ui/button';
import daysAgo from '@/lib/show-time';

export const Job = ({ job }: { job: JobType }) => {
return (
Expand All @@ -20,6 +21,9 @@ export const Job = ({ job }: { job: JobType }) => {
? `${formatSalary(job.minSalary)}-${formatSalary(job.maxSalary)}`
: 'Not disclosed'}
</span>
<span className="flex items-center gap-0.5">
{daysAgo(job.postedAt)}
</span>
</div>
</div>
<Button className="justify-self-start">Apply</Button>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/show-time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const daysAgo = (jobDate:Date)=>{
const postDate = new Date(jobDate);
const now = new Date();
const differenceInMilles = now.getTime() - postDate.getTime();
const differenceInDays = Math.floor(differenceInMilles / (1000 * 60 * 60 * 24))
return differenceInDays === 0 ? 'Today': `${differenceInDays} day${differenceInDays > 1 ? 's' : ''} ago`;
}
export default daysAgo;

0 comments on commit 1246662

Please sign in to comment.