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

Commit

Permalink
Merge pull request #2 from etcdigital/v1.1
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
etc-tiago authored May 11, 2020
2 parents 48864a7 + d04fba6 commit 177bdb2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/changelog.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ jobs:

- name: Build
run: yarn build

changelog:
needs: [test]
name: Chanegelog Generator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: etcdigital/pull-request-changelog@1.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "time2input",
"description": "A helper to manage 2 time inputs with increment/decrement",
"version": "1.0.0",
"version": "1.1.0",
"author": "Tiago Souza",
"license": "MIT",
"scripts": {
Expand All @@ -24,9 +24,7 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"date-fns": "^2.13.0"
},
"dependencies": {},
"devDependencies": {
"@netflix/tslint-config": "^1.0.1",
"@types/jest": "^25.1.3",
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { addMinutes, subMinutes } from 'date-fns';

const addSecondDigit = (digit: number): string => (digit < 10 ? `0${digit}` : digit.toString());

const setMinutes = (date: Date, minutes) => {
const base = new Date(date.valueOf());
base.setMinutes(base.getMinutes() + minutes);
return base;
};

export const getTimeString = (date: Date): string => `${addSecondDigit(date.getHours())}:${addSecondDigit(date.getMinutes())}`;

export const inputPattern = '([0-1]{1}[0-9]{1}|20|21|22|23):[0-5]{1}[0-9]{1}';
Expand All @@ -15,9 +19,9 @@ export type ITimeChangeAction = 'up' | 'down';
*/
const timeChange = (date: Date, method: ITimeChangeAction, minutes: number): Date => {
if (method === 'up') {
return addMinutes(date, minutes);
return setMinutes(date, minutes);
}
return subMinutes(date, minutes);
return setMinutes(date, -minutes);
};

/* Turn time string to date */
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,6 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"

date-fns@^2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.13.0.tgz#d7b8a0a2d392e8d88a8024d0a46b980bbfdbd708"
integrity sha512-xm0c61mevGF7f0XpCGtDTGpzEFC/1fpLXHbmFpxZZQJuvByIK2ozm6cSYuU+nxFYOPh2EuCfzUwlTEFwKG+h5w==

debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down

0 comments on commit 177bdb2

Please sign in to comment.