Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia Programming Projects

You're reading from   Julia Programming Projects Learn Julia 1.x by building apps for data analysis, visualization, machine learning, and the web

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher Packt
ISBN-13 9781788292740
Length 500 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Adrian Salceanu Adrian Salceanu
Author Profile Icon Adrian Salceanu
Adrian Salceanu
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Julia Programming FREE CHAPTER 2. Creating Our First Julia App 3. Setting Up the Wiki Game 4. Building the Wiki Game Web Crawler 5. Adding a Web UI for the Wiki Game 6. Implementing Recommender Systems with Julia 7. Machine Learning for Recommender Systems 8. Leveraging Unsupervised Learning Techniques 9. Working with Dates, Times, and Time Series 10. Time Series Forecasting 11. Creating Julia Packages 12. Other Books You May Enjoy

Rounding of dates


There might be situations where we have a date/time and a need to compute the previous, or next complete time interval, for example, the next hour, or the previous day. The Dates API exposes a few methods for rounding Date and DateTime objects—floor, ceil, and time. They are quite intuitive and very powerful:

julia> now() 
2018-11-08T21:13:20.605 

# round down to the nearest hour 
julia> floor(now(), Hour) 
2018-11-08T21:00:00 

# or to the nearest 30 minutes increment 
julia> floor(now(), Minute(30))  
2018-11-08T21:00:00 

# it also works with dates  
julia> floor(today(), Month) # today() is the 8th of Nov 2018 
2018-11-01

The ceil function works similarly, but instead of rounding down, it rounds up. As for the round function, it will round up or down, depending on whichever is the closest value:

julia> round(today(), Month) 
2018-11-01 # today is the 11th so beginning of month is closer 
 
julia> round(today() + Day(10), Month) 
2018-12-01 # end of month...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime