#Bash + coreutils, 50
Bash + coreutils, 50
date -d1ドル+$[(2ドル-`date -d1ドル +%u`+9)%7-3]day +%Y%m%d
date -d1ドル +%ugives the day of week (1..7); 1 is Monday- This is subtracted from the input day of week to give a difference of day indexes. We want to add a factor between in the range [-3, 3] to the input date to get the closest date, so we add a magic factor 9, take the modulo 7, then subtract 3. The magic factor 9 is
3 + 7 - 1. The 3 adjusts the input range for range [-3, 3], and is subtracted again after the modulo. The 7 is required because bash modulo is the same as CPU modulo and can give -ve results - adding 7 adjusts into the right range. The -1 is because in the input, 1 is Sunday, but with the %u output, 1 is Monday. - The outer
datethen parses<input date> + <magic factor>daysand presents it in the YYYYMMDD format.
#Bash + coreutils, 50
date -d1ドル+$[(2ドル-`date -d1ドル +%u`+9)%7-3]day +%Y%m%d
date -d1ドル +%ugives the day of week (1..7); 1 is Monday- This is subtracted from the input day of week to give a difference of day indexes. We want to add a factor between in the range [-3, 3] to the input date to get the closest date, so we add a magic factor 9, take the modulo 7, then subtract 3. The magic factor 9 is
3 + 7 - 1. The 3 adjusts the input range for range [-3, 3], and is subtracted again after the modulo. The 7 is required because bash modulo is the same as CPU modulo and can give -ve results - adding 7 adjusts into the right range. The -1 is because in the input, 1 is Sunday, but with the %u output, 1 is Monday. - The outer
datethen parses<input date> + <magic factor>daysand presents it in the YYYYMMDD format.
Bash + coreutils, 50
date -d1ドル+$[(2ドル-`date -d1ドル +%u`+9)%7-3]day +%Y%m%d
date -d1ドル +%ugives the day of week (1..7); 1 is Monday- This is subtracted from the input day of week to give a difference of day indexes. We want to add a factor between in the range [-3, 3] to the input date to get the closest date, so we add a magic factor 9, take the modulo 7, then subtract 3. The magic factor 9 is
3 + 7 - 1. The 3 adjusts the input range for range [-3, 3], and is subtracted again after the modulo. The 7 is required because bash modulo is the same as CPU modulo and can give -ve results - adding 7 adjusts into the right range. The -1 is because in the input, 1 is Sunday, but with the %u output, 1 is Monday. - The outer
datethen parses<input date> + <magic factor>daysand presents it in the YYYYMMDD format.
#Bash + coreutils, 50
date -d1ドル+$[(2ドル-`date -d1ドル +%u`+9)%7-3]day +%Y%m%d
date -d1ドル +%ugives the day of week (1..7); 1 is Monday- This is subtracted from the input day of week to give a difference of day indexes. We want to add a factor between in the range [-3, 3] to the input date to get the closest date, so we add a magic factor 9, take the modulo 7, then subtract 3. The magic factor 9 is
3 + 7 - 1. The 3 adjusts the input range for range [-3, 3], and is subtracted again after the modulo. The 7 is required because bash modulo is the same as CPU modulo and can give -ve results - adding 7 adjusts into the right range. The -1 is because in the input, 1 is Sunday, but with the %u output, 1 is Monday. - The outer
datethen parses<input date> + <magic factor>daysand presents it in the YYYYMMDD format.
#Bash + coreutils, 50
date -d1ドル+$[(2ドル-`date -d1ドル +%u`+9)%7-3]day +%Y%m%d
date -d1ドル +%ugives the day of week (1..7); 1 is Monday- This is subtracted from the input day of week to give a difference of day indexes. We want to add a factor between in the range [-3, 3] to the input date to get the closest date, so we add a magic factor 9, take the modulo 7, then subtract 3. The magic factor 9 is
3 + 7 - 1. The 3 adjusts the input range for range [-3, 3], and is subtracted again after the modulo. The 7 is required because bash modulo is the same as CPU modulo and can give -ve results - adding 7 adjusts into the right range. The -1 is because in the input, 1 is Sunday, but with the %u output, 1 is Monday. - The outer
datethen parses<input date> + <magic factor>daysand presents it in the YYYYMMDD format.