0

I am needing to work out paid overtime for a project. I have to be compensated for working after 1600. I need to find the last commit to a repository (branch does not matter) for every day over the past 4 months.

How would I achieve this? I need this in a format that I can parse, so I can run a script over it and calculate the hours

Gibbo
  • 630
  • 1
  • 8
  • 22

3 Answers3

1

You can get each day commit like this git log --after="2018-11-12 00:00" --format="%ci %cr""

After that, you can write a script to run for each day

For more details read this

twister_void
  • 1,377
  • 3
  • 13
  • 31
1

I used the one-liner below to get the commit hashes of the commits since yesterday, 26/03/2020, commited after 16:00:00. You can adjust accordingly with your date:

$ git log --all --since="26/03/2020" --oneline --pretty=format:"%H %an %ad" | awk -F ' ' '{gsub(":","",$7); if($7>160000) print $1}'
Paolo
  • 21,270
  • 6
  • 38
  • 69
1

The following pipe should provide you with the output you are looking for

git log --all --since="26/03/2019" --pretty=format:"%an %ad" --date=format:'%Y-%m-%d %H:%M:%S' | process.awk MYNAME=Enrico

The script process.awk is the following (you have to chmod +x it, or alternatively you have to change | process.awk ... to | awk -f process.awk ...)

#!/usr/bin/env -S awk -f
BEGIN {
  fourPM = 16*3600
}
!match($1,MYNAME) || $2 == previousDay { next }
{
  previousDay = $2
  split($3,previousTime,":")
  oversec = previousTime[1]*3600 \
          + previousTime[2]*60   \
          + previousTime[3]      \
          - fourPM
  if (oversec > 0) {
    $(NF + 1) = "overtime: " int(oversec/3600)        \
                         ":" int((oversec % 3600)/60) \
                         ":" int(oversec % 60)
    print $0
  }
}
Enlico
  • 23,259
  • 6
  • 48
  • 102