Skip to content

Commit

Permalink
Merge pull request #389 from KTH/fix/KUI-1396-fix-date-and-version-bu…
Browse files Browse the repository at this point in the history
…gs-in-preview

fix/KUI-1396: fix date and version bugs in preview
  • Loading branch information
allazis authored Sep 20, 2024
2 parents b9808cd + 223650a commit c901404
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion public/js/app/components/preview/CourseFacts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const startDate = (labels, memoData) =>
memoData.roundsStartDate ? (
<>
<h3>{labels.startdate}</h3>
<p>{getDateFormat(memoData.roundsStartDate[0])}</p>
<p>{getDateFormat(memoData.roundsStartDate[0], memoData.languageOfInstructions)}</p>
</>
) : (
<>
Expand Down
22 changes: 10 additions & 12 deletions public/js/app/components/preview/CourseMemoLinks.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import React from 'react'
import PropTypes from 'prop-types'

import { getDateFormat } from '../../util/helpers'
import Popup from './Popup'

const formatVersion = (language = 'sv', version) => {
const unixTime = Date.parse(version)
const formatVersionDateAndTime = (language = 'sv', lastChangedDateTime) => {
const unixTime = Date.parse(lastChangedDateTime)
if (unixTime) {
if (language === 'sv') {
return new Date(unixTime).toLocaleString('sv-SE')
} else {
const options = { day: 'numeric', month: 'short', year: 'numeric' }
return new Date(unixTime).toLocaleDateString('en-GB', options)
}
const date = new Date(unixTime)
const time = date.toLocaleTimeString()
return `${getDateFormat(date, language)} ${time}`
}
return null
}

const version = (language, labels, memoVersion) =>
memoVersion ? (
const version = (language, labels, lastChangedDateTime, memoData) =>
lastChangedDateTime ? (
<>
<h3>{labels.versionTitle}</h3>
<p>{`${labels.latest} ${formatVersion(language, memoVersion)}`}</p>
<p>{`Ver ${memoData.version} - ${formatVersionDateAndTime(language, lastChangedDateTime)}`}</p>
</>
) : (
<>
Expand All @@ -41,7 +39,7 @@ const pdfLink = labels => (

const CourseMemoLinks = ({ language, labels, memoData = {} }) => (
<div className="info-box">
{version(language, labels, memoData.lastChangeDate)}
{version(language, labels, memoData.lastChangeDate, memoData)}
{pdfLink(labels)}
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions public/js/app/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const combinedCourseName = (courseCode, course, langAbbr) => {
}

export const getDateFormat = (date, language) => {
const timestamp = Date.parse(date)
const parsedDate = new Date(timestamp)
if (language === 1 || language === 'Svenska' || language === 'Swedish' || language === 'sv') {
return date
return parsedDate.toLocaleDateString('sv')
}
const options = { day: 'numeric', month: 'short', year: 'numeric' }
const timestamp = Date.parse(date)
const parsedDate = new Date(timestamp)
return parsedDate.toLocaleDateString('en-GB', options)
}

Expand Down

0 comments on commit c901404

Please sign in to comment.