Skip to content

Commit 47d9a53

Browse files
committed
Enable formatting of time
1 parent d9de858 commit 47d9a53

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ A react component to display event in a vertical timeline format. This is based
66

77
![alt tag](https://github.com/arunghosh/react-time-line/raw/master/docs/timeline.png)
88

9-
**Installation**
9+
## Installation
1010
```
1111
npm install react-time-line
1212
```
1313

1414

15-
**Usage**
15+
## Usage
1616

1717
```javascript
1818
const events = [
@@ -24,17 +24,19 @@ const events = [
2424
{ts: "2017-09-16T12:20:46.587Z", text: 'Clicked Checkout'},
2525
];
2626

27-
<Timeline items={events} />
27+
// default format is "hh:mm"
28+
<Timeline items={events} format="hh:mm a" />
2829
```
29-
The events should be ordered in a way you need.
30+
The events should be ordered in a way you need.
3031

32+
**For time formatting options [check momentjs format docs](https://momentjs.com/docs/#/displaying/format/).**
3133

32-
**Style**
34+
## Style
3335

3436
Currently there is no proper way to set the style. As a hack you can override the default style. Check for the default style in `src/style.scss`.
3537

3638

37-
### For developers
39+
## For developers
3840

3941
To make new build
4042
```

dist/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import Timeline from '../src';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import Timeline from "../src";
44

55
const events = [
6-
{ts: "2017-09-17T12:22:46.587Z", text: 'Logged in'},
7-
{ts: "2017-09-17T12:21:46.587Z", text: 'Clicked Home Page'},
8-
{ts: "2017-09-17T12:20:46.587Z", text: 'Edited Profile'},
9-
{ts: "2017-09-16T12:22:46.587Z", text: 'Registred'},
10-
{ts: "2017-09-16T12:21:46.587Z", text: 'Clicked Cart'},
11-
{ts: "2017-09-16T12:20:46.587Z", text: 'Clicked Checkout'},
6+
{ ts: "2017-09-17T12:22:46.587Z", text: "Logged in" },
7+
{ ts: "2017-09-17T12:21:46.587Z", text: "Clicked Home Page" },
8+
{ ts: "2017-09-17T12:20:46.587Z", text: "Edited Profile" },
9+
{ ts: "2017-09-16T12:22:46.587Z", text: "Registred" },
10+
{ ts: "2017-09-16T12:21:46.587Z", text: "Clicked Cart" },
11+
{ ts: "2017-09-16T12:20:46.587Z", text: "Clicked Checkout" }
1212
];
1313

14-
ReactDOM.render(<Timeline items={events} />, document.getElementById('app'));
14+
ReactDOM.render(
15+
<Timeline items={events} format="hh:mm a" />,
16+
document.getElementById("app")
17+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-time-line",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "React component for displaying timeline",
55
"main": "dist/bundle.js",
66
"scripts": {

src/Timeline.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import TimlineItem from "./TimlineItem";
1010
* @param {Array} items Array of events in the form of ts and text
1111
* @returns {Object} return object with key as date and values array in events for that date
1212
*/
13-
function getFormattedData(items) {
13+
function getFormattedData(items, format="hh:mm") {
1414
const activities = {};
1515
items.forEach(({ ts, text }, index) => {
1616
const date = moment(ts);
1717
const dateStr = date.format("DD MMM YYYY");
1818
const list = activities[dateStr] || [];
1919
list.push({
20-
time: date.format("hh:mm"),
20+
time: date.format(format),
2121
text,
2222
key: index,
2323
});
@@ -26,8 +26,8 @@ function getFormattedData(items) {
2626
return activities;
2727
}
2828

29-
function Timeline({ items }) {
30-
const activities = getFormattedData(items);
29+
function Timeline({ items, format }) {
30+
const activities = getFormattedData(items, format);
3131
const dates = Object.keys(activities);
3232
return (
3333
<div className="time-line-ctnr">
@@ -52,6 +52,7 @@ Timeline.propTypes = {
5252
text: PropTypes.string.isRequired,
5353
})
5454
).isRequired,
55+
format: PropTypes.string,
5556
};
5657

5758
export default Timeline;

0 commit comments

Comments
 (0)