Skip to content

Commit

Permalink
convertion when substracting dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Dec 28, 2020
1 parent 755090e commit c87f1a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
keywords = ["time", "calendar", "netcdf", "climate and forecast conventions", "oceanography", "meteorology", "climatology", "opendap"]
license = "MIT"
desc = "Julia library for decoding time units conforming to the Climate and Forecasting (CF) netCDF conventions"
version = "0.1.0"
version = "0.1.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
9 changes: 9 additions & 0 deletions src/CFTime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ pattern given in the `format` string.
end


-(dt1::Union{DateTimeStandard,DateTimeJulian,DateTimeProlepticGregorian},
dt2::DateTime) = DateTime(dt1) - DateTime(dt2)

-(dt1::Union{DateTimeStandard,DateTimeJulian,DateTimeProlepticGregorian},
dt2::Union{DateTimeStandard,DateTimeJulian,DateTimeProlepticGregorian}) = DateTime(dt1) - DateTime(dt2)

-(dt1::DateTime,
dt2::Union{DateTimeStandard,DateTimeJulian,DateTimeProlepticGregorian}) = DateTime(dt1) - DateTime(dt2)



"""
Expand Down
6 changes: 6 additions & 0 deletions test/test_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,9 @@ dt = @test_logs (:warn,r"Time zones are currently not supported.*") begin
end
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00+00:00",DateTime360Day)
@test data == data2


# convertion when substracting dates
@test DateTimeStandard(2000,1,1) - DateTime(2000,1,1) == Dates.Day(0)
@test DateTime(2000,1,1) - DateTimeStandard(2000,1,1) == Dates.Day(0)
@test DateTimeStandard(2000,1,1) - DateTimeProlepticGregorian(2000,1,1) == Dates.Day(0)

2 comments on commit c87f1a5

@Alexander-Barth
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/27018

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" c87f1a5861e258e2188fad9363cca7522ac93aaf
git push origin v0.1.1

Please sign in to comment.