Skip to content

Applying a date formatter to a date field #4322

Closed Answered by simenbrekken-visma
brandonpittman asked this question in Q&A
Discussion options

You must be logged in to vote

I just came across this issue myself where we support multiple locales but dates are always displayed in ISO-8601 format. A somewhat hacky way to accomplish this is by mapping DateSegments[] to a different list of segments:

const state = useDateFieldState(...);
const segments = getDateFieldSegments(state.segments);


function getDateFieldSegments(segments: DateSegment[]): DateSegment[] {
    const daySegment = segments.find((segment) => segment.type === 'day');
    const monthSegment = segments.find((segment) => segment.type === 'month');
    const yearSegment = segments.find((segment) => segment.type === 'year');
    const separatorSegment = segments.find(
        (segment) => segment.type 

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@brandonpittman
Comment options

@snowystinger
Comment options

@brandonpittman
Comment options

@simenbrekken-visma
Comment options

Answer selected by brandonpittman
@RIP21
Comment options

@simenbrekken-visma
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants