Skip to content

Add timestamp to generated docs #2465

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

Merged
merged 1 commit into from
May 20, 2017
Merged

Add timestamp to generated docs #2465

merged 1 commit into from
May 20, 2017

Conversation

Varunram
Copy link
Contributor

@Varunram Varunram commented May 18, 2017

Intended as a solution to #2115.
Contrary to what was proposed back in the issue, appending at the end of the file seemed to be an easier alternative than reading from the file and rewriting - I'm new here, so please correct me if I'm wrong.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@Varunram
Copy link
Contributor Author

Signed the CLA!

@@ -311,6 +315,16 @@ case class Site(val root: JFile, val projectTitle: String, val documentation: Ma
* defaults, the user-defined one will take precedence.
*/
val layouts: Map[String, Layout] = {

val cal = Calendar.getInstance()
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend against using java.util.Date/Calendar/SimpleDataFormat. These APIs have many pitfalls and are not thread-safe. Java 8 introduced a new set of APIs to deal with date and time in the java.time package that should be used instead. To get the current time you should use LocalDateTime.now: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#now--

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much! Doing it right away!

val amOrPm = new SimpleDateFormat("a").format(today)
val x = "<!-- generated on " + cal.get(Calendar.DATE) + "/"+ (cal.get(Calendar.MONTH)+1)+ "/"+cal.get(Calendar.YEAR) + " " + currentHour + ":" + currentMinute + ":" + amOrPm + "-->"
var loc = root.getAbsolutePath.toString + "/.." + "/doc-tool/resources/_layouts/main.html"
scala.tools.nsc.io.File(loc).appendAll(x)
Copy link
Member

Choose a reason for hiding this comment

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

This is an alias for dotty.tools.io.File, use that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks again and Sorry. Regarding the failing tests, would it be better if I add a check for loc over here?

@Varunram
Copy link
Contributor Author

Varunram commented May 18, 2017

CLA signed already, I dunno what the problem is...

Copy link
Contributor

@felixmulder felixmulder left a comment

Choose a reason for hiding this comment

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

I would not solve this by injecting the time into every main.html file. Some people might not even be using said template.

This should be solved by using the infrastructure that templating provides. I.e:

<!-- generated on: {{ page.date | date: '%B %d, %Y' }} -->

It may be such that it is not set by default in page, and should if not exists be set to the current time (for posts it should be set in the preamble).

Regarding the signing, I can see that you have indeed signed. A rebase should fix this.

@Varunram
Copy link
Contributor Author

Varunram commented May 19, 2017

Noticed this just now, sorry! Would a tacky fix along the lines of case class PageInfo(url: String, date: String = (LocalDateTime.now().getDayOfMonth() + "/"+ ... in DefaultParams.scala be acceptable?

@felixmulder
Copy link
Contributor

@Varunram - we want to support people in doing something like:

{{ "2017-10-16" | date: '%B %d, %Y' }}

Therefore it might be better to fill in the correct date in DefaultParams.scala and use that if there wasn't a date already defined in the preamble.

@Varunram
Copy link
Contributor Author

Varunram commented May 20, 2017

Pushed back irrelevant commits and did the requested changes. Thanks @felixmulder for helping me out 😄

@felixmulder felixmulder merged commit d8955ce into scala:master May 20, 2017
@felixmulder
Copy link
Contributor

LGTM, thanks @Varunram !

@Varunram Varunram deleted the branch1 branch May 20, 2017 09:44
Varunram added a commit to Varunram/dotty that referenced this pull request May 30, 2017
Varunram added a commit to Varunram/dotty that referenced this pull request Jun 28, 2017
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.

4 participants