Skip to content

Commit

Permalink
Switch to GitHub for CI; fix formatting and parsing (#265)
Browse files Browse the repository at this point in the history
* Switch to GitHub CI

* Fix formatting and parsing

* Remove travis
  • Loading branch information
sloria authored May 3, 2020
1 parent 66faadf commit 0e9d0a8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# jrnl-parse

[![Current Version](https://badgen.net/npm/v/jrnl-parse)](https://www.npmjs.org/package/jrnl-parse)
[![Build Status](https://travis-ci.org/sloria/jrnl-parse.svg?branch=master)](https://travis-ci.org/sloria/jrnl-parse)
![CI](https://github.com/sloria/jrnl-parse/workflows/CI/badge.svg)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=sloria/jrnl-parse)](https://dependabot.com)

Parses [jrnl](http://jrnl.sh) files in Node.js or the browser.
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const formatDate = require("date-fns/format");
const parseDate = require("date-fns/parse");
const isValidDate = require("date-fns/is_valid");
const isValidDate = require("date-fns/isValid");

const defaultConfig = {
// jrnl's default timeformat (%Y-%m-%d %H:%M)
timeformat: "YYYY-MM-DD HH:mm",
timeformat: "yyyy-MM-dd HH:mm",
tagsymbols: "@"
};

Expand All @@ -13,10 +13,12 @@ const parseTags = (input, tagsymbols) => {
return (input.match(pattern) || []).map(x => x.slice(1));
};

const referenceDate = new Date(1970, 0, 1);

const parse = (input, config) => {
const entries = [];
const conf = Object.assign({}, defaultConfig, config);
const dateLength = formatDate(new Date(), conf.timeformat).length;
const dateLength = formatDate(referenceDate, conf.timeformat).length;
let currentEntry = null;
input
.replace(/\n+$/, "")
Expand All @@ -26,7 +28,7 @@ const parse = (input, config) => {
const dateMatch = /^\[(.+)\]/.exec(line);
const dateString = dateMatch ? dateMatch[1] : null;
// try to parse line as date => new entry begins
const newDate = parseDate(dateString, conf.timeformat);
const newDate = parseDate(dateString, conf.timeformat, referenceDate);
if (dateMatch && isValidDate(newDate)) {
// parsing successful => save old entry and create new one
if (currentEntry) {
Expand Down

0 comments on commit 0e9d0a8

Please sign in to comment.