Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from pskt/feature/file-name
Browse files Browse the repository at this point in the history
Use date and activity name in filename
  • Loading branch information
mipapo authored Aug 17, 2019
2 parents 86a66ba + 302e899 commit 6cc26a5
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ const template = (data, name) => {
`.trim();
};

const fileName = (data, name) => {
const createdDate = new Date(data.created_at);
const month = createdDate.getMonth() + 1;
const day = createdDate.getDate();

function pad(n){return n<10 ? '0'+n : n}
const datePart = [
createdDate.getFullYear(),
pad(month),
pad(day)
].join('');

const timePart = [
pad(createdDate.getHours()),
pad(createdDate.getMinutes()),
].join('');

return [datePart, timePart, name].join('_');
};

let amountExportedFiles = 0;

const start = async ([exportPath, outputPath = `${process.cwd()}/export`]) => {
Expand Down Expand Up @@ -283,7 +303,7 @@ const start = async ([exportPath, outputPath = `${process.cwd()}/export`]) => {

return util
.promisify(fs.writeFile)(
`${segmentPath}/${session.id}.gpx`,
`${segmentPath}/${fileName(session, name)}.gpx`,
template(session, name),
)
.catch(console.error);
Expand Down

0 comments on commit 6cc26a5

Please sign in to comment.