Skip to content

Commit

Permalink
Added util/helpers for helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
abohannon committed Mar 22, 2018
1 parent 7cab116 commit 9d0b734
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/src/components/PollCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { formatDate } from '../util/helpers';
import { Card, Button } from './common';
import { deletePoll } from '../actions';
import { COLOR_GREY_DARK, COLOR_GREY_DARK_50 } from '../constants/style';
Expand Down Expand Up @@ -68,7 +69,7 @@ class PollCard extends Component {
<div>
<h2 style={h2}>{title}</h2>
<p style={votesStyle}>Total votes: {votes}</p>
<p style={dateStyle}>Date created: {date}</p>
<p style={dateStyle}>Date created: {formatDate(new Date(date))}</p>
<p style={dateStyle}>Author: {author}</p>
</div>
<div style={buttonContainerStyle}>
Expand Down
14 changes: 14 additions & 0 deletions client/src/util/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const formatDate = (date) => {
let monthNames = [
'Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct',
'Nov', 'Dec',
];

let day = date.getDate();
let monthIndex = date.getMonth();
let year = date.getFullYear();

return `${day } ${ monthNames[monthIndex] } ${ year}`;
};

0 comments on commit 9d0b734

Please sign in to comment.