]> git.plutz.net Git - shellwiki/blobdiff - datetime.sh
nth-last-weekday recurrence
[shellwiki] / datetime.sh
index 124ccfb6643584605960bba9d761bca116cf3375..2b4bba9ff014d00c2e198432141374dc10bd06de 100755 (executable)
@@ -74,3 +74,28 @@ istime(){
   printf '%02i:%02i\n' "${h#0}" "${m#0}"
   return 0
 }
+
+numdays(){
+  # return number of days in a month (i.e. 28, 29, 30, or 31)
+  local y="$1" m="${2#0}"
+
+  case $m in
+    1|3|5|7|10|12)
+      printf 31\\n
+      ;;
+    4|6|8|9|11)
+      printf 30\\n
+      ;;
+    2) if  [ "$((y % 400))" -eq 0 ]; then
+        printf 29\\n
+      elif [ "$((y % 100))" -eq 0 ]; then
+        printf 28\\n
+      elif [ "$((y % 4))" -eq 0 ]; then
+        printf 29\\n
+      else
+        printf 28\\n
+      fi
+      ;;
+    *) return 1;;
+  esac
+}