Skip to content

Commit 45edbec

Browse files
Use parseTime
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent 42e684a commit 45edbec

File tree

5 files changed

+5
-25
lines changed

5 files changed

+5
-25
lines changed

api/src/main/java/io/cloudevents/rw/CloudEventAttributesWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ default CloudEventAttributesWriter withAttribute(String name, @Nullable URI valu
6060
* @return self
6161
*/
6262
default CloudEventAttributesWriter withAttribute(String name, @Nullable OffsetDateTime value) throws CloudEventRWException {
63-
return withAttribute(name, value == null ? null : Time.writeTime(value));
63+
return withAttribute(name, value == null ? null : Time.writeTime(name, value));
6464
}
6565

6666
}

core/src/main/java/io/cloudevents/core/v03/CloudEventBuilder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.net.URI;
2626
import java.net.URISyntaxException;
2727
import java.time.OffsetDateTime;
28-
import java.time.format.DateTimeParseException;
2928

3029
/**
3130
* CloudEvent V0.3 builder.
@@ -167,11 +166,7 @@ public CloudEventBuilder withAttribute(String name, String value) throws CloudEv
167166
withSubject(value);
168167
return this;
169168
case "time":
170-
try {
171-
withTime(Time.parseTime(value));
172-
} catch (DateTimeParseException e) {
173-
throw CloudEventRWException.newInvalidAttributeValue("time", value, e);
174-
}
169+
withTime(Time.parseTime("time", value));
175170
return this;
176171
}
177172
throw CloudEventRWException.newInvalidAttributeName(name);

core/src/main/java/io/cloudevents/core/v03/V1ToV03AttributesConverter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.net.URI;
2525
import java.net.URISyntaxException;
2626
import java.time.OffsetDateTime;
27-
import java.time.format.DateTimeParseException;
2827

2928
class V1ToV03AttributesConverter implements CloudEventAttributesWriter {
3029

@@ -64,11 +63,7 @@ public V1ToV03AttributesConverter withAttribute(String name, String value) throw
6463
builder.withSubject(value);
6564
return this;
6665
case "time":
67-
try {
68-
builder.withTime(Time.parseTime(value));
69-
} catch (DateTimeParseException e) {
70-
throw CloudEventRWException.newInvalidAttributeValue("time", value, e);
71-
}
66+
builder.withTime(Time.parseTime("time", value));
7267
return this;
7368
}
7469
throw CloudEventRWException.newInvalidAttributeName(name);

core/src/main/java/io/cloudevents/core/v1/CloudEventBuilder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.net.URI;
2828
import java.net.URISyntaxException;
2929
import java.time.OffsetDateTime;
30-
import java.time.format.DateTimeParseException;
3130

3231
/**
3332
* CloudEvent V1.0 builder.
@@ -161,11 +160,7 @@ public CloudEventBuilder withAttribute(String name, String value) throws CloudEv
161160
withSubject(value);
162161
return this;
163162
case "time":
164-
try {
165-
withTime(Time.parseTime(value));
166-
} catch (DateTimeParseException e) {
167-
throw CloudEventRWException.newInvalidAttributeValue("time", value, e);
168-
}
163+
withTime(Time.parseTime("time", value));
169164
return this;
170165
}
171166
throw CloudEventRWException.newInvalidAttributeName(name);

core/src/main/java/io/cloudevents/core/v1/V03ToV1AttributesConverter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.net.URI;
2525
import java.net.URISyntaxException;
2626
import java.time.OffsetDateTime;
27-
import java.time.format.DateTimeParseException;
2827

2928
class V03ToV1AttributesConverter implements CloudEventAttributesWriter {
3029

@@ -64,11 +63,7 @@ public V03ToV1AttributesConverter withAttribute(String name, String value) throw
6463
builder.withSubject(value);
6564
return this;
6665
case "time":
67-
try {
68-
builder.withTime(Time.parseTime(value));
69-
} catch (DateTimeParseException e) {
70-
throw CloudEventRWException.newInvalidAttributeValue("time", value, e);
71-
}
66+
builder.withTime(Time.parseTime("time", value));
7267
return this;
7368
}
7469
throw CloudEventRWException.newInvalidAttributeName(name);

0 commit comments

Comments
 (0)