2022年2月21日月曜日

国際祝日対応再び2022年度版

 date-holidays.jsonの更新を行いました。138Aより適用になっています。


その際、npm -i date-holidaysでは、ubuntu20.4LTSのnode versionが低いらしく動きませんでした。以下は、その対処方法で、まず node versionを14.xに上げました。

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm i date-holidays
node_modules/testフォルダ下で、
node tree2.js >date-holidays.json

tree2.jsソースは、
#!/usr/bin/env node

/**
 * draw tree of supported countries, states, regions
 */
function country_draw(stream,hd,country,country_name,state,state_name,region,region_name){
  hd.init(country)
    
    var holidays=hd.getHolidays(2015)
    for (y=2016;y<2035 -="" 10="" 1="" :="" console.dir="" console.log="" const="" countries="" countrieslen="" country="" country_code="" country_name="" d="" date-holidays="" date="" draw="[" dt.getdate="" dt.getmonth="" dt="new" else="" for="" foreach="" function="" hd="new" holiday.substitute="" holiday.type="=" holiday="" holidays1="hd.getHolidays(y)" holidays="" i="" if="" m="" maxarraylength:="" maxarraylength="" msec="" n="" null="" object.keys="" of="" ountries:="" public="" public_holidays.push="" public_holidays="" region="" region_code="" region_name="" slice="" state="" state_code="" state_name="" str="" stream="" substitute_holidays.push="" substitute_holidays="" t="" tree="" util.inspect="" util="" var="" y="dt.getFullYear();"> {
    const d = (i === countriesLen ? draw[1] : draw[0])
    //console.log(d + country + ': ' + countries[country] + '\n')
    const hd = new Holidays()
    if (i!=0) console.log(",");
    country_draw(stream,hd,country,countries[country],"","","","")
    const states = hd.getStates(country)
    if (states) {
      const statesLen = Object.keys(states).length - 1
      Object.keys(states).forEach((state, j) => {
        let d = (i === countriesLen ? draw[3] : draw[2])
        d += (j === statesLen ? draw[1] : draw[0])
        //console.log(d + state + ': ' + states[state] + '\n')
        console.log(",");
   	country_draw(stream,hd,country,countries[country],state,states[state],"","")

        const regions = hd.getRegions(country, state)
        if (regions) {
          const regionsLen = Object.keys(regions).length - 1
          Object.keys(regions).forEach((region, k) => {
            let d = (i === countriesLen ? draw[3] : draw[2])
            d += (j === statesLen ? draw[3] : draw[2])
            d += (k === regionsLen ? draw[1] : draw[0])
            //console.log(d + region + ': ' + regions[region] + '\n')
	console.log(",");
   	country_draw(stream,hd,country,countries[country],state,states[state],region,regions[region])

          })
        }
      })
    }
  })
}
module.exports = tree

if (module === require.main) {
    console.log("{'members':[\n")
  tree(process.stdout)
  console.log("]\n")
  console.log("}\n")
}

0 件のコメント:

コメントを投稿