Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release note timezone fix #9318

Merged
merged 6 commits into from
Nov 21, 2024
Merged
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
27 changes: 11 additions & 16 deletions src/components/PublishedDate/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import React from "react"
import React from 'react';

import "./style.css"
import './style.css';

const PublishedDate = ({ dateString, className }) => {
// Todo, more type checking.
if (!dateString) {
return null
return null;
}

// Turn ReleaseNoteData.frontmatter.published_date into a date object.
// And then format it as Month Day, Year.
// https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date
const date = new Date(dateString)
const options = { year: "numeric", month: "long", day: "numeric" }
const formattedDate = date.toLocaleDateString(undefined, options)
const [year, month, day] = dateString.split('-'); // Extract year, month, and day
const formattedDate = `${new Date(year, month - 1).toLocaleString('default', { month: 'long' })} ${parseInt(day)}, ${year}`;

return (
<div
className={["docs-published-date", className]
.join(" ")
className={['docs-published-date', className]
.join(' ')
.trim()
.replace(/\s+/g, " ")}
.replace(/\s+/g, ' ')}
>
{formattedDate}
</div>
)
}
);
};

export default PublishedDate
export default PublishedDate;
Loading