Primer::LocalTime에서 이전하기
Primer::LocalTime에서 이전하기 (Moving Away From Primer::LocalTime)
이 가이드는 이제 deprecated된 Primer::LocalTime에서 최신 Primer::Beta::RelativeTime 컴포넌트로 업그레이드하는 방법을 보여줍니다.
출처: 문서
본문
이 가이드는 이제 deprecated된 Primer::LocalTime에서 최신 Primer::Beta::RelativeTime 컴포넌트로 업그레이드하는 방법을 보여줍니다.
마이그레이션 예시 (A Migration Example)
LocalTime 컴포넌트의 가장 흔한 사용 사례는 몇 가지 사소한 변경만으로 마이그레이션할 수 있습니다.
예를 들어, LocalTime이 이렇게 설정되어 있었다면:
<%= Primer::LocalTime(datetime: Time.now, initial_text: Time.now.iso8601) %>
initial_text를 제거하고 빈 prefix를 설정하며 threshold: "PT0S"를 추가해 마이그레이션할 수 있습니다.
<%= Primer::Beta::RelativeTime(datetime: Time.now, prefix: "", threshold: "PT0S") %>
RelativeTime 컴포넌트는 기본적으로 iso8601 형식을 사용하며 직접 지정할 필요가 없습니다.
threshold 값은 RelativeTime 컴포넌트에 상대 시간 설명 대신 절대 날짜/시간을 표시하라고 알려주는 ISO-8601 "duration"입니다. PT0S 예는 0초 전부터 절대 시간 표시로 전환하라고 말합니다. 실질적으로는 항상 절대 시간을 표시한다는 뜻입니다. LocalTime 컴포넌트에서는 PT0S가 기본 threshold였습니다. 그러나 RelativeTime 컴포넌트는 기본적으로 P30D를 사용하므로, 항상 datetime을 표시하려면 0으로 만들어 주어야 합니다.
인자 (Arguments)
다음 인자들이 LocalTime과 RelativeTime 사이에서 다릅니다:
| From Primer::LocalTime | To Primer::Beta::RelativeTime | Notes |
|---|---|---|
| initial_text | n/a | No longer used. |
| n/a | tense | Which tense to use. One of :auto, :future, or :past. |
| n/a | prefix | What to prefix the relative time display with. |
| n/a | threshold | The threshold, in ISO-8601 'durations' format, at which relative time displays become absolute. |
| n/a | precision | The precision elapsed time should display. One of nil, :day, :hour, :minute, :month, :second, or :year. |
| n/a | format | The format the display should take. One of :auto, :elapsed, or :micro. |
| n/a | lang | The language to use. |
| n/a | title | Provide a custom title to the element. |
나머지 인자들은 동일하게 유지됩니다.
완전한 설명과 예시는 다음 문서를 참고하세요.
Primer::Beta::RelativeTimecomponentPrimer::Beta::RelativeTimeLookbook examples
← Back to development docs
더 알아보기 (Learn more)
Primer::Beta::RelativeTime컴포넌트 문서에서tense,precision,format,threshold인자를 확인해 보세요.- 상대 시간 대신 항상 절대 datetime을 표시하려면
threshold: "PT0S"를 사용해 보세요. prefix인자로 상대 시간 표시 앞에 텍스트를 붙여 보세요.