-
Notifications
You must be signed in to change notification settings - Fork 3
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
Rewrite the library in kotlin #8
Conversation
// If we are using the equinox calculation method, or if we are within the dates the | ||
// calendar was used (regardless of the selected calculation method), use the equinox | ||
// calculation method. | ||
val result: FrenchRevolutionaryCalendarDate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use
val result = when {
calculationMethod == CalculationMethod.EQUINOX || gregorianDate.after(frenchEraYearOne) && gregorianDate.before(frenchEraEnd) -> getDateEquinox(gregorianDate)
...
private fun getDateEquinox(gregorianDate: Calendar): FrenchRevolutionaryCalendarDate { | ||
|
||
val gyear = gregorianDate.get(Calendar.YEAR) | ||
val gAutumnEquinox = getAutumnEquinox(gyear) ?: throw IllegalArgumentException("Date not supported: " + gregorianDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Date not supported: $gregorianDate"
val gAutumnEquinox = getAutumnEquinox(gyear) ?: throw IllegalArgumentException("Date not supported: " + gregorianDate) | ||
|
||
// Determine the first day of the French year. | ||
var g1stVendemiaire : Calendar? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var g1stVendemiaire = gAutumnEquinox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// last year | ||
if (gregorianDate < gAutumnEquinox) { | ||
g1stVendemiaire = getAutumnEquinox(gyear - 1) | ||
if (g1stVendemiaire == null) throw IllegalArgumentException("Date not supported: " + gregorianDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Date not supported: $gregorianDate"
fakeFrenchDate.timeInMillis = fakeFrenchTimestamp | ||
|
||
// Extract the year, and day in year from the French date. | ||
val frenchYear = fakeFrenchDate.get(Calendar.YEAR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of .get(Calendar.YEAR)
you can use [Calendar.YEAR]
- not sure if it's really clearer
/** | ||
* @return a number from 1 to 10. | ||
*/ | ||
val dayInWeek: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a getter (computed every time)? Could be calculated only once:
val dayInWeek = (dayOfMonth - 1) % 10 + 1
val weekInMonth: Int | ||
get() = (dayOfMonth - 1) / 10 + 1 | ||
|
||
val objectType: DailyObjectType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe val objectType = when {
etc.
get() { | ||
val type = objectType | ||
return FrenchRevolutionaryCalendarLabels.getInstance(locale).getDailyObjectTypeName(type) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val objectTypeName = FrenchRevolutionaryCalendarLabels.getInstance(locale).getDailyObjectTypeName(objectType)
?
|
||
* @author calvarez | ||
*/ | ||
abstract class FrenchRevolutionaryCalendarLabels internal constructor(private val weekdays: Array<String>, private val months: Array<String>, private val daysOfYear: Array<Array<String>>, private val dailyObjectTypes: Array<String>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the visibility of this one. Should it be hidden from the users of the lib?
var result: FrenchRevolutionaryCalendarLabels? = instances[language] | ||
if (result != null) return result | ||
if (Locale.ENGLISH.language == language) result = FrenchRevolutionaryCalendarLabelsEN() | ||
else if ("es" == language) result = FrenchRevolutionaryCalendarLabelsES() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a when
* from 0 to 9, the minute is from 0 to 99, and the second is from | ||
* 0 to 99. | ||
*/ | ||
fun getFrenchTime(gtime: Calendar): Triple<Int, Int, Int> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't return a Triple
, it breaks the api
* Specify sourceDirectory so cobertura can show covered lines * Split a huge method in EquinoxDates into smaller methods
Set the kotlin-maven-plugin phase to process-sources
7aeb327
to
7f55332
Compare
No description provided.