Print object properties using member function in Kotlin - kotlin

I am really confused with the task I received from the Jetbrains Academy.
There is a calendar object which has day, month and year properties. Somebody has created a selectCurrentDay() member function that sets the object's properties to the current day. There is no need to type the date manually anymore because we have the selectCurrentDay() function!
Initially, the calendar shows a random date. Implement the current date printing: select it and print the day, the month and the year split by a space.
Output example:
21 12 2021
What i did was:
val calendar = createCalendar()
calendar.selectCurrentDay()
print("{$calendar.day} ${calendar.month} ${calendar.year}")
However my answer is rejected. What do they want me to implement?

print("${calendar.day} ${calendar.month} ${calendar.year}")

Related

kotlin OffsetDateTime format of pattern

I am try to convert a offsetdatetime to a specific format, but i have a problem
OffsetDateTime.parse("2021-12-27T15:49:08Z")
.format(DateTimeFormatter.ofPattern("EEE dd MMM YYYY, h:mm:ss"))
and it print one year more
lun. 27 dic. 2022, 3:49:08
what is the reason?
thanks a lot
This is because you're specifying the pattern YYYY for the year.
According to the docs for java.time.format.DateTimeFormatter, a pattern of one or more Ys means ‘week-based year’.
That's different from the usual ‘year-of-era’, which you get from a pattern of one or more lower-case ys.
The difference is explained in this question. Basically, if the year starts in the middle of a week, it treats that entire week as falling either in the previous year or the following year.
The exact calculation will depend indirectly upon the locale, as that controls which day the week starts on. (I don't fully understand all the details, but I think it's mediated by the WeekFields class. However it works, it can cause the last few days of 2021 to be treated as part of 2022, as this question demonstrates.)
In any case, it looks like your real problem is using a week-based year number when you just want the normal calendar year! So, simply change your pattern to "EEE dd MMM yyyy, h:mm:ss", and you should get the expected result:
lun. 27 dic. 2021, 3:49:08

Kotlin convert FileTime to day, month, year

Problem:
I have got a directory of files, which have a creation date.
What I am trying to reach is to get the value of the creation date day, month and year.
However, I am working with a FileTime.
I was expecting to be able to call a GetMonth method or such.
Unfortunately, this is not possible, does someone know a nice solution to get the day/month/year of a FileTime?
What have I tried:
I have tried to convert this to the Date type. This is possible, but here are the day, month and year methods deprecated.
I have tried to use to get the milliseconds of the FileTime, but this did not feel like a pretty solution.
Final question:
How do I get the day, month and year of a FileTime?
Thanks in forward.
FileTime ➙ Instant ➙ ZonedDateTime
I'm assuming that you're using Java 8 or later. You must convert the FileTime to an Instant. You can then apply a ZoneId to the Instant to get a ZonedDateTime object for the time zone you want the date in. The below code converts the FileTime to date in India time.
val zonedTime = fileTime.toInstant().atZone(ZoneId.of("Asia/Kolkata"))
println(zonedTime.year)
println(zonedTime.monthValue)
println(zonedTime.dayOfMonth)

Pandas DateOffset, Periods and tslib.period_ordinal

I am trying to understand the relationship in Pandas between DateOffset, Periods and tslib.period_ordinal.
When I create a new Period using: pd.Period("2013-12", freq="Q-DEC"),
I see that "Q-DEC" is resolved to a base of 2000, this base in addition to the components of a datetime parsed from the date string are passed to tslib.period_ordinal which returns 175.
Where if anywhere does DateOffset come in? What is the meaning of the base? Are there any docs on period_ordinal?
I am looking to add some new Frequencies, such as 52–53-week fiscal year (see: https://github.com/pydata/pandas/issues/4511) and was wondering where to start.

ms-access built in function Month(number)

I Have been playing with variations of the Month... function in access query builder. I am having trouble building a date value from an expression. I am looking to create my own date that will be behind the scenes to perform some filtering and other tasks. My problem is that I cant seem to get the Month(number) function to do what I think it should be doing. Here is a summary of what I am looking for.
5/31/2012
Through something like this
DateSerial(Year(Date()),Month(5),Day(31))
Also
DateSerial(Year(Date()),Month("5"),Day("31"))
When I try these as an experssion the return is
1/30/2012
Im sure I am misunderstanding the structure. Please educate me.
DateSerial requires three integers, year, month, day:
DateSerial(1992,5,2)
02/05/1992 ''Euro locale
Year(Date()) returns an integer, so you can substitute:
DateSerial(Year(Date()),5,31)
Interestingly, the zeroth day is the last day of the previous month:
DateSerial(2012,12,0)=30/11/2012
-- http://office.microsoft.com/en-ie/access-help/HV080206953.aspx
As an aside, do not forget that all dates are numbers.
Month(5) will equal 1, but Month(41263)=12 !
Also
?month(100)
4
?Year(100)
1900

How to get work days and absence days of an employee (resource)?

How do I get the work and absence days of an employee with VBA from MS-Project? (an employee is a ressource)
Some additional infos:
I know how to get tasks
Dim ts as Tasks
Set ts = ActiveProject.Tasks
and I know how to get ressources from my project file:
Dim rs as Resources
Set rs = ActiveProject.ressources
but I do not find a (trivial) way to get work and absence days from this variables.
You need to look at the Resource object to find the working and non-working days:
ActiveProject.Resources.Item(1).Calendar
In this trivial example we're picking up the first resource in the project and pulling out it's associated Calendar.
A resource calendar will have a base calendar from which it inherits:
...Calendar.BaseCalendar
and both the resource calendar and the base calendar define working days, working weeks and exceptions. Exceptions are typically how periods of absence are defined... i.e. they are exceptions to the normal pattern of work:
...Calendar.WorkWeeks
...Calendar.WeekDays
...Calendar.Exceptions
The answer already provided information to get one started, but does not actually answer the question. As stated, "Exceptions" are indeed how periods of absence are defined but to determine if a given date is an absence day from the exception object will take a not-insignificant amout of parsing code.
It would be a lot simpler and much more reliable to determine workdays empirically. Assuming variable "cal" is the calendar in question declare a variable (say "d") of type long then loop from some start date to some end date-1 and determine if that date is a workday or not using Application.datedifference (d, d+1, cal). A non work day will yield 0.