score:3
Accepted answer
I was able to do this with a simple for comprehension and the java.time.LocalDate
and java.time.Year
:
import java.time.{LocalDate, Year}
def allDaysForYear(year: String): List[(String, String, String)] = {
val daysInYear = if(Year.of(year.toInt).isLeap) 366 else 365
for {
day <- (1 to daysInYear).toList
localDate = LocalDate.ofYearDay(year.toInt, day)
month = localDate.getMonthValue
dayOfMonth = localDate.getDayOfMonth
} yield (year, month.toString, dayOfMonth.toString)
}
score:0
Use Lamma Date
Date(2015, 1, 1) to Date(2015, 12, 131) foreach println
Date(2015,1,1)
Date(2015,1,2)
Date(2015,1,3)
Date(2015,1,4)
Source: stackoverflow.com
Related Query
- Scala - Get all months and days for a given year
- Get all dates as list for given month and year in scala
- Scala - Get list of days and months for a selected year
- In scala 3, how to get a given Factory for both something like Iteratable and an Array?
- How to get all request parameters in Play and Scala
- Scala reflection, finding and instantiating all classes with a given annotation
- Scala 2.10 reflection: Why do I get the same type "List()" for the list and list element?
- Scala SortedMap : Get all keys greater than a given key
- Scala runtime reflections get all the members of a specific type even for inner classes
- regex Scala for replacing all but white space and specified target
- how to get all instances of a given class/trait with scala reflect? all refs to a given instance?
- Get date out of year and day of year from a value - Scala
- Scala Get List of last 12 months from given month
- How to get year and week number aligned for a date
- How to get all possible partitions for a list in Scala
- How to get all the children and sub-children of XML file using Scala
- How to get number of days between two given dates in Scala
- First and Last Date of Current and Previous Quarter For a Given Date in Scala
- Scala - Spark : Operate on all the columns of DF at once and create a case-class for each column efficiently
- Scala Kafka Spark: Get all kafkaConsumer endOffSets and assign it to a val
- groupBy Id and get multiple records for multiple columns in scala
- groupBy and get count of records for multiple columns in scala
- Scala Spark Convert Dataframe and get all Unique IDs and its type from each row
- How to generate getters and setters for all field of scala in Intellij
- Is there a way for a Scala base class to get informed when all the derived classes have been constructed? (guess not)
- How to get all S3ObjectSummary from an S3 bucket using scala and the aws-java-sdk?
- Not able to apply AggregateByKey using Spark Scala to get (id, total,( max, min)) for given input(id, value)
- How to get the first date and last date using current month and year on scala
- Simple and concise HTTP client library for Scala
- How the get the classOf for a scala object type
More Query from same tag
- How to determine the output type of a function (type)?
- Why is generic parameter not required to be set explicitly?
- Scala returning object type in if/else statements
- Error 500 for basic REST service in Lift Scala MongoDB while createRecord
- Abstract types versus type parameters
- WS - Setting string in request headers creates a list
- How to invoke a main method in a nested object?
- Vector product using map and reduce in scala
- How to fix "implement traits member" error?
- Logging elastic4s client
- Is it possible to have compiler specific code sections in scala
- Java.util.Calendar.add() function in scala
- @Repeat Form Helper with complex object - Play Framework
- How to change SBT's rules on generating URLs for Maven repositories?
- How would you write a method that takes an optional inner function
- java.lang.ClassCastException: [B cannot be cast to java.lang.String while parsing json[String,String]
- Slick projection with multiple MappedColumnType
- Scala abstract types in classes within objects
- How to connect to Oracle 11g database using Slick via Play 2/TypeSafe Activator?
- In Scala how to group elements in list with reverse dimension?
- Scala Co-Variant Bounded Types
- Scala List - extract 'Date' and 'Adj close' values (columns)
- https4s how to make a POST call to a REST web service
- Avoid a .toString call in REPL?
- How to get the posted "id=1&id=2" in action, in play2?
- Sbt downloads the dependency but IntelliJ cannot resolve its usages
- HSQLDB Embedded in Jar throwing
- PlayFramework NoClassDefFoundError: jdk/nashorn/api/scripting/NashornScriptEngineFactory
- Passing a Shapeless Extensible Record to a Function
- transform dataset into case class via (wrapped) encoders