commit 3ff38b96dd2d8c93a407f2bfb9c1f36904b51b11 Author: KeeganForelight Date: Fri Jan 13 13:42:13 2023 -0500 moved from dotfiles diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/timesheets/.session b/timesheets/.session new file mode 100644 index 0000000..9fe0a87 --- /dev/null +++ b/timesheets/.session @@ -0,0 +1,2 @@ +DATE=1673627871 +TIME_IN=1673627871 diff --git a/timesheets/Jan-13-23.csv b/timesheets/Jan-13-23.csv new file mode 100644 index 0000000..817837e --- /dev/null +++ b/timesheets/Jan-13-23.csv @@ -0,0 +1,13 @@ +Date, Time In, Time Out, Total Time (HH:MM) +Fri Jan-06, 02:30pm, 05:10pm, 02:40 +Mon Jan-09, 01:35pm, 08:59pm, 07:24 +Mon Jan-09, 08:59pm, 08:59pm, 00:00 +Tue Jan-10, 10:36am, 08:17pm, 09:41 +Tue Jan-10, 08:17pm, 08:20pm, 00:02 +Wed Jan-11, 11:30am, 08:39pm, 09:09 +Thu Jan-12, 10:35am, 10:57am, 00:21 +Thu Jan-12, 10:57am, 11:08am, 00:11 +Thu Jan-12, 11:09am, 11:27am, 00:18 +Thu Jan-12, 11:27am, 11:50am, 00:22 +Thu Jan-12, 11:51am, 07:47pm, 07:56 +Thu Jan-12, 07:47pm, 07:47pm, 00:00 diff --git a/timesheets/archive/timesheet.log b/timesheets/archive/timesheet.log new file mode 100644 index 0000000..7ee7dfd --- /dev/null +++ b/timesheets/archive/timesheet.log @@ -0,0 +1,105 @@ +I 10-03T16:24 +O 10-03T16:25 +I 10-03T16:25 +O 10-03T16:27 +I 10-03T16:27 +O 10-03T16:30 +I 10-03T16:31 +O 10-03T16:31 +I 10-05T09:52 +O 10-05T10:06 +I 10-05T10:06 +O 10-05T10:06 +I 10-05T10:15 +O 10-05T12:53 +I 10-05T17:18 +O 10-05T18:48 +I 10-06T13:21 +O 10-06T13:40 +I 10-07T11:37 +O 10-07T12:59 +I 10-07T16:13 +O 10-07T16:38 +I 10-07T17:06 +O 10-07T20:20 +I 10-08T14:22 +O 10-08T18:50 +I 10-09T14:35 +O 10-09T19:13 +I 10-10T10:35 +O 10-10T16:43 +I 10-11T11:28 +O 10-11T12:29 +I 10-11T14:54 +O 10-11T18:56 +I 10-12T09:45 +O 10-12T12:23 +I 10-12T15:39 +O 10-12T17:06 +I 10-13T09:55 +O 10-13T10:30 +I 10-14T15:25 +O 10-14T17:19 +I 10-16T13:19 +O 10-16T17:00 +I 10-17T10:15 +O 10-17T13:41 +I 10-18T13:22 +O 10-18T13:54 +I 10-18T14:11 +O 10-18T18:00 +I 10-19T10:22 +O 10-19T13:00 +I 10-19T13:25 +O 10-19T16:59 +I 10-19T17:23 +O 10-19T18:34 +I 10-21T12:04 +O 10-21T12:51 +I 10-23T14:59 +O 10-23T17:19 +I 10-24T13:07 +O 10-24T13:57 +I 10-25T15:34 +O 10-25T17:53 +I 10-26T11:57 +O 10-26T19:47 +I 10-27T17:56 +O 10-27T20:23 +I 11-01T13:40 +O 11-01T18:13 +I 11-02T13:24 +O 11-02T18:57 +I 11-03T12:59 +O 11-03T15:53 +I 11-03T17:07 +O 11-03T18:31 +I 11-04T19:07 +O 11-04T19:34 +I 11-07T15:15 +O 11-07T17:11 +I 11-08T13:58 +O 11-08T17:27 +I 11-09T17:02 +O 11-09T19:05 +I 11-10T13:19 +O 11-10T21:12 +I 11-11T16:03 +O 11-11T20:24 +I 11-14T13:39 +O 11-14T14:20 +I 11-14T14:23 +O 11-14T14:23 +I 11-15T17:06 +O 11-15T21:11 +I 11-16T15:11 +O 11-16T17:09 +I 11-17T14:34 +O 11-17T22:01 +I 11-18T15:25 +O 11-18T19:39 +I 11-20T15:34 +O 11-20T19:22 +I 11-21T15:10 +O 11-21T19:09 +I 11-28T12:20 diff --git a/timetracker b/timetracker new file mode 100755 index 0000000..fd67d95 --- /dev/null +++ b/timetracker @@ -0,0 +1,134 @@ +#!/bin/bash + +# Time sheet creator +# Stores clock in and outs to timesheet named for the ending date of the ts +usage() { + cat < "${TIMESHEET_DIR}/${TIMESHEET}" +} + +getTimesheet() { + # get Timesheet to use + if [[ -z "$TIMESHEET" ]] ; then + # no timesheet, create one + createTimesheet + else + # timesheet found, check we are still in period + period_end=$(date -d "$(echo "$TIMESHEET" | awk -F . '{print $1}') + 1 days" +%s) + if [[ $(date +%s) -ge $period_end ]] ; then + # past timesheet, moving to archive and creating new + mv ${TIMESHEET_DIR}/${TIMESHEET} ${TIMESHEET_DIR}/archive + createTimesheet + fi + fi +} + +clockIn() { + # clock in by creating env file + curdate=$(date +%s) + env_details=$(printf 'DATE=%s\nTIME_IN=%s\n' "$curdate" "$curdate") + if [[ ! -f "$CURRENT_SESSION" ]] ; then + # creating session + echo "$env_details" > "$CURRENT_SESSION" + else + echo "Already Clocked In!" >&2 + exit 1 + fi +} + +clockOut() { + # clock out + if [[ -f "$CURRENT_SESSION" ]] ; then + # session exists, get info + source "$CURRENT_SESSION" + # printing to timesheet + TIME_OUT=$(date +%s) + TOTAL_TIME=$(($TIME_OUT - $TIME_IN + 3600 * 5)) + echo "$TOTAL_TIME" + # printing to timesheet + printf '%s, %s, %s, %s\n' "$(date -d @$DATE "+%a %b-%d")" "$(date -d @$TIME_IN +%I:%M%P)" "$(date -d @$TIME_OUT +%I:%M%P)" "$(date -d @$TOTAL_TIME +%H:%M)" >> ${TIMESHEET_DIR}/${TIMESHEET} + # cleaning up session + rm ${CURRENT_SESSION} + else + # no session + echo "Not clocked in!" >&2 + exit 1 + fi +} + +visualize() { + # visualize the current timesheet + column -s "," -t < ${TIMESHEET_DIR}/${TIMESHEET} +} + +totalHours() { + # tally up hours for the current timesheet + while read -r entry; do + date=$(echo "$entry" | awk -F , '{print $1}' | tr -d ",\n") + time=$(echo "$entry" | awk -F , '{print $4}' | tr -d " ,\n") + if [[ "$date" != "Date" ]] ; then + printf 'On %s worked %s\n' "$date" "$time" + hours=$(($hours + 10#$(echo "$time" | awk -F : '{print $1}'))) + mins=$(($mins + 10#$(echo "$time" | awk -F : '{print $2}'))) + fi + done < ${TIMESHEET_DIR}/${TIMESHEET} + hours=$(($hours + $mins/60)) # overflow + mins=$(($mins%60)) + printf 'Worked %d hours, %d minutes\n' "$hours" "$mins" +} + +# get the timesheet +getTimesheet + +# parse args +while [[ $# -gt 0 ]] ; do + case $1 in + -h | --help) + usage + exit 0 + ;; + -i | --in) + clockIn + ;; + -o | --out) + clockOut + ;; + -v | --visualize) + visualize + ;; + -t | --total) + totalHours + ;; + *) + echo "Error: Unrecognized" >&2 + usage + exit 1 + ;; + esac + shift +done