{"id":770,"date":"2016-03-12T21:30:15","date_gmt":"2016-03-12T21:30:15","guid":{"rendered":"http:\/\/blog.paranoidprofessor.com\/?p=770"},"modified":"2016-03-12T21:30:15","modified_gmt":"2016-03-12T21:30:15","slug":"command-line-stupid-date-tricks","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2016\/03\/12\/command-line-stupid-date-tricks\/","title":{"rendered":"command line &#8211; stupid date tricks"},"content":{"rendered":"<p>Just because you can do something doesn&#8217;t mean that you should do it. \u00a0I try and keep to that simple rule but from time to time it is fun to see what crazy things you can do in a simple shell script.<\/p>\n<p>Easter is one of those holidays that does not fall on a fixed date each year. \u00a0There is a fairly complicated formula to calculate the Easter weekend.<\/p>\n<p>All that is needed to calculate Easter is integer math. \u00a0I described how to perform simple math in a bash shell in a <a href=\"http:\/\/blog.paranoidprofessor.com\/index.php\/2016\/03\/01\/command-line-fun-math\/\" target=\"_blank\">previous blog entry<\/a>.<\/p>\n<div class=\"sbody-code\">\n<pre><code># https:\/\/en.wikipedia.org\/wiki\/Computus\r\n# anonymous Gregorian algorithm\r\n\r\ntwodig()\r\n{\r\n  retval=$1\r\n  if [ $1 -lt 10 ]\r\n  then\r\n    retval=0$1\r\n  fi\r\n  echo $retval\r\n}\r\n\r\neaster()\r\n{\r\n  Y=$1\r\n  a=$(( $Y % 19 ))\r\n  b=$(( $Y \/ 100 ))\r\n  c=$(( $Y % 100 ))\r\n  d=$(( $b \/ 4 ))\r\n  e=$(( $b % 4 ))\r\n  f=$(( ($b + 8) \/ 25 ))\r\n  g=$(( ($b - $f + 1) \/ 3 ))\r\n  h=$(( (19 * $a + $b - $d - $g + 15) % 30 ))\r\n  i=$(( $c \/ 4 ))\r\n  k=$(( $c % 4 ))\r\n  l=$(( (32 + 2 * $e + 2 * $i - $h - $k) % 7 ))\r\n  m=$(( ($a + 11 * $h + 22 * $l) \/ 451 ))\r\n\r\n  month=$(( (($h + $l - 7 * $m + 114) \/ 31) ))\r\n  month=`twodig $month`\r\n  day=$(( (($h + $l - 7 * $m + 114) % 31) + 1 ))\r\n  day=`twodig $day`\r\n\r\n  echo $Y$month$day\r\n}\r\n\r\nfor i in 2008 2009 2010 2011 2012 2013 2014 2015\r\ndo\r\n  easter $i\r\ndone\r\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Just because you can do something doesn&#8217;t mean that you should do it. \u00a0I try and keep to that simple rule but from time to time it is fun to see what crazy things you can do in a simple &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2016\/03\/12\/command-line-stupid-date-tricks\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[17,39],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/770"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":4,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":774,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/770\/revisions\/774"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}