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

Update the date syntax to use gnu date #1

Merged
merged 6 commits into from
Sep 9, 2023

Conversation

lukas-the-wizard
Copy link
Contributor

No description provided.

@mikaelvesavuori
Copy link
Owner

Hey! Thanks for this.

Since this is at least 2 different changes, I'd want this to be a separate pull request from the new feature being added.

For the date, I'm not getting that variant to work correctly on MacOS — this is the same I tried in my own work. Unfortunately, it gives too big values, i.e.

Days since the last commit: 19605

Is there an issue with the current formatting when run on your system, which I suspect is some Linux variant?

@lukas-the-wizard
Copy link
Contributor Author

lukas-the-wizard commented Sep 6, 2023

Mac/BSD uses a non standard date variant, this fix makes it run with 90% of the linux distros...
We should do a switch then that uses the Mac/BSD version on Mac/BSD and the Linux version on linux.

lemme try to find something that does that

@lukas-the-wizard
Copy link
Contributor Author

like this?

@lukas-the-wizard
Copy link
Contributor Author

lukas-the-wizard commented Sep 6, 2023

im new to git
next time it gets its own branch

@mikaelvesavuori
Copy link
Owner

mikaelvesavuori commented Sep 6, 2023

Thanks for the find! Had a suggestion that I updated with the tr usage in your example.

I'd suggest the following as a solution. It checks for MacOS (because that's a bit particular) and otherwise assumes standard Linux functionality. At this point I'm not overly interested in Windows or anything, given where Bash is used most commonly.

daysSinceLastCommit() {
  last_commit_date=$(git log -1 --format="%ai")

  if [[ "$(uname | tr '[:upper:]' '[:lower:]')" == "darwin" ]]; then
    last_commit_timestamp=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$last_commit_date" "+%s")
  else
    last_commit_timestamp=$(date -d "$last_commit_date" "+%s")
  fi

  current_timestamp=$(date "+%s")
  time_diff=$((current_timestamp - last_commit_timestamp))
  days_since_last_commit=$((time_diff / 86400)) # 86400 seconds in a day
  echo "Days since the last commit: $days_since_last_commit" >"$GITANALYZED_FOLDER/$FILENAME_DAYS_SINCE_LAST_COMMIT"
}

@lukas-the-wizard
Copy link
Contributor Author

yeah, seems good, should i change it?

@mikaelvesavuori
Copy link
Owner

Go ahead, and I'll merge.

@mikaelvesavuori mikaelvesavuori merged commit ef27699 into mikaelvesavuori:main Sep 9, 2023
@mikaelvesavuori
Copy link
Owner

Added the changes and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants