본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Calendar

원문 보기 위키 갱신

캘린더(Calendar)는 날짜와 시간을 선택할 수 있는 컴포넌트예요. 데이트, 타임, 월, 연 단위 선택과 범위 선택을 지원하며, 특정 날이나 시간을 비활성화하거나 강조할 수 있어요.

출처: 문서

본문

Types

Calendar

표준 캘린더예요.

$('#standard_calendar')
        .calendar()
      ;

Range

범위(Range) 캘린더는 시작 날짜와 종료 날짜를 선택할 수 있게 해줘요.

Start date
            
              
                
                
              
            
          
          
            End date
            
              
                
                
              
            
          
        
      

      
      $('#rangestart').calendar({
        type: 'date',
        endCalendar: $('#rangeend')
      });
      $('#rangeend').calendar({
        type: 'date',
        startCalendar: $('#rangestart')
      });

Inline calendar

인라인 캘린더는 팝업에 표시되지 않아요.

$('#inline_calendar')
        .calendar()
      ;

Variations

Size

캘린더는 다양한 크기를 가질 수 있어요.

Inverted

캘린더는 색상이 반전될 수 있어요.

Multimonth

여러 달을 표시할 수 있어요. monthOffset을 사용해 선택한 날짜를 기준으로 시작 달을 조정할 수 있어요.

$('#multimonth_calendar')
          .calendar({
              type: 'date',
              multiMonth: 3,
              monthOffset: -1 // current month will be shown in the middle of 3 months
          })
        ;

States

Disabled

비활성화된 캘린더는 사용자 상호작용을 허용하지 않아요.

Examples

Date calendar

데이트 캘린더는 시간 선택을 비활성화해요.

$('#date_calendar')
        .calendar({
          type: 'date'
        })
      ;

Time calendar

타임 캘린더는 날짜 선택을 비활성화해요.

$('#time_calendar')
        .calendar({
          type: 'time'
        })
      ;

HTML 마크업으로 타입이나 날짜를 설정할 수도 있어요.

Year first calendar

연도 우선 캘린더는 연도를 먼저 선택해 날짜를 고르게 해줘요.

$('#year_first_calendar')
        .calendar({
          startMode: 'year'
        })
      ;

24 hour format

format 토큰을 조정해 AM/PM 표기를 없앨 수 있어요.

$('#no_ampm')
        .calendar({
          type: 'time',
          formatter: {
            time: 'H:mm',
            cellTime: 'H:mm'
          }
        })
      ;

Month and year calendar

월·연 캘린더는 날짜와 시간 선택을 비활성화해요.

$('#month_year_calendar')
        .calendar({
          type: 'month'
        })
      ;

Year calendar

연 캘린더는 연도만 선택할 수 있게 해줘요.

$('#year_calendar')
        .calendar({
          type: 'year'
        })
      ;

Min/max date

최소 및 최대 선택 날짜를 설정할 수 있어요.

var today = new Date();

      $('#minmax_calendar')
        .calendar({
          minDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 5),
          maxDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 5)
        })
      ;

HTML 마크업으로도 최소/최대 선택 날짜를 설정할 수 있어요.

Day first calendar

날짜 우선 표시 캘린더를 선택할 수 있어요. (파싱과 변환에도 영향을 줘요).

$('#day_first_calendar')
        .calendar({
          type: 'date',
          monthFirst: false
        })
      ;

Custom format

토큰 문자열 포맷터를 사용해 날짜 형식을 완전히 변경할 수 있어요.

$('#token_format_calendar')
        .calendar({
          type: 'date',
          formatter: {
            date: '"approx:"YYYY-MM-DD'
          }
        })
      ;

원하는 무엇이든 반환하는 커스텀 함수를 제공할 수도 있어요.

$('#custom_format_calendar')
        .calendar({
          type: 'date',
          formatter: {
            date: function (date, settings) {
              if (!date) return '';
              // Show the selected year 85 Years ahead
              return 'Expires in ' + (date.getFullYear() + 85);
            }
          }
        })
      ;

Century Calculation for shortyears

2자리 단축 연도(shortyear)를 입력하면, 그에 속하는 세기를 어떻게 계산할지 조정할 수 있어요.

Example 1: Shortyears 00-99 -> 2000-2099
        
            
                
                
            
        
        
        $('#shortyear_example1')
            .calendar({
                type: 'date',
                centuryBreak: 100
            })
        ;
Example 2: Shortyears 00-99 -> 1900-1999
      
          
              
              
          
      
      
      $('#shortyear_example2')
          .calendar({
              type: 'date',
              centuryBreak: 0
          })
      ;
Example 3: Shortyears 00-59 -> 3000-3059
          Shortyears 60-99 -> 2900-2959
      
          
              
              
          
      
      
      $('#shortyear_example3')
          .calendar({
              type: 'date',
              currentCentury: 3000
          })
      ;
Example 4:Shortyears 00-39 -> 1800-1839
          Shortyears 40-99 -> 1740-1799
      
          
              
              
          
      
      
      $('#shortyear_example4')
          .calendar({
              type: 'date',
              currentCentury: 1800,
              centuryBreak: 40
          })
      ;

Select adjacent days

현재 달 보기에서 이전·다음 달의 인접한 날들도 비활성화되는 대신 선택할 수 있게 할 수 있어요.

$('#adjacentdays_calendar')
        .calendar({
          selectAdjacentDays: true,
          type: 'date'
        })
      ;

Language

캘린더 언어를 필요에 맞게 변경할 수 있어요.

$('#french_calendar')
        .calendar({
          text: {
            days: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
            dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
            dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
            months: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Decembre'],
            monthsShort: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'],
            today: 'Aujourd\\'hui',
            now: 'Maintenant',
            am: 'AM',
            pm: 'PM',
            weekNo: 'Semaine'
          }
        })
      ;

Coupling

Button

캘린더는 버튼과 결합할 수 있어요.

Select date
      
      
      $('#button_calendar')
        .calendar()
      ;

Context

넘치는(overflowing) 컨테이너 안의 캘린더 팝업은 기본적으로 트리거 요소와 같은 넘치는 컨테이너 안에 배치되기 때문에 완전히 표시되지 못해요. 이를 해결하기 위해 context 설정을 사용해 (넘치지 않는) 부모 요소를 제공하면, 캘린더 팝업을 넘치는 컨테이너 밖으로 이동시켜 제대로 표시할 수 있어요.

다음 예제는 캘린더 입력을 넘치는 스크롤 세그먼트 안에 배치해요. context를 body로 정의하면 캘린더 팝업이 body의 직접 자식으로 렌더링되어, 그렇지 않으면 제한되는 세그먼트 위에 팝업이 제대로 겹쳐 표시돼요.

$('#context_calendar')
        .calendar({
            context: 'body'
        })
      ;

Disabling specific Days

Days of Week

매주 월요일, 수요일, 금요일을 선택에서 비활성화해요.

$('#disableddaysofweek_calendar')
        .calendar({
            disabledDaysOfWeek: [1,3,5]
        })
      ;

Single Dates

특정 개별 날짜를 비활성화할 수 있으며, 마우스 오버 시 팝업에 이유를 표시할 수도 있어요.

$('#disableddates_calendar')
        .calendar({
            initialDate: new Date('2018-12-01'),
            disabledDates: [{
                    date: new Date('2018-12-22'),
                    message: 'xmas gift shopping'
                },
                {
                    date: new Date('2018-12-25'),
                    message: 'Santa Clause is coming to town',
                    inverted: true,
                    variation: 'basic'
                },
                new Date('2018-12-31')  /* No Reason. Everybody knows why ;) */
            ]
        })
      ;

Hours

특정 날짜의 특정 시간을 비활성화할 수 있으며, 마우스 오버 시 팝업에 이유를 표시할 수도 있어요.

$('#disabledhours_calendar')
        .calendar({
            initialDate: new Date('2021-07-01'),
            formatter: {
                datetime: 'MMMM D, YYYY H:mm',
                time: 'H:mm',
                cellTime: 'H:mm'
            },
            disabledHours: [
              0, // Midnight will always be disabled
              {
              // Every Saturday and Sunday will be entirely disabled
                days: [0, 6],
                hours: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
                message: 'We dont work on Saturday and Sunday',
                inverted: true,
                variation: 'basic'
              },
              {
               // Friday afternoon will be disabled
                date: new Date('2021-07-02'),
                hours: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
                message: 'Sorry this afternoon we are closed !',
                inverted: true
              },
              {
               // All hours between 1 and 7 will be disabled every day
                hours: [1, 2, 3, 4, 5, 6, 7],
                message: 'We are sleeping !'
              },
              {
              // 12:00 and 13:00 will be disabled every day
                hours: [12, 13],
                message: 'Lunch time !'
              }
            ]
        })
      ;

