Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change date format to work in US #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"jest": "^20.0.4"
"jest": "^20.0.4",
"jest-cli": "^20.0.4"
},
"homepage": "https://github.com/lucasbento/reminders-cli#readme",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions src/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getReminders = () => applescript.execFile(getRemindersPath);
export const getReminderDate = async ({ name }) => {
const date = await applescript.execFile(getReminderPath, [name]);

return moment(date, 'dddd, D MMMM YYYY H:mm:ss').format('DD/MM/YYYY-HH:mm').split('-');
return moment(date, 'dddd, D MMMM YYYY H:mm:ss').format('L-hh:mma').split('-');
};

const showReminderList = async () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const updateReminder = async (reminderName, { name, date, time }) => {
spinner.start();
spinner.text = 'Updating reminder';

const datetime = moment(`${date} ${time}`, 'DD/MM/YYYY HH:mm').format('YYYY-MM-DD HH:mm');
const datetime = moment(`${date} ${time}`, 'L hh:mma').format('YYYY-MM-DD hh:mma');
const args = [
reminderName,
name,
Expand Down
33 changes: 19 additions & 14 deletions src/utils/__tests__/date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,43 @@ it('should parse phrases correctly', () => {
const phrases = [{
phrase: 'remind me to feed the cats tomorrow at 6 am',
parsedPhrase: 'feed the cats',
date: moment().add(1, 'day').format('DD/MM/YYYY'),
time: '06:00',
date: moment().add(1, 'day').format('L'),
time: '06:00am',
}, {
phrase: 'remind me in two hours to take a break',
parsedPhrase: 'take a break',
date: moment().format('DD/MM/YYYY'),
time: moment().add(2, 'hours').format('HH:mm'),
date: moment().format('L'),
time: moment().add(2, 'hours').format('hh:mma'),
}, {
phrase: 'remind me to do some deep breathing in 10 minutes',
parsedPhrase: 'do some deep breathing',
date: moment().format('DD/MM/YYYY'),
time: moment().add(10, 'minutes').format('HH:mm'),
date: moment().format('L'),
time: moment().add(10, 'minutes').format('hh:mma'),
}, {
phrase: 'remind me at 3pm to wash the dishes',
parsedPhrase: 'wash the dishes',
date: moment().format('DD/MM/YYYY'),
time: '15:00',
date: moment().format('L'),
time: '03:00pm',
}, {
phrase: 'remind me to wash the dishes at 4:00 pm tomorrow',
parsedPhrase: 'wash the dishes',
date: moment().add(1, 'day').format('DD/MM/YYYY'),
time: '16:00',
date: moment().add(1, 'day').format('L'),
time: '04:00pm',
}, {
phrase: 'remind me on friday at 9pm to go party',
parsedPhrase: 'go party',
date: moment().startOf('week').add(5, 'days').format('DD/MM/YYYY'),
time: '21:00',
date: moment().startOf('week').add(5, 'days').format('L'),
time: '09:00pm',
}, {
phrase: 'remind me to feed the doggies tomorrow at 12',
parsedPhrase: 'feed the doggies',
date: moment().add(1, 'day').format('DD/MM/YYYY'),
time: '12:00',
date: moment().add(1, 'day').format('L'),
time: '12:00pm',
}, {
phrase: 'remind me tomorrow to call bob',
parsedPhrase: 'call bob',
date: moment().add(1, 'day').format('L'),
time: '09:00am',
}];

phrases.forEach(({ phrase, parsedPhrase, date, time }) => {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export const parsePhrase = (phrase) => {
return null;
}

// Change default time to 09:00 instead of 12:00
if (parsedPhrase.start.impliedValues.hour === 12) {
parsedPhrase.start.impliedValues.hour = 9;
}

const eventName = phrase.replace(parsedPhrase.text, '');

const startDate = parsedPhrase.start && moment(parsedPhrase.start.date()).format('DD/MM/YYYY-HH:mm').split('-');
const endDate = parsedPhrase.end && moment(parsedPhrase.end.date()).format('DD/MM/YYYY-HH:mm').split('-');
const startDate = parsedPhrase.start && moment(parsedPhrase.start.date()).format('L-hh:mma').split('-');
const endDate = parsedPhrase.end && moment(parsedPhrase.end.date()).format('L-hh:mma').split('-');

return {
name: clearPhrase(eventName),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dateRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DateRange {
}
}

return date.format('DD/MM/YYYY');
return date.format('L');
};

today = () => this.parseDate();
Expand Down
Loading