Skip to content

Instantly share code, notes, and snippets.

@mikehibm
Last active August 9, 2018 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikehibm/cf26fd6d846051561380a9c4f467e9cc to your computer and use it in GitHub Desktop.
Save mikehibm/cf26fd6d846051561380a9c4f467e9cc to your computer and use it in GitHub Desktop.
import * as moment from 'moment';
export interface WorkItem {
user: string;
client: string;
project: string;
description: string;
startDate: Date;
endDate: Date;
duration: number;
}
export function mapArrayToWorkItem(data: string[][]): WorkItem[] {
return data
.map((row) => {
const startDate = moment(`${row[4]} ${row[5]}`, 'YYYY-MM-DD HH:mm:ss');
const endDate = moment(`${row[6]} ${row[7]}`, 'YYYY-MM-DD HH:mm:ss');
const duration = moment.duration(endDate.diff(startDate));
return {
user: row[0],
client: row[1],
project: row[2],
description: row[3],
startDate: startDate.toDate(),
endDate: endDate.toDate(),
duration: duration.asHours()
};
})
.filter((i) => i.client !== 'Client' && i.client); // 先頭と末尾の行を除外。
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment