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

What does this do? #1

Closed
barrywe7 opened this issue Jan 12, 2018 · 1 comment
Closed

What does this do? #1

barrywe7 opened this issue Jan 12, 2018 · 1 comment

Comments

@barrywe7
Copy link

The extension in date to return a calendar object looks quite complicated.

var Date.calendar: Calendar
    get() = Calendar.getInstance().apply { time = this@calendar }
    set(value) {
        time = value.timeInMillis
    }

Isn't that the equivalent of this?

val Date.calendar: Calendar
    get() = Calendar.getInstance().apply { timeInMillis = this@calendar.time }
@vanshg
Copy link
Owner

vanshg commented Jan 14, 2018

Nope it wouldn't be -- your proposed change is a val instead of var, therefore it doesn't have a setter and would not be able to be reassigned (aka, setting a new Calendar on the Date)

@vanshg vanshg closed this as completed May 23, 2019
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

No branches or pull requests

2 participants