忍者ブログ

ひつ(じのひよこが)プログラミングします。
お仕事や趣味で困ったこととか、何度も「あれ?どうだったかしら」と調べたりしたこととか、作ったものとか、こどものこととかを書きます
★前は週末定期更新でしたが今は不定期更新です

2024/11    10« 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  »12

その月が何日あるのかをさっと計算する

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

コメント

ただいまコメントを受けつけておりません。

その月が何日あるのかをさっと計算する

https://shunshun94.github.io/shared/other/io/github/shunshun94/util/timeutil.jsこんなのを書いた。

// 2019年の2月が何日あるのかを計算している
console.log(1, io.github.shunshun94.util.Time.getMonthDays('2019/2') );
console.log(2, io.github.shunshun94.util.Time.getMonthDays('2019/02') );
console.log(3, io.github.shunshun94.util.Time.getMonthDays('2019-2') );
console.log(4, io.github.shunshun94.util.Time.getMonthDays('2019-02') );
console.log(5, io.github.shunshun94.util.Time.getMonthDays(2019, 2) );
console.log(6, io.github.shunshun94.util.Time.getMonthDays('2019', '2') );
console.log(7, io.github.shunshun94.util.Time.getMonthDays('2019', '02') );
console.log(8, io.github.shunshun94.util.Time.getMonthDays(new Date('2019/02/14')) );
console.log(9, io.github.shunshun94.util.Time.getMonthDays(2), '(これだけ「今年の2月」を対象としている)'); 

// 第一引数から第二引数の期間にある週末をリストアップ
const weekends = io.github.shunshun94.util.Time.getWeekendsInTerm(
    new Date('2019/1/1'),
    new Date('2020/1/1')
);
// => ※1 結果は追記部分記載

// 第一引数から第二引数の期間にある 10:00~14:00 の区間をリストアップ
const dayTimes = io.github.shunshun94.util.Time.getDaytimeTermInTerm(
    new Date('2019/1/1'),
    new Date('2020/1/1'),
    '10:00',
    '14:00'
);

// 第一引数から第二引数の期間にある 10:00~14:00 の区間をリストアップ (月~金除)
io.github.shunshun94.util.Time.getDaytimeTermInTerm(
    new Date('2019/1/1'),
    new Date('2020/1/1'),
    '10:00',
    '14:00',
    [1,2,3,4,5]
);

// 上述の weekends と dayTimes の重複する区間だけリストアップ
io.github.shunshun94.util.Time.getConflictedTerms(weekends, dayTimes);

スケジュールの重複などを扱わなければならない状況で便利かも。


※1 の結果

