Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Mar 11, 2024
1 parent 3889b2d commit 3de9545
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
41 changes: 41 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,44 @@ DateTimeStandard(2000,01,01) < DateTimeStandard(2000,01,02)

Time ranges can be constructed using a start date, end date and a time increment, for example: `DateTimeStandard(2000,1,1):Dates.Day(1):DateTimeStandard(2000,12,31)`


## Rounding


```julia
using CFTime: DateTimeStandard
using Dates: DateTime
dt = DateTimeStandard(24*60*60*1000*1000 + 123,"microsecond since 2000-01-01")
round(DateTime,dt)
# output

2000-01-02T00:00:00
```



```julia
using Dates: DateTime, Second
using CFTime: DateTimeStandard

dt = DateTimeStandard(24*60*60,"second since 2000-01-01")

floor(dt+Second(9),Second(10)) == dt
# output

true

ceil(dt+Second(9),Second(10)) == dt + Second(10)
# output

true

round(dt+Second(9),Second(10)) == dt + Second(10)
# output

true
```



9 changes: 4 additions & 5 deletions test/test_rounding.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

using Test
using Dates: DateTime, Day, Microsecond, Second
using Dates: DateTime, Day, Second
using CFTime: DateTimeStandard


# rounding
dt = DateTimeStandard(24*60*60*1000*1000 + 123,"microsecond since 2000-01-01")
@test round(DateTime,dt) == DateTime(2000,1,2)

dt = DateTimeStandard(24*60*60+8,"second since 2000-01-01")
p = Second(10)
dt = DateTimeStandard(24*60*60,"second since 2000-01-01")

@test floor(dt,p) == DateTimeStandard(24*60*60,"second since 2000-01-01")
@test round(dt,p) == DateTimeStandard(24*60*60+10,"second since 2000-01-01")
@test floor(dt+Second(9),Second(10)) == dt
@test round(dt+Second(9),Second(10)) == dt + Second(10)

0 comments on commit 3de9545

Please sign in to comment.