neige d'aoust

knowledge, art, and other stuff

User Tools

Site Tools


cardcal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cardcal [2025/11/11 14:12] Yukicardcal [2025/11/11 23:24] (current) Yuki
Line 18: Line 18:
 { {
   display: inline-table;   display: inline-table;
 +}
 +#year, #gen
 +{
 +  font-size: 2em;
 +}
 +#year
 +{
 +  width: 4em;
 } }
 </style> </style>
 +<input id="year" size="4" type="number"/><button id="gen">Generate</button>
 <div id="cal"> <div id="cal">
 </div> </div>
Line 25: Line 34:
 import moment from 'https://esm.run/moment'; import moment from 'https://esm.run/moment';
 import * as seasons from 'https://esm.run/@postlight/seasons'; import * as seasons from 'https://esm.run/@postlight/seasons';
-var year = 2025;+var y = moment().year(); 
 +var $year = jQuery("#year"); 
 +$year.val(y); 
 +genCal(y); 
 +jQuery("#gen").click(e=>genCal($year.val())); 
 +function genCal(year) 
 +{
 var last = moment(seasons.getSeasonStart(11,year-1)); var last = moment(seasons.getSeasonStart(11,year-1));
 var weeks = [last.isoWeek()-last.isoWeeksInYear(),...seasons.getSeasons(year).map(t=>moment(t).isoWeek())] var weeks = [last.isoWeek()-last.isoWeeksInYear(),...seasons.getSeasons(year).map(t=>moment(t).isoWeek())]
 console.log(weeks) console.log(weeks)
 var $cal = jQuery("#cal"); var $cal = jQuery("#cal");
 +$cal.html("");
 var cards = ['A','2','3','4','5','6','7','8','9','10','J','Q','K','Joker']; var cards = ['A','2','3','4','5','6','7','8','9','10','J','Q','K','Joker'];
 var suits = [0x2666, 0x2660, 0x2665, 0x2663, 0x2666].map(a=>String.fromCodePoint(a, 0xfe0f)); var suits = [0x2666, 0x2660, 0x2665, 0x2663, 0x2666].map(a=>String.fromCodePoint(a, 0xfe0f));
Line 36: Line 52:
 for(var month = 0; month < 12; month++) for(var month = 0; month < 12; month++)
 { {
-  var time = moment.utc(year+"-"+(month+1));+  var time = moment.utc(year+"-"+(month+1).toString().padStart(2,'0'));
   var name = time.format("MMMM");   var name = time.format("MMMM");
   var $table = jQuery(`<table class="inline">   var $table = jQuery(`<table class="inline">
Line 47: Line 63:
   var last = time.add(1,'months').subtract(1,'days').isoWeek()   var last = time.add(1,'months').subtract(1,'days').isoWeek()
   if(last < first)   if(last < first)
-    if(month == 0) first -= time.isoWeeksInYear(); +    if(month == 0) first -= moment.utc().isoWeekYear(year-1).isoWeeksInYear(); 
-    else if(month == 11) last += time.isoWeeksInYear();+    else if(month == 11) last += moment.utc().isoWeekYear(year).isoWeeksInYear();
   for(var week = first; week <= last; week++)   for(var week = first; week <= last; week++)
   {   {
Line 54: Line 70:
     var suit = weeks.findLastIndex(a=>a<=week);     var suit = weeks.findLastIndex(a=>a<=week);
     var days = Array(7).fill(0).map((a,i)=>{     var days = Array(7).fill(0).map((a,i)=>{
-      var m = moment.utc(year).isoWeek(week).day(i+2);+      var m = moment.utc().isoWeekYear(year).isoWeek(week).day(i+1);
       return m.month()==month?m.date():'';       return m.month()==month?m.date():'';
     })     })
Line 64: Line 80:
   jQuery("tbody", $table).append($week);   jQuery("tbody", $table).append($week);
   $cal.append($table);   $cal.append($table);
 +}
 } }
 </script> </script>
 </html> </html>
cardcal.1762888335.txt.gz · Last modified: by Yuki