Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const doClockOut = async (context) => {
if (userId) {
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName));
}
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut();
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight();
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
}
})
Expand All @@ -62,8 +62,8 @@ const findUserData = (users, id) => {
return user ? { userName: user.displayName.split(" ")[0], userEmail: _.first(user.otherMails) } : {};
};

const findSlackUserId = (users, email) => {
const user = users.find((user) => user.email === email);
const findSlackUserId = (slackUsers, email) => {
const user = slackUsers.find((slackUser) => slackUser.email === email);
return user ? user.id : null;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const constants = {
CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:',
CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :cara_con_monóculo: \nBTW, we just did a clock-out for you; If you want to continue working, please do a new clock-in the Time Tracker app https://timetracker.ioet.com/'
CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit :ioet: <https://timetracker.ioet.com|Time Tracker App> to set the right end time for your entries, we just did a clock out for you :wink:',
CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :face_with_monocle: \nBTW, we just did a clock-out for you. If you want to continue working, please use :ioet: <https://timetracker.ioet.com|Time Tracker App> to clock back in.'
};

module.exports = constants;
16 changes: 10 additions & 6 deletions nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class TimeEntry {

getMidnightInTimeEntryZone(){
return moment(this.timeEntry.start_date).utc()
.subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day')
.subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day');
}

getTimeToClockOutMidnight(){
return moment().utc().endOf('day').toISOString();
}

getCurrentTimeInTimeEntryZone(){
return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes')
return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes');
}

needsToBeClockedOut() {
const currentTimeInUTC = moment().utc()
const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes()
const currentTimeInUTC = moment().utc();
const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes();
return minutesRunning > 720;
}

needsToBeClockedOutMidnight(){
return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone())
return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone());
}
}

module.exports = TimeEntry
module.exports = TimeEntry;