Whole Months

특정 월의 모든 날짜를 비활성화할 수 있어요.

$('#disabledmonth_calendar')
          .calendar({
            type: 'date',
            initialDate: new Date('2020-12-01'),
            disabledDates: [{
                month: 11,     //Javascript months start from 0 (!)
                message: 'All days in December are booked out'
            },
            {
                month: [0,1],  //Javascript months start from 0 (!)
                message: 'No booking in January or February'
            }
          ]
          })
          ;

Whole Years

한 해의 모든 날짜를 비활성화할 수 있어요.

$('#disabledyear_calendar')
          .calendar({
            type: 'date',
            initialDate: new Date('2020-12-01'),
            disabledDates: [{
                year: 2020,
                message: '2020 is not available'
            },
            {
                year: [2022,2023],
                message: 'Years 2022 and 2023 are not available'
            }
            ]
          })
          ;

Enable only specific Dates

기본적으로 모든 날짜를 비활성화하고 특정 날짜만 활성화할 수 있어요.

$('#enableddates_calendar')
          .calendar({
            type: 'date',
            initialDate: new Date('2019-03-01'),
            enabledDates: [
                new Date('2019-03-05'),
                new Date('2019-03-10'),
                new Date('2019-03-20')
            ]
          })
          ;

Highlighting specific Days

Event Dates

특정 날짜를 이벤트로 표시해 다른 셀 스타일과 툴팁 메시지를 줄 수 있어요.

$('#eventdates_calendar').calendar({
          initialDate: new Date('2019-04-01'),
          eventDates: [
              {
                date: new Date('2019-04-21'),
                message: 'Show me in light purple',
                class: 'inverted purple',   // cellclass
                variation: 'purple'         // tooltip variation
              },{
                date: new Date('2019-04-22'),
                message: 'Show me in green',
                class: 'green',
                variation: 'green'
              }
          ]
      });
$('#eventdates2_calendar').calendar({
          initialDate: new Date('2019-04-01'),
          eventClass: 'inverted red',
          eventDates: [
              new Date('2019-04-20'), //no message tooltip
              {
                date: new Date('2019-04-21'),
                message: 'I got the default color (light red)'
              },{
                date: new Date('2019-04-22'),
                message: 'Me too'
              }
          ]
      });

Initializing

Initializing a calendar

캘린더는 기존 마크업 위에서 초기화돼요.

$('.ui.calendar')
        .calendar()
      ;

Behaviors

다음 모든 행동은 다음 구문을 사용해 호출할 수 있어요:

.ui.calendar').calendar('behavior', argumentOne, argumentTwo...);
  • refresh — 캘린더를 새로고침해요.
  • popup(arguments) — popup 모듈을 호출해요 (예: show를 전달하면 캘린더 팝업을 표시해요).
  • focus — 캘린더 입력에 포커스를 맞춰요.
  • blur — 캘린더 입력에서 포커스를 제거해요.
  • clear — 선택된 날짜를 지워요.
  • get date(format = '') — 선택된 날짜를 가져와요. format을 생략하면 JavaScript Date 객체를, 그렇지 않으면 형식화된 문자열을 반환해요.
  • set date(date, updateInput = true, fireChange = true) — 선택된 날짜를 설정해요. updateInput에 false를 전달하면 입력 업데이트를 비활성화해요. fireChange에 false를 전달하면 이 변경에 대한 onBeforeChange와 onChange 콜백을 비활성화해요.
  • get mode — 현재 선택 모드(year, month, day, hour, minute)를 가져와요.
  • set mode(mode) — 현재 선택 모드(year, month, day, hour, minute)를 설정해요.
  • get startDate(format = '') — 범위 선택의 시작 날짜를 가져와요. format을 생략하면 Date 객체를, 그렇지 않으면 문자열을 반환해요.
  • set startDate(date) — 범위 선택의 시작 날짜를 설정해요.
  • get endDate(format = '') — 범위 선택의 종료 날짜를 가져와요. format을 생략하면 Date 객체를, 그렇지 않으면 문자열을 반환해요.
  • set endDate(date) — 범위 선택의 종료 날짜를 설정해요.
  • get focusDate(format = '') — 현재 포커스된 날짜를 가져와요. format을 생략하면 Date 객체를, 그렇지 않으면 문자열을 반환해요.
  • set focusDate(date) — 현재 포커스된 날짜를 설정해요.
  • set minDate(date) — 선택 가능한 최소 날짜를 설정해요.
  • set maxDate(date) — 선택 가능한 최대 날짜를 설정해요.
  • destroy — 인스턴스를 파괴하고 모든 이벤트를 제거해요.

Calendar

Behavior

설정 기본값 설명
type datetime 피커 타입으로 datetime, date, time, month, year 중 하나예요.
firstDayOfWeek 0 첫 번째 일(day) 열의 요일이에요 (0 = 일요일).
constantHeight true 짧은 달에 행을 추가해 일 캘린더 높이를 일정하게(6행) 유지해요.
today false 캘린더 하단에 '오늘/지금' 버튼을 표시해요.
closable true 날짜/시간을 선택한 후 팝업을 닫아요.
monthFirst true 텍스트에서 날짜를 파싱/변환할 때 월을 일보다 먼저 배치해요.
touchReadonly false 터치 장치에서 입력을 readonly로 설정해요.
inline false 캘린더를 팝업 대신 인라인으로 생성해요.
showWeekNumbers false 왼쪽에 주 번호를 표시해요.
disabledDaysOfWeek [] 일주일 중 일부 요일을 선택에서 비활성화해요 (0=일요일, 1=월요일, ...).
disabledDates [] Date 객체 배열 또는 해당 날짜에 마우스를 올릴 때 팝업에 표시할 message를 가진 객체 {date: Date, message: string} 배열이에요.
disabledHours [] 0-23 정수 값 배열 또는 {days: intArray, hours: intArray, message: string} 객체 배열이에요.
enabledDates [] 선택에 활성화할 Date 객체 배열이에요. 그 외 모든 날짜는 비활성화돼요.
eventDates [] Date 객체 배열 또는 message와 셀용 개별 class를 가진 객체 {date: Date, message: string, class: string} 배열이에요.
eventClass blue eventDate 요소에 특정 class가 주어지지 않을 때 각 셀에 추가되는 기본 class예요.
on null 캘린더 팝업을 트리거하는 이벤트예요. focus, click, hover 중 하나 (기본 click).
initialDate null 날짜가 선택되지 않았을 때 처음 표시할 날짜예요 (null = 지금).
startMode false 시작 디스플레이 모드로 year, month, day, hour, minute (false = 'day')예요.
minDate null 선택할 수 있는 최소 날짜/시간이며, 그 이전은 비활성화돼요.
maxDate null 선택할 수 있는 최대 날짜/시간이며, 그 이후는 비활성화돼요.
disableYear false 연도 선택 모드를 비활성화해요.
disableMonth false 월 선택 모드를 비활성화해요.
disableMinute false 분 선택 모드를 비활성화해요.
formatInput true 입력 blur와 모듈 생성 시 입력 텍스트를 포맷해요.
startCalendar null 날짜 범위의 시작 날짜를 나타내는 또 다른 캘린더의 jQuery 객체 또는 선택자예요.
endCalendar null 날짜 범위의 종료 날짜를 나타내는 또 다른 캘린더의 jQuery 객체 또는 선택자예요.
multiMonth 1 day 모드일 때 여러 달을 표시해요.
monthOffset 0 multimonth > 1일 때 오프셋으로 현재 달을 배치해요.
minTimeGap 5 최소 시간 간격으로, 5, 10, 15, 20, 30만 가능해요.
centuryBreak 60 99까지의 단축 연도 시작값으로, 그 후엔 지난 세기에 속한다고 가정해요.
currentCentury 2000 2자리 연도(00부터 centuryBreak-1까지)에 더할 세기예요.
selectAdjacentDays false 이전·다음 달의 인접한 날들도 선택 가능하게 해요.
popupOptions { position: 'bottom left', lastResort: 'bottom left', prefer: 'opposite', hideOnScroll: false } 캘린더 팝업의 배치 옵션이에요.
text (요일/월/오늘/지금/AM/PM 문자열) 표시되는 텍스트를 정의해요.
formatter (토큰 문자열 또는 함수) 날짜나 팝업 텍스트 출력의 특정 부분을 서식화하는 커스터마이즈 가능한 메서드예요. cell 함수는 cellOptions에 {mode,adjacent,disabled,active,today} 값을 담은 객체를 받아요. 토큰 문자열 형식의 자세한 내용은 Custom Format 참고.
parser { date: function (text, settings) {} } 주어진 날짜를 파싱하는 커스터마이즈 가능한 메서드로, 날짜 객체를 반환해야 해요.
context false 캘린더 팝업이 연결될 DOM 선택자예요. 기본값(false)에서는 캘린더 팝업이 트리거 요소의 직접 자식으로 연결돼요.

