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

RssItem now is a Date instead of a String #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eagskunst
Copy link

As for issue #8 and in terms for making it more simple to devs to filter Items by date, I make the necessary modifications to now have a Date inside the RssItem.

Added also a Log message in order to inform the existence of an unparseable date.

I tried to make changes in dev, but I couldn't be able to resolve the conflicts in merge.

@faruktoptas
Copy link
Owner

Hi @eagskunst The date format is not the same for all RSS contents. It changes depends on the content. So date will be null if the format is other than EEE, dd MMM yyyy HH:mm:ss. You can find different contents here: https://github.com/faruktoptas/RetrofitRssConverterFactory/tree/dev/library/src/androidTest/assets/rss

@eagskunst
Copy link
Author

eagskunst commented Dec 15, 2018

@faruktoptas What about if there's a builder where you could add the formatter?

@faruktoptas
Copy link
Owner

@eagskunst The formatter should change depending on the RSS content. An interceptor should be better instead of the builder. You can manipulate the RssItem after it is created by intercepting. So you can change each field's value or type.

@eagskunst
Copy link
Author

@faruktoptas I'm not familiar with the concept of interceptors (how they're made). Could you help me a little bit so I can do it?

@faruktoptas
Copy link
Owner

Currently, it is not implemented. But I'm planning to add it to be more flexible. You can follow the steps below:

  • Extend RssItem with a date object instead of String. Something like MyRssItem
  • When Retrofit service successfully returns the RssFeed object. Iterate through RssItem list and convert them to MyRssItem with formatted date objects.

@eagskunst
Copy link
Author

eagskunst commented Dec 16, 2018

In my research for the ways to test all patterns of SimpleDateFormatter, I found this library,
POJava DateTime. They site is down, but with web archive you could see the docs. I tested the dates with the sample app and with the custom test you make, all passed @faruktoptas.

@eagskunst
Copy link
Author

@faruktoptas Don't forge to give me some feedback 😅

try{
DateTime.parse(it, DateTimeConfig.getGlobalDefault()).toDate()
}catch (e: Exception){
Log.i(XMLParser::class.java.simpleName, "Careful! ${e}")
Copy link
Owner

Choose a reason for hiding this comment

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

If parsing fails date will be null. But the user could parse it somehow.

@faruktoptas
Copy link
Owner

@eagskunst sorry for late reply :)

Trying to parse the date string could cause date to be null. But it should not be. I will add a formatter that works with RSS urls. So user can add their own formatters. It would be more flexible

@eagskunst
Copy link
Author

@faruktoptas What about using a formatter with the RSS specification?

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.

2 participants