Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/components/Job.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import { Link } from "gatsby";

import Badge from "./Badge";
import jobToMarkdown from "../jobToMarkdown.mjs";
import { isJobExpired } from "../utils.mjs";


const Job = ({ job }) => {
const processedJob = React.useMemo(() => jobToMarkdown(job), [job]);

const isExpired = React.useMemo(() => {
if (!processedJob || !processedJob.expires) return false;
const today = new Date();
return new Date(`${processedJob.expires}T23:59:59.999-12:00`) < today;
}, [processedJob]);
return isJobExpired(job);
}, [job]);

if (processedJob === undefined) {
console.log("We don't expect an empty job posting; aborting");
return <div>Empty job posting</div>;
}

return (
<div className="job">
<div className={`job${isExpired ? " expired" : ""}`}>
<div className="badges">
{ processedJob.badges &&
processedJob.badges.map((badge) =>
Expand Down
16 changes: 10 additions & 6 deletions src/filter-jobs.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { isJobExpired } from "./utils.mjs";

const filterJobs = (jobs, filter) => {
// Filter out expired jobs. Use Howland Island timezone to ensure
// that everyone sees the job on its last day.
const today = new Date();

// Filter out expired jobs if requested.
if (!filter.showExpired) {
jobs = jobs.filter((job) => new Date(`${job.expires}T23:59:59.999-12:00`) > today)
jobs = jobs.filter((job) => !isJobExpired(job, today));
}

if (filter.fullTime) {
jobs = jobs.filter((job) => job.percentTime === 100)
jobs = jobs.filter((job) => job.percentTime === 100);
}

if (filter.ossTimeGt) {
jobs = jobs.filter((job) => job.percentOSS >= parseInt(filter.ossTimeGt))
// Ensure we're comparing numbers
const minOSS = parseInt(filter.ossTimeGt, 10);
jobs = jobs.filter((job) => job.percentOSS >= minOSS);
}

if (filter.remote) {
jobs = jobs.filter((job) => (job.location || 'remote').toLowerCase() === 'remote' );
}

return jobs;
}
};

export default filterJobs;
19 changes: 19 additions & 0 deletions src/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Checks if a job has expired using the 'Anywhere on Earth' (-12:00) timezone.
*/
export const isJobExpired = (job, now = new Date()) => {
try {
const expiresStr = String(job.expires).trim();
const expiryDate = new Date(`${expiresStr}T23:59:59.999-12:00`);

// If date is malformed, default to NOT expired to avoid hiding jobs by mistake.
if (isNaN(expiryDate.getTime())) {
return false;
}

return expiryDate < now;
} catch (error) {
// Fail-safe: malformed data shouldn't break the entire jobs board UI.
return false;
}
};