특정 연도의 주 번호에서 자동으로 날짜 가져오기

특정 연도의 주 번호에서 자동으로 날짜 가져오기

주 번호를 기준으로 날짜를 자동으로 출력하는 방법이 있습니까?

보다 정확하게는 특정 연도의 주 번호를 입력하고 출력으로 월요일부터 일요일까지의 날짜를 얻습니까?

달력을 생성하기 위한 여러 패키지가 있지만 그 중 어느 것도 이를 허용하지 않는 것 같습니다. 누구든지 좋은 팁이 있나요?

(Taco Hoekwater는 내 질문에 가까운 작업을 수행했지만 그 반대였습니다. 주 번호에 대한 매크로)

답변1

나도 추가했어PGFCalendar의 반대그러나 우리는 필요한 주의 정확한 시작일과 종료일을 얻기 위해 그것과 약간의 수학을 사용할 수 있습니다.

PGFCalendar와 내 확장 프로그램 모두TikZ-ext이에 대해 높은 수준의 인터페이스를 제공하지 않으므로 일부 개수, 값 및 변환을 조정해야 합니다.

이것은 주어진 주가 실제로 연도인지 여부를 확인하지 않습니다. \weekinyear{174}{2021}아래 코드와 동일한 결과를 얻는 데 사용할 수 있습니다 .

암호

\documentclass{article}
\usepackage{pgfcalendar-ext}
\makeatletter
\newcommand*\weekinyear[2]{% #1 = week, #2 = year
  \pgfcalendardatetojulian{#2-01-01}{\count@}%
  \edef\wiy@first{\the\count@}%
  \pgfcalendarjuliantoweekday{\count@}{\count@}%
  \edef\wiy@day{\the\count@}%
  \pgfcalendarjulianyeartoweek{\wiy@first}{#2}{\count@}%
  \ifnum\count@>1 \count@=0 \fi% first day might be in last week of prev year
  \pgfintset\count@{\wiy@first+(#1-\count@)*7-\wiy@day}%
  \pgfcalendarjuliantodate{\count@}{\wiyStartY}{\wiyStartM}{\wiyStartD}%
  \advance\count@ by 6
  \pgfcalendarjuliantodate{\count@}{\wiyEndY}{\wiyEndM}{\wiyEndD}%
}
\makeatother
\begin{document}
\weekinyear{18}{2024}
Week 18 in year 2024 starts on
Monday \wiyStartY-\wiyStartM-\wiyStartD\ and
ends on Sunday \wiyEndY-\wiyEndM-\wiyEndD.
\end{document}

산출

2024년 18주차는 2024년 4월 29일 월요일에 시작하여 2024년 5월 5일 일요일에 끝납니다.

관련 정보