-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Support for relative/pretty date formatting #79
Comments
This would be really nice and I think it is feasible. Needs further investigation. |
It could be a nice feature to replace the old relative formatting feature and make it more flexible. |
"Pretty" date formatting is an interesting feature to implement but I'm not sure the best way is to make some sort of resemble of difference() method we have already. I would to take a look around to other frameworks+languages in order to get the most convenient way to implement it. OPTION 1
where PrettyDateFormatWithTime
PrettyDateFormatNoTime
PrettyDateFormatTodayTimeOnly
PrettyDateLongRelativeTime
PrettyDateShortRelativeTime
|
I presume the last two lines in PrettyDateShortRelativeTime should be prefixed with a minus? |
Instead of having all kinds of different names, I prefer one general function with parameters for the units to format and the 'shortness' of the output string |
So something like the NSCalendarUnit (one or more to get granularity of the statement) and another param to get the short/long/medium style? |
However in order to get a reasonable behavior we should provide an easy to use formatting; while it great to have some sort of granularity of the interval (you would print 24 hours or 1 day) the most common way to format is 1 day. Customization is great but is also good to keep it simple. |
To keep it simple we could also do some fuzzy parametering e.g.
Thus we can issue for 25 hours:
|
Okay this is my proposal. COLLOQUIAL STYLE
We also have another style (name???) which works by using parameters we have specified above:
What do you think? |
Looks good to me! One remark though: following the path from #123 NOT to put redundant parameters in a function I would suggest two functions: // Takes the biggest unit of difference and the number of subsequent smaller units
func toRelativeString(fromDate: date, numberOfUnits: Int = 1, style: Y = .Medium)
// Takes the difference of the specified units
func toRelativeString(fromDate: date, units: NSCalendarUnits, style: Y = .Medium) I think more nuances are possible, but I suggest an agile approach: try fast and fail fast (if at all). |
I agree! However I don't understand params of these two functions:
So something like: // Colloquial output
func toRelativeString(fromDate: date, style: Y = .Medium)
// Standard output
func toRelativeString(fromDate: date, units: NSCalendarUnits, numberOfUnits: Int = 1 style: Y = .Medium) Am I missing something? |
Just added This is the logical behind this method:
|
I've also added .toComponentsStrings() method. func toComponentsStrings(refDate :DateInRegion = DateInRegion(), units :[NSCalendarUnit]? = nil, maxUnits cUnits :Int = 0, style :DateFormatterStyle = .Default) -> [String]?``` This method get differences in terms of specified units from a Supported units are:
|
Remarks: |
Okay; just a question: this is for English, are we sure we can remove safely singular form from types and make this assumption valid even for other languages? Otherwise we can simply make set the same value for both singular and plural and maintain the distinction inside the code. |
Not sure, but still I think three type of abbreviations is overkill in English, Dutch, German, French and Indonesian. Not sure about Italian ;-) |
BTW have you checked my suggestion in #65 with NSDateComponentFormatter? This seems to give you the names if the units automagically. |
Damn it seems the solution, I forgot that :| |
Have you looked at this?
We can provide a port of TTTTimeIntervalFormatter right now and replace it with NSDateComponentsFormatter when it will be fixed. What do you think? |
I am always in favour of using the native libraries. Can't we work around Besides we could use this for more than just time intervals
|
Another referece:
[EDITED] |
Added support for NSDateComponentsFormatter. It's a shared instance in each called thread and it's wrapped in FormatterStyle. |
Is there the way to custom time unit when call the function like
toRelativeString
? , and then return the relative representation with custom time unit.For example if the time unit is
day
, a relative representation of the date by comparing2015-11-15 00:00
to the2015-11-16 02:00
should be returned1 day
, and if the time unit ishour
, should be returned26 hours
.The text was updated successfully, but these errors were encountered: