master
1import { Commit, define, latest } from '#src'
2
3export default define({
4 url: import.meta.url,
5 badges: ['programmers-day'] as const,
6 present(data, grant) {
7 const commits: Commit[] = []
8
9 for (const repo of data.repos) {
10 for (const commit of repo.commits) {
11 const data = new Date(commit.committedDate)
12 if (getDayOfYear(data) === 256) {
13 commits.push(commit)
14 }
15 }
16 }
17
18 if (commits.length > 0) {
19 grant(
20 'programmers-day',
21 'Happy Programmers Day! I committed on a 256 Day of Year!',
22 ).evidenceCommits(...commits.sort(latest).slice(0, 6))
23 }
24 },
25})
26
27function getDayOfYear(date: Date) {
28 return (
29 (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) -
30 Date.UTC(date.getFullYear(), 0, 0)) /
31 86400000
32 )
33}