File tree Expand file tree Collapse file tree 1 file changed +10
-17
lines changed Expand file tree Collapse file tree 1 file changed +10
-17
lines changed Original file line number Diff line number Diff line change @@ -6,25 +6,18 @@ get_version() {
6
6
local version=$( date -u -d " $date " +" %y.%m." ) $week_number
7
7
echo " $version "
8
8
}
9
-
10
9
get_week_number () {
11
- local date=$1
12
- local first_day_of_month=$( date -u -d " $( date -u -d " $date " +" %Y-%m-01T00:00:00%z" ) " +" %Y-%m-%dT%H:%M:%S%z" ) # First day of the month
13
- local days_until_first_monday=$(( ( $(date - u - d "$first_day_of_month " + "% u") + 7 - 1 ) % 7 )) # Days until the first Monday of the month
14
- local first_monday_of_month=$( date -u -d " $first_day_of_month +$days_until_first_monday days" +" %Y-%m-%dT%H:%M:%S%z" ) # First Monday of the month
10
+ local date=" $1 "
11
+ local first_day_of_month=$( date -d " $date " +%Y-%m-01)
12
+ local first_day_of_week=" Monday"
13
+
14
+ # Find the first day of the week that falls on or before the first day of the month
15
+ while [[ $( date -d " $first_day_of_month " +%A) != " $first_day_of_week " ]]; do
16
+ first_day_of_month=$( date -d " $first_day_of_month - 1 day" +%Y-%m-%d)
17
+ done
15
18
16
- if [[ $date < $first_monday_of_month ]]; then
17
- echo 1
18
- else
19
- local week_number=$(( ( $(date - u - d "$date " + "% d") - $(date - u - d "$first_monday_of_month " + "% d") ) / 7 + 1 ))
20
- local next_monday=$( date -u -d " $first_monday_of_month +$(( week_number * 7 )) days" +" %Y-%m-%dT%H:%M:%S%z" )
21
-
22
- if [[ $next_monday > $date ]]; then
23
- echo $week_number
24
- else
25
- echo $(( week_number + 1 ))
26
- fi
27
- fi
19
+ local week_number=$(( ($(date - d "$date " +% s) - $(date - d "$first_day_of_month " +% s)) / (60 * 60 * 24 * 7) + 1))
20
+ echo " $week_number "
28
21
}
29
22
30
23
versionNumber=$( get_version)
You can’t perform that action at this time.
0 commit comments