Callbacks

콜백 컨텍스트 설명
onBeforeChange(date, text, mode) active content 캘린더 날짜가 변경되기 전에 호출돼요. return false;는 변경을 취소해요.
onChange(date, text, mode) active content 캘린더 날짜가 변경된 후에 호출돼요.
onShow active content 캘린더가 표시되기 전에 호출돼요. return false;는 표시를 막아요.
onVisible active content 캘린더가 표시될 때 호출돼요.
onHide active content 캘린더가 숨겨지기 전에 호출돼요. return false;는 숨김을 막아요.
onHidden active content 캘린더가 숨겨질 때 호출돼요.
onSelect(date,mode) active content 캘린더의 셀이 선택될 때 호출되어 값과 현재 모드를 제공해요. return false;는 선택을 막아요.

DOM Settings

DOM 설정은 이 모듈이 DOM과 어떻게 인터페이스할지 지정해요.

설정 기본값 설명
name Calendar 로그 문장에 사용되는 이름이에요.
namespace calendar 이벤트 네임스페이스예요.
selector { popup: '.ui.popup', input: 'input', activator: 'input', append: '.inline.field,.inline.fields' } 캘린더의 부모 노드가 append 선택자와 일치하면, 캘린더는 입력 필드에 앞에(prepend) 붙는 대신 뒤에(append) 붙어요.
className { calendar: 'calendar', active: 'active', popup: 'ui popup', grid: 'ui equal width grid', column: 'column', table: 'ui celled center aligned unstackable table', prev: 'prev link', next: 'next link', prevIcon: 'chevron left icon', nextIcon: 'chevron right icon', link: 'link', cell: 'link', disabledCell: 'disabled', weekCell: 'disabled', adjacentCell: 'adjacent', activeCell: 'active', rangeCell: 'range', focusCell: 'focus', todayCell: 'today', today: 'today link' } 요소 상태를 결정하는 데 사용되는 클래스 이름이에요.
regExp { dateWords: /[^A-Za-z\u00C0-\u024F]+/g, dateNumbers: /[^\d:]+/g } 날짜 파싱에 사용되는 정규식이에요.
metadata { date: 'date', focusDate: 'focusDate', startDate: 'startDate', endDate: 'endDate', mode: 'mode', monthOffset: 'monthOffset' } 캘린더가 사용하는 메타데이터 키예요.
silent false 모든 콘솔 출력을 조용히 만들어요.
debug false 콘솔에 디버그 출력을 보여줘요.
performance true 성능 메트릭과 함께 console.table 출력을 보여줘요.
verbose false 디버그 출력에 모든 내부 행동을 포함해요.
errors { popup: 'UI Popup, a required component is not included in this page', method: 'The method you called is not defined.' } 오류 메시지 설정이에요.

더 알아보기 (Learn more)

캘린더로 날짜와 시간 선택 UI를 다양하게 구성할 수 있어요. 날짜 범위 연동과 특정 일자 비활성화 같은 고급 기능을 활용해 보세요. 폼 안에서의 활용은 Form 문서도 함께 참고하세요.