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

Rewrite the library in kotlin #8

Closed
wants to merge 9 commits into from
Closed

Conversation

caarmen
Copy link
Owner

@caarmen caarmen commented May 21, 2017

No description provided.

// 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?
Copy link
Contributor

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)
Copy link
Contributor

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?
Copy link
Contributor

Choose a reason for hiding this comment

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

var g1stVendemiaire = gAutumnEquinox

Copy link
Owner Author

Choose a reason for hiding this comment

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

compileerror

// last year
if (gregorianDate < gAutumnEquinox) {
g1stVendemiaire = getAutumnEquinox(gyear - 1)
if (g1stVendemiaire == null) throw IllegalArgumentException("Date not supported: " + gregorianDate)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
}
Copy link
Contributor

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>) {
Copy link
Contributor

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()
Copy link
Contributor

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> {
Copy link
Owner Author

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

@caarmen caarmen changed the base branch from master to dependency-updates May 24, 2017 16:47
@caarmen caarmen closed this May 24, 2017
@caarmen caarmen deleted the kotlin branch July 22, 2017 19:15
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.

None yet

2 participants