Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISO Support for Time Grains #1739

Closed
wants to merge 11 commits into from
Closed

ISO Support for Time Grains #1739

wants to merge 11 commits into from

Conversation

AvaniMakwana
Copy link
Collaborator

Resolves #1545

Description

ISO Support for time grains

Motivation and Context

How Has This Been Tested?

Unit tests included

Screenshots (if appropriate):

License

I confirm that this contribution is made under an Apache 2.0 license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* Time Grain class for Day.
*/
public class Day extends Date {
public class Day extends Date implements TimeGrainFormatter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a Day an instance of TimeGrainFormatter? Can we remove this association?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeGrainFormatter has common logic that will be used by all the Grains for ISO handling. So instead of creating a Util class with that supporting method, we went the implement/interface route.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe DaySerde can implement it instead of Day.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are calling a static method on the interface. Technically nothing needs to implement it. DaySerde would make more sense though if we do.

}
date = new Day(FORMATTER.parse(FORMATTER.format(val)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we still need the else case? Otherwise this line stomps on line 36.

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* Time Grain class for Day.
*/
public class Day extends Date {
public class Day extends Date implements TimeGrainFormatter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are calling a static method on the interface. Technically nothing needs to implement it. DaySerde would make more sense though if we do.

/** Interface for ISO timegrain Support. */
public interface TimeGrainFormatter {

String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "yyyy-MM-dd'T'HH:mm:ss'Z'", single quotes around Z


static Timestamp formatDateString(SimpleDateFormat formatter, String val) throws ParseException {
try {
return new Timestamp(formatter.parse((String) val).getTime());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to cast val here as a String.

@Override
public Minute deserialize(Object val) {

Minute date = null;

try {
if (val instanceof String) {
date = new Minute(new Timestamp(FORMATTER.parse((String) val).getTime()));
date = new Minute(FORMATTER.parse(FORMATTER.format(TimeGrainFormatter.formatDateString(FORMATTER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look correct - why do we need to parse and then format, and then parse again? It looks like we are doing unnecessary work here.

@Test
public void testISODateString() throws ParseException {
String dateInString = "2020-01-01T00:00:00-0500";
Day expectedDate = new Day(formatter.parse(dateInString));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be isoFormatter instead of formatter. Also might be a good idea to update dateInString to have different hour minutes.

@aklish aklish deleted the iso-date-format branch October 29, 2021 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ISO Date Formats in Time Grains
3 participants