[
  {
    "head": 1546614000000,
    "tail": 1546786800000,
    "headDate": "2019-01-04T15:00:00.000Z",
    "tailDate": "2019-01-06T15:00:00.000Z"
  },
  {
    "head": 1547218800000,
    "tail": 1547391600000,
    "headDate": "2019-01-11T15:00:00.000Z",
    "tailDate": "2019-01-13T15:00:00.000Z"
  },
  {
    "head": 1547823600000,
    "tail": 1547996400000,
    "headDate": "2019-01-18T15:00:00.000Z",
    "tailDate": "2019-01-20T15:00:00.000Z"
  },
  {
    "head": 1548428400000,
    "tail": 1548601200000,
    "headDate": "2019-01-25T15:00:00.000Z",
    "tailDate": "2019-01-27T15:00:00.000Z"
  },
  {
    "head": 1549033200000,
    "tail": 1549206000000,
    "headDate": "2019-02-01T15:00:00.000Z",
    "tailDate": "2019-02-03T15:00:00.000Z"
  },
  {
    "head": 1549638000000,
    "tail": 1549810800000,
    "headDate": "2019-02-08T15:00:00.000Z",
    "tailDate": "2019-02-10T15:00:00.000Z"
  },
  {
    "head": 1550242800000,
    "tail": 1550415600000,
    "headDate": "2019-02-15T15:00:00.000Z",
    "tailDate": "2019-02-17T15:00:00.000Z"
  },
  {
    "head": 1550847600000,
    "tail": 1551020400000,
    "headDate": "2019-02-22T15:00:00.000Z",
    "tailDate": "2019-02-24T15:00:00.000Z"
  },
  {
    "head": 1551452400000,
    "tail": 1551625200000,
    "headDate": "2019-03-01T15:00:00.000Z",
    "tailDate": "2019-03-03T15:00:00.000Z"
  },
  {
    "head": 1552057200000,
    "tail": 1552230000000,
    "headDate": "2019-03-08T15:00:00.000Z",
    "tailDate": "2019-03-10T15:00:00.000Z"
  },
  {
    "head": 1552662000000,
    "tail": 1552834800000,
    "headDate": "2019-03-15T15:00:00.000Z",
    "tailDate": "2019-03-17T15:00:00.000Z"
  },
  {
    "head": 1553266800000,
    "tail": 1553439600000,
    "headDate": "2019-03-22T15:00:00.000Z",
    "tailDate": "2019-03-24T15:00:00.000Z"
  },
  {
    "head": 1553871600000,
    "tail": 1554044400000,
    "headDate": "2019-03-29T15:00:00.000Z",
    "tailDate": "2019-03-31T15:00:00.000Z"
  },
  {
    "head": 1554476400000,
    "tail": 1554649200000,
    "headDate": "2019-04-05T15:00:00.000Z",
    "tailDate": "2019-04-07T15:00:00.000Z"
  },
  {
    "head": 1555081200000,
    "tail": 1555254000000,
    "headDate": "2019-04-12T15:00:00.000Z",
    "tailDate": "2019-04-14T15:00:00.000Z"
  },
  {
    "head": 1555686000000,
    "tail": 1555858800000,
    "headDate": "2019-04-19T15:00:00.000Z",
    "tailDate": "2019-04-21T15:00:00.000Z"
  },
  {
    "head": 1556290800000,
    "tail": 1556463600000,
    "headDate": "2019-04-26T15:00:00.000Z",
    "tailDate": "2019-04-28T15:00:00.000Z"
  },
  {
    "head": 1556895600000,
    "tail": 1557068400000,
    "headDate": "2019-05-03T15:00:00.000Z",
    "tailDate": "2019-05-05T15:00:00.000Z"
  },
  {
    "head": 1557500400000,
    "tail": 1557673200000,
    "headDate": "2019-05-10T15:00:00.000Z",
    "tailDate": "2019-05-12T15:00:00.000Z"
  },
  {
    "head": 1558105200000,
    "tail": 1558278000000,
    "headDate": "2019-05-17T15:00:00.000Z",
    "tailDate": "2019-05-19T15:00:00.000Z"
  },
  {
    "head": 1558710000000,
    "tail": 1558882800000,
    "headDate": "2019-05-24T15:00:00.000Z",
    "tailDate": "2019-05-26T15:00:00.000Z"
  },
  {
    "head": 1559314800000,
    "tail": 1559487600000,
    "headDate": "2019-05-31T15:00:00.000Z",
    "tailDate": "2019-06-02T15:00:00.000Z"
  },
  {
    "head": 1559919600000,
    "tail": 1560092400000,
    "headDate": "2019-06-07T15:00:00.000Z",
    "tailDate": "2019-06-09T15:00:00.000Z"
  },
  {
    "head": 1560524400000,
    "tail": 1560697200000,
    "headDate": "2019-06-14T15:00:00.000Z",
    "tailDate": "2019-06-16T15:00:00.000Z"
  },
  {
    "head": 1561129200000,
    "tail": 1561302000000,
    "headDate": "2019-06-21T15:00:00.000Z",
    "tailDate": "2019-06-23T15:00:00.000Z"
  },
  {
    "head": 1561734000000,
    "tail": 1561906800000,
    "headDate": "2019-06-28T15:00:00.000Z",
    "tailDate": "2019-06-30T15:00:00.000Z"
  },
  {
    "head": 1562338800000,
    "tail": 1562511600000,
    "headDate": "2019-07-05T15:00:00.000Z",
    "tailDate": "2019-07-07T15:00:00.000Z"
  },
  {
    "head": 1562943600000,
    "tail": 1563116400000,
    "headDate": "2019-07-12T15:00:00.000Z",
    "tailDate": "2019-07-14T15:00:00.000Z"
  },
  {
    "head": 1563548400000,
    "tail": 1563721200000,
    "headDate": "2019-07-19T15:00:00.000Z",
    "tailDate": "2019-07-21T15:00:00.000Z"
  },
  {
    "head": 1564153200000,
    "tail": 1564326000000,
    "headDate": "2019-07-26T15:00:00.000Z",
    "tailDate": "2019-07-28T15:00:00.000Z"
  },
  {
    "head": 1564758000000,
    "tail": 1564930800000,
    "headDate": "2019-08-02T15:00:00.000Z",
    "tailDate": "2019-08-04T15:00:00.000Z"
  },
  {
    "head": 1565362800000,
    "tail": 1565535600000,
    "headDate": "2019-08-09T15:00:00.000Z",
    "tailDate": "2019-08-11T15:00:00.000Z"
  },
  {
    "head": 1565967600000,
    "tail": 1566140400000,
    "headDate": "2019-08-16T15:00:00.000Z",
    "tailDate": "2019-08-18T15:00:00.000Z"
  },
  {
    "head": 1566572400000,
    "tail": 1566745200000,
    "headDate": "2019-08-23T15:00:00.000Z",
    "tailDate": "2019-08-25T15:00:00.000Z"
  },
  {
    "head": 1567177200000,
    "tail": 1567350000000,
    "headDate": "2019-08-30T15:00:00.000Z",
    "tailDate": "2019-09-01T15:00:00.000Z"
  },
  {
    "head": 1567782000000,
    "tail": 1567954800000,
    "headDate": "2019-09-06T15:00:00.000Z",
    "tailDate": "2019-09-08T15:00:00.000Z"
  },
  {
    "head": 1568386800000,
    "tail": 1568559600000,
    "headDate": "2019-09-13T15:00:00.000Z",
    "tailDate": "2019-09-15T15:00:00.000Z"
  },
  {
    "head": 1568991600000,
    "tail": 1569164400000,
    "headDate": "2019-09-20T15:00:00.000Z",
    "tailDate": "2019-09-22T15:00:00.000Z"
  },
  {
    "head": 1569596400000,
    "tail": 1569769200000,
    "headDate": "2019-09-27T15:00:00.000Z",
    "tailDate": "2019-09-29T15:00:00.000Z"
  },
  {
    "head": 1570201200000,
    "tail": 1570374000000,
    "headDate": "2019-10-04T15:00:00.000Z",
    "tailDate": "2019-10-06T15:00:00.000Z"
  },
  {
    "head": 1570806000000,
    "tail": 1570978800000,
    "headDate": "2019-10-11T15:00:00.000Z",
    "tailDate": "2019-10-13T15:00:00.000Z"
  },
  {
    "head": 1571410800000,
    "tail": 1571583600000,
    "headDate": "2019-10-18T15:00:00.000Z",
    "tailDate": "2019-10-20T15:00:00.000Z"
  },
  {
    "head": 1572015600000,
    "tail": 1572188400000,
    "headDate": "2019-10-25T15:00:00.000Z",
    "tailDate": "2019-10-27T15:00:00.000Z"
  },
  {
    "head": 1572620400000,
    "tail": 1572793200000,
    "headDate": "2019-11-01T15:00:00.000Z",
    "tailDate": "2019-11-03T15:00:00.000Z"
  },
  {
    "head": 1573225200000,
    "tail": 1573398000000,
    "headDate": "2019-11-08T15:00:00.000Z",
    "tailDate": "2019-11-10T15:00:00.000Z"
  },
  {
    "head": 1573830000000,
    "tail": 1574002800000,
    "headDate": "2019-11-15T15:00:00.000Z",
    "tailDate": "2019-11-17T15:00:00.000Z"
  },
  {
    "head": 1574434800000,
    "tail": 1574607600000,
    "headDate": "2019-11-22T15:00:00.000Z",
    "tailDate": "2019-11-24T15:00:00.000Z"
  },
  {
    "head": 1575039600000,
    "tail": 1575212400000,
    "headDate": "2019-11-29T15:00:00.000Z",
    "tailDate": "2019-12-01T15:00:00.000Z"
  },
  {
    "head": 1575644400000,
    "tail": 1575817200000,
    "headDate": "2019-12-06T15:00:00.000Z",
    "tailDate": "2019-12-08T15:00:00.000Z"
  },
  {
    "head": 1576249200000,
    "tail": 1576422000000,
    "headDate": "2019-12-13T15:00:00.000Z",
    "tailDate": "2019-12-15T15:00:00.000Z"
  },
  {
    "head": 1576854000000,
    "tail": 1577026800000,
    "headDate": "2019-12-20T15:00:00.000Z",
    "tailDate": "2019-12-22T15:00:00.000Z"
  },
  {
    "head": 1577458800000,
    "tail": 1577631600000,
    "headDate": "2019-12-27T15:00:00.000Z",
    "tailDate": "2019-12-29T15:00:00.000Z"
  }
]
PR

コメント

ただいまコメントを受けつけておりません。

ブログ内検索

P R