Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 2cd4a94a authored by Fadhil Pradipta Widyanto's avatar Fadhil Pradipta Widyanto
Browse files

Merge branch 'fadhil' into 'master'

Fadhil

See merge request !63
parents da188340 cf280f17
No related branches found
No related tags found
1 merge request!63Fadhil
import './ThreadList.css';
import { tConvert, translate } from './helpers/time-util'
export default function ThreadList(props){
const time = translate(props.time)
return (
<div id="threadCard">
<div id="threadCardHeader">
......@@ -8,7 +11,7 @@ export default function ThreadList(props){
</div>
<div id="threadCardContent">
<p id="topic">{props.topic}</p>
<p id="creator">By {props.user} - {props.time} - {props.points} </p>
<p id="creator">By {props.user} - {time} - {props.points} </p>
</div>
</div>
)
......
......@@ -5,6 +5,7 @@ import AuthService from '../services/auth.service'
import authHeader from '../services/auth-header'
import React, { useState, useEffect} from 'react'
import { loggedIn } from '../services/loggedInService'
import { translate } from '../helpers/time-util';
const LINK = 'http://localhost:4000/api';
export default function Post(props){
......@@ -50,12 +51,14 @@ export default function Post(props){
}
}
const time = translate(props.time)
return (
<div id="post">
<div id="postHeader">
<div id="headerData">
<div id="round"></div>
<p id="creator">By {props.user} - {props.time} </p>
<p id="creator">By {props.user} - {time} </p>
</div>
{ AuthService.getCurrentUserId() === props.user_id && (
......
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"];
function tConvert (time) {
// Check correct time format and split into components
time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) { // If time format correct
console.log(time)
time = time.slice (1, 4); // Remove full string match value
time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours
}
return time.join (''); // return adjusted time or original string
}
function translate(time) {
const timeSplit = time.split('T')
const date = new Date(timeSplit[0])
const fullDate = `${date.getDay()} ${monthNames[date.getMonth()]} ${date.getFullYear()}`
return `${fullDate}, ${tConvert(timeSplit[1])}`
}
export {tConvert, translate}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment