Skip to content

Commit

Permalink
Use DateTimeResolution/DateResolution enums instead of string for Dat…
Browse files Browse the repository at this point in the history
…eFieldDefinitionBuilder resolution
  • Loading branch information
eschleb committed Sep 16, 2024
1 parent b4c7da8 commit cd01c41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import info.magnolia.ui.field.DateFieldDefinition;
import info.magnolia.ui.field.TextFieldDefinition;

import javax.annotation.Nullable;
import java.util.Optional;

import javax.annotation.Nullable;

import com.vaadin.shared.ui.datefield.DateResolution;
import com.vaadin.shared.ui.datefield.DateTimeResolution;

/**
* builds a {@link DateFieldDefinition}
* @see <a href="https://docs.magnolia-cms.com/product-docs/6.2/Developing/Templating/Dialog-definition/Field-definition/List-of-fields/Date-field.html">magnolia Docs - Date field </a>
Expand Down Expand Up @@ -53,11 +56,19 @@ public DateFieldDefinitionBuilder timeFormat(final String timeFormat) {
return self();
}

public DateFieldDefinitionBuilder resolution(final String resolution) {
private DateFieldDefinitionBuilder resolution(final String resolution) {
this.resolution = resolution;
return self();
}

public DateFieldDefinitionBuilder resolution(final DateTimeResolution resolution) {
return resolution(resolution.name());
}

public DateFieldDefinitionBuilder resolution(final DateResolution resolution) {
return resolution(resolution.name());
}

public DateFieldDefinition build(final String name) {
final DateFieldDefinition definition = new DateFieldDefinition();
super.populate(definition, name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import com.merkle.oss.magnolia.definition.builder.AbstractFieldDefinitionBuilderTestCase;
import com.vaadin.shared.ui.datefield.DateTimeResolution;

import info.magnolia.ui.field.DateFieldDefinition;
import org.junit.jupiter.api.Test;

Expand All @@ -16,11 +18,11 @@ void testBuilder() {
.timeFormat("timeFormat")
.time(true)
.inISO8061Format(true)
.resolution("minute")
.resolution(DateTimeResolution.MINUTE)
.build("date");
assertEquals("dateFormat", definition.getDateFormat());
assertEquals("timeFormat", definition.getTimeFormat());
assertEquals("minute", definition.getResolution());
assertEquals("MINUTE", definition.getResolution());
assertTrue(definition.isTime());
assertTrue(definition.isInISO8061Format());

Expand Down

0 comments on commit cd01c41

Please sign in to comment.