code
stringlengths 3
10M
| language
stringclasses 31
values |
---|---|
import std.stdio;
import std.format;
import std.algorithm;
const fileName = "day2.txt";
void main() {
auto file = File(fileName);
writefln("paper needed: %d", file.byLine()
.map!readSize
.map!getPaper
.sum());
file.seek(0);
writefln("ribbon needed: %d", file.byLine()
.map!readSize
.map!getRibbon
.sum()
);
}
auto readSize(char[] text) {
uint[3] size;
formattedRead(text, "%dx%dx%d", &size[0], &size[1], &size[2]);
return size;
}
auto getPaper(uint[3] s) {
auto sides = [s[0]*s[1], s[0]*s[2], s[1]*s[2]];
return sum(map!"a*2"(sides)) + reduce!"min(a, b)"(sides);
}
auto getRibbon(uint[3] size) {
auto maxSide = size.reduce!"max(a, b)";
auto maxIndex = size.dup.countUntil(maxSide);
return 2*size.dup.remove(maxIndex).sum() + reduce!"a * b"(size);
}
| D |
/Users/natasilva/repositories/algoritmos/atividade-7/target/rls/debug/deps/atividade_7-1ab8ca7b33c13fb3.rmeta: src/main.rs
/Users/natasilva/repositories/algoritmos/atividade-7/target/rls/debug/deps/atividade_7-1ab8ca7b33c13fb3.d: src/main.rs
src/main.rs:
| D |
E: c70, c11, c83, c6, c73, c52, c16, c58, c44, c87, c90, c14, c66, c50, c82, c98, c28, c27, c3, c33, c88, c24, c79, c64, c59, c57, c96, c7, c15, c92, c38, c25, c39, c1, c78, c84, c72, c42, c48, c35, c23, c71, c18, c77, c85, c51, c26, c68, c95, c99, c31, c61, c55, c97, c75, c86.
p0(E,E)
c70,c11
c66,c88
c7,c15
c1,c25
c72,c11
c87,c35
c64,c77
c48,c26
c11,c92
.
p4(E,E)
c83,c6
c44,c6
c87,c90
c90,c44
c73,c66
c27,c83
c87,c6
c16,c6
c90,c6
c6,c44
c64,c16
c64,c44
c6,c6
c64,c87
c1,c44
c87,c44
c11,c64
c42,c48
c35,c16
c16,c44
c66,c6
c48,c87
c6,c16
c87,c16
c16,c1
c1,c16
c79,c35
c48,c44
c66,c87
c83,c44
c1,c6
c68,c83
c48,c16
c87,c87
c44,c87
c44,c16
c66,c16
c1,c87
c44,c44
c35,c44
c90,c16
.
p6(E,E)
c73,c52
c16,c58
c44,c3
c52,c96
c6,c96
c87,c75
.
p3(E,E)
c16,c14
c98,c98
c33,c33
c25,c25
c98,c39
c70,c70
c35,c68
c31,c61
c92,c92
c3,c72
.
p5(E,E)
c50,c82
c98,c79
.
p9(E,E)
c98,c28
c92,c16
c55,c16
c87,c88
.
p7(E,E)
c24,c79
c95,c28
.
p10(E,E)
c64,c11
c59,c57
c87,c66
c71,c18
c87,c48
c99,c25
c87,c87
c87,c16
c66,c73
c87,c1
c72,c11
c6,c97
c87,c90
c48,c42
c87,c44
.
p8(E,E)
c7,c15
c87,c35
c72,c11
.
p2(E,E)
c16,c38
c3,c88
c33,c66
c78,c84
c85,c51
c16,c27
c16,c57
c25,c1
.
p1(E,E)
c23,c35
c27,c78
c38,c78
c78,c16
c87,c57
c57,c78
c87,c23
c84,c27
c86,c79
.
| D |
/Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Intermediates/WanAndroid_IOS.build/Debug-iphonesimulator/WanAndroid_IOS.build/Objects-normal/x86_64/UIAlertExtension.o : /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/HotTabVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/homeVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/scrollerVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/alterVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/ProjectVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/imageT/ImagetVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/TextVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/MyTabViewVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/AppDelegate.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableViewCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/UIAlertExtension.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/Common.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ButtonT/button.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/CollectionHeader.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MyNavigationController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/oneViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MainViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/twoViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/other/otherViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/FeedBackView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/SnapKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/module.modulemap /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Intermediates/WanAndroid_IOS.build/Debug-iphonesimulator/WanAndroid_IOS.build/Objects-normal/x86_64/UIAlertExtension~partial.swiftmodule : /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/HotTabVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/homeVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/scrollerVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/alterVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/ProjectVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/imageT/ImagetVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/TextVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/MyTabViewVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/AppDelegate.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableViewCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/UIAlertExtension.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/Common.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ButtonT/button.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/CollectionHeader.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MyNavigationController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/oneViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MainViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/twoViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/other/otherViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/FeedBackView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/SnapKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/module.modulemap /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Intermediates/WanAndroid_IOS.build/Debug-iphonesimulator/WanAndroid_IOS.build/Objects-normal/x86_64/UIAlertExtension~partial.swiftdoc : /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/HotTabVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/homeVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/scrollerVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/alterVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/ProjectVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/imageT/ImagetVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/TextVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/MyTabViewVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/AppDelegate.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableViewCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/UIAlertExtension.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/Common.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ButtonT/button.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/CollectionHeader.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MyNavigationController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/oneViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MainViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/twoViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/other/otherViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/FeedBackView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/SnapKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/module.modulemap /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Intermediates/WanAndroid_IOS.build/Debug-iphonesimulator/WanAndroid_IOS.build/Objects-normal/x86_64/UIAlertExtension~partial.swiftsourceinfo : /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/HotTabVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/homeVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/scrollerVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/alterVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/ProjectVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/imageT/ImagetVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/TextVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/tabVC/MyTabViewVC.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/AppDelegate.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/collectionCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/TableViewCell.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/alterT/UIAlertExtension.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/Common.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ButtonT/button.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/ListT/CollectionHeader.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MyNavigationController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/oneViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/MainViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/scrollerT/twoViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/other/otherViewController.swift /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/WanAndroid_IOS/home/LableText/FeedBackView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/SnapKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-umbrella.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Headers/Alamofire-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Headers/SnapKit-Swift.h /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework/Modules/module.modulemap /Users/GuoYanjun/Desktop/TestDemo/WanAndroid_IOS/Build/Products/Debug-iphonesimulator/SnapKit/SnapKit.framework/Modules/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
| D |
/++
$(LUCKY Regular expressions) are a commonly used method of pattern matching
on strings, with $(I regex) being a catchy word for a pattern in this domain
specific language. Typical problems usually solved by regular expressions
include validation of user input and the ubiquitous find $(AMP) replace
in text processing utilities.
$(SECTION Synopsis)
---
import std.regex;
import std.stdio;
void main()
{
// Print out all possible dd/mm/yy(yy) dates found in user input.
auto r = regex(r"\b[0-9][0-9]?/[0-9][0-9]?/[0-9][0-9](?:[0-9][0-9])?\b");
foreach(line; stdin.byLine)
{
// matchAll() returns a range that can be iterated
// to get all subsequent matches.
foreach(c; matchAll(line, r))
writeln(c.hit);
}
}
...
// Create a static regex at compile-time, which contains fast native code.
auto ctr = ctRegex!(`^.*/([^/]+)/?$`);
// It works just like a normal regex:
auto c2 = matchFirst("foo/bar", ctr); // First match found here, if any
assert(!c2.empty); // Be sure to check if there is a match before examining contents!
assert(c2[1] == "bar"); // Captures is a range of submatches: 0 = full match.
...
// The result of the $(D matchAll) is directly testable with if/assert/while.
// e.g. test if a string consists of letters:
assert(matchFirst("Letter", `^\p{L}+$`));
---
$(SECTION Syntax and general information)
The general usage guideline is to keep regex complexity on the side of simplicity,
as its capabilities reside in purely character-level manipulation.
As such it's ill-suited for tasks involving higher level invariants
like matching an integer number $(U bounded) in an [a,b] interval.
Checks of this sort of are better addressed by additional post-processing.
The basic syntax shouldn't surprise experienced users of regular expressions.
For an introduction to $(D std.regex) see a
$(WEB dlang.org/regular-expression.html, short tour) of the module API
and its abilities.
There are other web resources on regular expressions to help newcomers,
and a good $(WEB www.regular-expressions.info, reference with tutorial)
can easily be found.
This library uses a remarkably common ECMAScript syntax flavor
with the following extensions:
$(UL
$(LI Named subexpressions, with Python syntax. )
$(LI Unicode properties such as Scripts, Blocks and common binary properties e.g Alphabetic, White_Space, Hex_Digit etc.)
$(LI Arbitrary length and complexity lookbehind, including lookahead in lookbehind and vise-versa.)
)
$(REG_START Pattern syntax )
$(I std.regex operates on codepoint level,
'character' in this table denotes a single Unicode codepoint.)
$(REG_TABLE
$(REG_TITLE Pattern element, Semantics )
$(REG_TITLE Atoms, Match single characters )
$(REG_ROW any character except [{|*+?()^$, Matches the character itself. )
$(REG_ROW ., In single line mode matches any character.
Otherwise it matches any character except '\n' and '\r'. )
$(REG_ROW [class], Matches a single character
that belongs to this character class. )
$(REG_ROW [^class], Matches a single character that
does $(U not) belong to this character class.)
$(REG_ROW \cC, Matches the control character corresponding to letter C)
$(REG_ROW \xXX, Matches a character with hexadecimal value of XX. )
$(REG_ROW \uXXXX, Matches a character with hexadecimal value of XXXX. )
$(REG_ROW \U00YYYYYY, Matches a character with hexadecimal value of YYYYYY. )
$(REG_ROW \f, Matches a formfeed character. )
$(REG_ROW \n, Matches a linefeed character. )
$(REG_ROW \r, Matches a carriage return character. )
$(REG_ROW \t, Matches a tab character. )
$(REG_ROW \v, Matches a vertical tab character. )
$(REG_ROW \d, Matches any Unicode digit. )
$(REG_ROW \D, Matches any character except Unicode digits. )
$(REG_ROW \w, Matches any word character (note: this includes numbers).)
$(REG_ROW \W, Matches any non-word character.)
$(REG_ROW \s, Matches whitespace, same as \p{White_Space}.)
$(REG_ROW \S, Matches any character except those recognized as $(I \s ). )
$(REG_ROW \\, Matches \ character. )
$(REG_ROW \c where c is one of [|*+?(), Matches the character c itself. )
$(REG_ROW \p{PropertyName}, Matches a character that belongs
to the Unicode PropertyName set.
Single letter abbreviations can be used without surrounding {,}. )
$(REG_ROW \P{PropertyName}, Matches a character that does not belong
to the Unicode PropertyName set.
Single letter abbreviations can be used without surrounding {,}. )
$(REG_ROW \p{InBasicLatin}, Matches any character that is part of
the BasicLatin Unicode $(U block).)
$(REG_ROW \P{InBasicLatin}, Matches any character except ones in
the BasicLatin Unicode $(U block).)
$(REG_ROW \p{Cyrillic}, Matches any character that is part of
Cyrillic $(U script).)
$(REG_ROW \P{Cyrillic}, Matches any character except ones in
Cyrillic $(U script).)
$(REG_TITLE Quantifiers, Specify repetition of other elements)
$(REG_ROW *, Matches previous character/subexpression 0 or more times.
Greedy version - tries as many times as possible.)
$(REG_ROW *?, Matches previous character/subexpression 0 or more times.
Lazy version - stops as early as possible.)
$(REG_ROW +, Matches previous character/subexpression 1 or more times.
Greedy version - tries as many times as possible.)
$(REG_ROW +?, Matches previous character/subexpression 1 or more times.
Lazy version - stops as early as possible.)
$(REG_ROW {n}, Matches previous character/subexpression exactly n times. )
$(REG_ROW {n$(COMMA)}, Matches previous character/subexpression n times or more.
Greedy version - tries as many times as possible. )
$(REG_ROW {n$(COMMA)}?, Matches previous character/subexpression n times or more.
Lazy version - stops as early as possible.)
$(REG_ROW {n$(COMMA)m}, Matches previous character/subexpression n to m times.
Greedy version - tries as many times as possible, but no more than m times. )
$(REG_ROW {n$(COMMA)m}?, Matches previous character/subexpression n to m times.
Lazy version - stops as early as possible, but no less then n times.)
$(REG_TITLE Other, Subexpressions $(AMP) alternations )
$(REG_ROW (regex), Matches subexpression regex,
saving matched portion of text for later retrieval. )
$(REG_ROW (?:regex), Matches subexpression regex,
$(U not) saving matched portion of text. Useful to speed up matching. )
$(REG_ROW A|B, Matches subexpression A, or failing that, matches B. )
$(REG_ROW (?P$(LT)name$(GT)regex), Matches named subexpression
regex labeling it with name 'name'.
When referring to a matched portion of text,
names work like aliases in addition to direct numbers.
)
$(REG_TITLE Assertions, Match position rather than character )
$(REG_ROW ^, Matches at the begining of input or line (in multiline mode).)
$(REG_ROW $, Matches at the end of input or line (in multiline mode). )
$(REG_ROW \b, Matches at word boundary. )
$(REG_ROW \B, Matches when $(U not) at word boundary. )
$(REG_ROW (?=regex), Zero-width lookahead assertion.
Matches at a point where the subexpression
regex could be matched starting from the current position.
)
$(REG_ROW (?!regex), Zero-width negative lookahead assertion.
Matches at a point where the subexpression
regex could $(U not) be matched starting from the current position.
)
$(REG_ROW (?<=regex), Zero-width lookbehind assertion. Matches at a point
where the subexpression regex could be matched ending
at the current position (matching goes backwards).
)
$(REG_ROW (?<!regex), Zero-width negative lookbehind assertion.
Matches at a point where the subexpression regex could $(U not)
be matched ending at the current position (matching goes backwards).
)
)
$(REG_START Character classes )
$(REG_TABLE
$(REG_TITLE Pattern element, Semantics )
$(REG_ROW Any atom, Has the same meaning as outside of a character class.)
$(REG_ROW a-z, Includes characters a, b, c, ..., z. )
$(REG_ROW [a||b]$(COMMA) [a--b]$(COMMA) [a~~b]$(COMMA) [a$(AMP)$(AMP)b],
Where a, b are arbitrary classes, means union, set difference,
symmetric set difference, and intersection respectively.
$(I Any sequence of character class elements implicitly forms a union.) )
)
$(REG_START Regex flags )
$(REG_TABLE
$(REG_TITLE Flag, Semantics )
$(REG_ROW g, Global regex, repeat over the whole input. )
$(REG_ROW i, Case insensitive matching. )
$(REG_ROW m, Multi-line mode, match ^, $ on start and end line separators
as well as start and end of input.)
$(REG_ROW s, Single-line mode, makes . match '\n' and '\r' as well. )
$(REG_ROW x, Free-form syntax, ignores whitespace in pattern,
useful for formatting complex regular expressions. )
)
$(SECTION Unicode support)
This library provides full Level 1 support* according to
$(WEB unicode.org/reports/tr18/, UTS 18). Specifically:
$(UL
$(LI 1.1 Hex notation via any of \uxxxx, \U00YYYYYY, \xZZ.)
$(LI 1.2 Unicode properties.)
$(LI 1.3 Character classes with set operations.)
$(LI 1.4 Word boundaries use the full set of "word" characters.)
$(LI 1.5 Using simple casefolding to match case
insensitively across the full range of codepoints.)
$(LI 1.6 Respecting line breaks as any of
\u000A | \u000B | \u000C | \u000D | \u0085 | \u2028 | \u2029 | \u000D\u000A.)
$(LI 1.7 Operating on codepoint level.)
)
*With exception of point 1.1.1, as of yet, normalization of input
is expected to be enforced by user.
$(SECTION Replace format string)
A set of functions in this module that do the substitution rely
on a simple format to guide the process. In particular the table below
applies to the $(D format) argument of
$(LREF replaceFirst) and $(LREF replaceAll).
The format string can reference parts of match using the following notation.
$(REG_TABLE
$(REG_TITLE Format specifier, Replaced by )
$(REG_ROW $$(AMP), the whole match. )
$(REG_ROW $(DOLLAR)$(BACKTICK), part of input $(I preceding) the match. )
$(REG_ROW $', part of input $(I following) the match. )
$(REG_ROW $$, '$' character. )
$(REG_ROW \c $(COMMA) where c is any character, the character c itself. )
$(REG_ROW \\, '\' character. )
$(REG_ROW $(DOLLAR)1 .. $(DOLLAR)99, submatch number 1 to 99 respectively. )
)
$(SECTION Slicing and zero memory allocations orientation)
All matches returned by pattern matching functionality in this library
are slices of the original input. The notable exception is the $(D replace)
family of functions that generate a new string from the input.
In cases where producing the replacement is the ultimate goal
$(LREF replaceFirstInto) and $(LREF replaceAllInto) could come in handy
as functions that avoid allocations even for replacement.
Copyright: Copyright Dmitry Olshansky, 2011-
License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Dmitry Olshansky,
API and utility constructs are modeled after the original $(D std.regex)
by Walter Bright and Andrei Alexandrescu.
Source: $(PHOBOSSRC std/_regex/_package.d)
Macros:
REG_ROW = $(TR $(TD $(I $1 )) $(TD $+) )
REG_TITLE = $(TR $(TD $(B $1)) $(TD $(B $2)) )
REG_TABLE = <table border="1" cellspacing="0" cellpadding="5" > $0 </table>
REG_START = <h3><div align="center"> $0 </div></h3>
SECTION = <h3><a id="$1">$0</a></h3>
S_LINK = <a href="#$1">$+</a>
+/
module std.regex;
import std.regex.internal.ir;
import std.regex.internal.thompson; //TODO: get rid of this dependency
import std.exception, std.traits, std.range;
/++
$(D Regex) object holds regular expression pattern in compiled form.
Instances of this object are constructed via calls to $(D regex).
This is an intended form for caching and storage of frequently
used regular expressions.
Example:
Test if this object doesn't contain any compiled pattern.
---
Regex!char r;
assert(r.empty);
r = regex(""); // Note: "" is a valid regex pattern.
assert(!r.empty);
---
Getting a range of all the named captures in the regex.
----
import std.range;
import std.algorithm;
auto re = regex(`(?P<name>\w+) = (?P<var>\d+)`);
auto nc = re.namedCaptures;
static assert(isRandomAccessRange!(typeof(nc)));
assert(!nc.empty);
assert(nc.length == 2);
assert(nc.equal(["name", "var"]));
assert(nc[0] == "name");
assert(nc[1..$].equal(["var"]));
----
+/
public alias Regex(Char) = std.regex.internal.ir.Regex!(Char);
/++
A $(D StaticRegex) is $(D Regex) object that contains D code specially
generated at compile-time to speed up matching.
Implicitly convertible to normal $(D Regex),
however doing so will result in losing this additional capability.
+/
public alias StaticRegex(Char) = std.regex.internal.ir.StaticRegex!(Char);
/++
Compile regular expression pattern for the later execution.
Returns: $(D Regex) object that works on inputs having
the same character width as $(D pattern).
Params:
pattern = Regular expression
flags = The _attributes (g, i, m and x accepted)
Throws: $(D RegexException) if there were any errors during compilation.
+/
@trusted public auto regex(S)(S pattern, const(char)[] flags="")
if(isSomeString!(S))
{
import std.functional;
enum cacheSize = 8; //TODO: invent nice interface to control regex caching
if(__ctfe)
return regexImpl(pattern, flags);
return memoize!(regexImpl!S, cacheSize)(pattern, flags);
}
public auto regexImpl(S)(S pattern, const(char)[] flags="")
if(isSomeString!(S))
{
import std.regex.internal.parser;
auto parser = Parser!(Unqual!(typeof(pattern)))(pattern, flags);
auto r = parser.program;
return r;
}
template ctRegexImpl(alias pattern, string flags=[])
{
import std.regex.internal.parser, std.regex.internal.backtracking;
enum r = regex(pattern, flags);
alias Char = BasicElementOf!(typeof(pattern));
enum source = ctGenRegExCode(r);
alias Matcher = BacktrackingMatcher!(true);
@trusted bool func(ref Matcher!Char matcher)
{
debug(std_regex_ctr) pragma(msg, source);
mixin(source);
}
enum nr = StaticRegex!Char(r, &func);
}
/++
Compile regular expression using CTFE
and generate optimized native machine code for matching it.
Returns: StaticRegex object for faster matching.
Params:
pattern = Regular expression
flags = The _attributes (g, i, m and x accepted)
+/
public enum ctRegex(alias pattern, alias flags=[]) = ctRegexImpl!(pattern, flags).nr;
enum isRegexFor(RegEx, R) = is(RegEx == Regex!(BasicElementOf!R))
|| is(RegEx == StaticRegex!(BasicElementOf!R));
/++
$(D Captures) object contains submatches captured during a call
to $(D match) or iteration over $(D RegexMatch) range.
First element of range is the whole match.
+/
@trusted public struct Captures(R, DIndex = size_t)
if(isSomeString!R)
{//@trusted because of union inside
alias DataIndex = DIndex;
alias String = R;
private:
import std.conv;
R _input;
bool _empty;
enum smallString = 3;
union
{
Group!DataIndex[] big_matches;
Group!DataIndex[smallString] small_matches;
}
uint _f, _b;
uint _ngroup;
NamedGroup[] _names;
this()(R input, uint ngroups, NamedGroup[] named)
{
_input = input;
_ngroup = ngroups;
_names = named;
newMatches();
_b = _ngroup;
_f = 0;
}
this(alias Engine)(ref RegexMatch!(R,Engine) rmatch)
{
_input = rmatch._input;
_ngroup = rmatch._engine.re.ngroup;
_names = rmatch._engine.re.dict;
newMatches();
_b = _ngroup;
_f = 0;
}
@property Group!DataIndex[] matches()
{
return _ngroup > smallString ? big_matches : small_matches[0 .. _ngroup];
}
void newMatches()
{
if(_ngroup > smallString)
big_matches = new Group!DataIndex[_ngroup];
}
public:
///Slice of input prior to the match.
@property R pre()
{
return _empty ? _input[] : _input[0 .. matches[0].begin];
}
///Slice of input immediately after the match.
@property R post()
{
return _empty ? _input[] : _input[matches[0].end .. $];
}
///Slice of matched portion of input.
@property R hit()
{
assert(!_empty);
return _input[matches[0].begin .. matches[0].end];
}
///Range interface.
@property R front()
{
assert(!empty);
return _input[matches[_f].begin .. matches[_f].end];
}
///ditto
@property R back()
{
assert(!empty);
return _input[matches[_b - 1].begin .. matches[_b - 1].end];
}
///ditto
void popFront()
{
assert(!empty);
++_f;
}
///ditto
void popBack()
{
assert(!empty);
--_b;
}
///ditto
@property bool empty() const { return _empty || _f >= _b; }
///ditto
R opIndex()(size_t i) /*const*/ //@@@BUG@@@
{
assert(_f + i < _b,text("requested submatch number ", i," is out of range"));
assert(matches[_f + i].begin <= matches[_f + i].end,
text("wrong match: ", matches[_f + i].begin, "..", matches[_f + i].end));
return _input[matches[_f + i].begin .. matches[_f + i].end];
}
/++
Explicit cast to bool.
Useful as a shorthand for !(x.empty) in if and assert statements.
---
import std.regex;
assert(!matchFirst("nothing", "something"));
---
+/
@safe bool opCast(T:bool)() const nothrow { return !empty; }
/++
Lookup named submatch.
---
import std.regex;
import std.range;
auto c = matchFirst("a = 42;", regex(`(?P<var>\w+)\s*=\s*(?P<value>\d+);`));
assert(c["var"] == "a");
assert(c["value"] == "42");
popFrontN(c, 2);
//named groups are unaffected by range primitives
assert(c["var"] =="a");
assert(c.front == "42");
----
+/
R opIndex(String)(String i) /*const*/ //@@@BUG@@@
if(isSomeString!String)
{
size_t index = lookupNamedGroup(_names, i);
return _input[matches[index].begin .. matches[index].end];
}
///Number of matches in this object.
@property size_t length() const { return _empty ? 0 : _b - _f; }
///A hook for compatibility with original std.regex.
@property ref captures(){ return this; }
}
///
unittest
{
auto c = matchFirst("@abc#", regex(`(\w)(\w)(\w)`));
assert(c.pre == "@"); // Part of input preceding match
assert(c.post == "#"); // Immediately after match
assert(c.hit == c[0] && c.hit == "abc"); // The whole match
assert(c[2] == "b");
assert(c.front == "abc");
c.popFront();
assert(c.front == "a");
assert(c.back == "c");
c.popBack();
assert(c.back == "b");
popFrontN(c, 2);
assert(c.empty);
assert(!matchFirst("nothing", "something"));
}
/++
A regex engine state, as returned by $(D match) family of functions.
Effectively it's a forward range of Captures!R, produced
by lazily searching for matches in a given input.
$(D alias Engine) specifies an engine type to use during matching,
and is automatically deduced in a call to $(D match)/$(D bmatch).
+/
@trusted public struct RegexMatch(R, alias Engine = ThompsonMatcher)
if(isSomeString!R)
{
private:
import core.stdc.stdlib;
alias Char = BasicElementOf!R;
alias EngineType = Engine!Char;
EngineType _engine;
R _input;
Captures!(R,EngineType.DataIndex) _captures;
void[] _memory;//is ref-counted
this(RegEx)(R input, RegEx prog)
{
_input = input;
immutable size = EngineType.initialMemory(prog)+size_t.sizeof;
_memory = (enforce(malloc(size), "malloc failed")[0..size]);
scope(failure) free(_memory.ptr);
*cast(size_t*)_memory.ptr = 1;
_engine = EngineType(prog, Input!Char(input), _memory[size_t.sizeof..$]);
static if(is(RegEx == StaticRegex!(BasicElementOf!R)))
_engine.nativeFn = prog.nativeFn;
_captures = Captures!(R,EngineType.DataIndex)(this);
_captures._empty = !_engine.match(_captures.matches);
debug(std_regex_allocation) writefln("RefCount (ctor): %x %d", _memory.ptr, counter);
}
@property ref size_t counter(){ return *cast(size_t*)_memory.ptr; }
public:
this(this)
{
if(_memory.ptr)
{
++counter;
debug(std_regex_allocation) writefln("RefCount (postblit): %x %d",
_memory.ptr, *cast(size_t*)_memory.ptr);
}
}
~this()
{
if(_memory.ptr && --*cast(size_t*)_memory.ptr == 0)
{
debug(std_regex_allocation) writefln("RefCount (dtor): %x %d",
_memory.ptr, *cast(size_t*)_memory.ptr);
free(cast(void*)_memory.ptr);
}
}
///Shorthands for front.pre, front.post, front.hit.
@property R pre()
{
return _captures.pre;
}
///ditto
@property R post()
{
return _captures.post;
}
///ditto
@property R hit()
{
return _captures.hit;
}
/++
Functionality for processing subsequent matches of global regexes via range interface:
---
import std.regex;
auto m = matchAll("Hello, world!", regex(`\w+`));
assert(m.front.hit == "Hello");
m.popFront();
assert(m.front.hit == "world");
m.popFront();
assert(m.empty);
---
+/
@property auto front()
{
return _captures;
}
///ditto
void popFront()
{
if(counter != 1)
{//do cow magic first
counter--;//we abandon this reference
immutable size = EngineType.initialMemory(_engine.re)+size_t.sizeof;
_memory = (enforce(malloc(size), "malloc failed")[0..size]);
_engine = _engine.dupTo(_memory[size_t.sizeof..size]);
counter = 1;//points to new chunk
}
//previous _captures can have escaped references from Capture object
_captures.newMatches();
_captures._empty = !_engine.match(_captures.matches);
}
///ditto
auto save(){ return this; }
///Test if this match object is empty.
@property bool empty(){ return _captures._empty; }
///Same as !(x.empty), provided for its convenience in conditional statements.
T opCast(T:bool)(){ return !empty; }
/// Same as .front, provided for compatibility with original std.regex.
@property auto captures(){ return _captures; }
}
private @trusted auto matchOnce(alias Engine, RegEx, R)(R input, RegEx re)
{
import core.stdc.stdlib;
alias Char = BasicElementOf!R;
alias EngineType = Engine!Char;
size_t size = EngineType.initialMemory(re);
void[] memory = enforce(malloc(size), "malloc failed")[0..size];
scope(exit) free(memory.ptr);
auto captures = Captures!(R, EngineType.DataIndex)(input, re.ngroup, re.dict);
auto engine = EngineType(re, Input!Char(input), memory);
static if(is(RegEx == StaticRegex!(BasicElementOf!R)))
engine.nativeFn = re.nativeFn;
captures._empty = !engine.match(captures.matches);
return captures;
}
private auto matchMany(alias Engine, RegEx, R)(R input, RegEx re)
{
re.flags |= RegexOption.global;
return RegexMatch!(R, Engine)(input, re);
}
unittest
{
//sanity checks for new API
auto re = regex("abc");
assert(!"abc".matchOnce!(ThompsonMatcher)(re).empty);
assert("abc".matchOnce!(ThompsonMatcher)(re)[0] == "abc");
}
private enum isReplaceFunctor(alias fun, R) =
__traits(compiles, (Captures!R c) { fun(c); });
// the lowest level - just stuff replacements into the sink
private @trusted void replaceCapturesInto(alias output, Sink, R, T)
(ref Sink sink, R input, T captures)
if(isOutputRange!(Sink, dchar) && isSomeString!R)
{
sink.put(captures.pre);
// a hack to get around bogus errors, should be simply output(captures, sink)
// "is a nested function and cannot be accessed from"
static if(isReplaceFunctor!(output, R))
sink.put(output(captures)); //"mutator" type of function
else
output(captures, sink); //"output" type of function
sink.put(captures.post);
}
// ditto for a range of captures
private void replaceMatchesInto(alias output, Sink, R, T)
(ref Sink sink, R input, T matches)
if(isOutputRange!(Sink, dchar) && isSomeString!R)
{
size_t offset = 0;
foreach(cap; matches)
{
sink.put(cap.pre[offset .. $]);
// same hack, see replaceCapturesInto
static if(isReplaceFunctor!(output, R))
sink.put(output(cap)); //"mutator" type of function
else
output(cap, sink); //"output" type of function
offset = cap.pre.length + cap.hit.length;
}
sink.put(input[offset .. $]);
}
// a general skeleton of replaceFirst
private R replaceFirstWith(alias output, R, RegEx)(R input, RegEx re)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
auto data = matchFirst(input, re);
if(data.empty)
return input;
auto app = appender!(R)();
replaceCapturesInto!output(app, input, data);
return app.data;
}
// ditto for replaceAll
// the method parameter allows old API to ride on the back of the new one
private R replaceAllWith(alias output,
alias method=matchAll, R, RegEx)(R input, RegEx re)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
auto matches = method(input, re); //inout(C)[] fails
if(matches.empty)
return input;
auto app = appender!(R)();
replaceMatchesInto!output(app, input, matches);
return app.data;
}
/++
Start matching $(D input) to regex pattern $(D re),
using Thompson NFA matching scheme.
The use of this function is $(RED discouraged) - use either of
$(LREF matchAll) or $(LREF matchFirst).
Delegating the kind of operation
to "g" flag is soon to be phased out along with the
ability to choose the exact matching scheme. The choice of
matching scheme to use depends highly on the pattern kind and
can done automatically on case by case basis.
Returns: a $(D RegexMatch) object holding engine state after first match.
+/
public auto match(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == Regex!(BasicElementOf!R)))
{
import std.regex.internal.thompson;
return RegexMatch!(Unqual!(typeof(input)),ThompsonMatcher)(input, re);
}
///ditto
public auto match(R, String)(R input, String re)
if(isSomeString!R && isSomeString!String)
{
import std.regex.internal.thompson;
return RegexMatch!(Unqual!(typeof(input)),ThompsonMatcher)(input, regex(re));
}
public auto match(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == StaticRegex!(BasicElementOf!R)))
{
import std.regex.internal.backtracking;
return RegexMatch!(Unqual!(typeof(input)),BacktrackingMatcher!true)(input, re);
}
/++
Find the first (leftmost) slice of the $(D input) that
matches the pattern $(D re). This function picks the most suitable
regular expression engine depending on the pattern properties.
$(D re) parameter can be one of three types:
$(UL
$(LI Plain string, in which case it's compiled to bytecode before matching. )
$(LI Regex!char (wchar/dchar) that contains a pattern in the form of
compiled bytecode. )
$(LI StaticRegex!char (wchar/dchar) that contains a pattern in the form of
compiled native machine code. )
)
Returns:
$(LREF Captures) containing the extent of a match together with all submatches
if there was a match, otherwise an empty $(LREF Captures) object.
+/
public auto matchFirst(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == Regex!(BasicElementOf!R)))
{
import std.regex.internal.thompson;
return matchOnce!ThompsonMatcher(input, re);
}
///ditto
public auto matchFirst(R, String)(R input, String re)
if(isSomeString!R && isSomeString!String)
{
import std.regex.internal.thompson;
return matchOnce!ThompsonMatcher(input, regex(re));
}
public auto matchFirst(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == StaticRegex!(BasicElementOf!R)))
{
import std.regex.internal.backtracking;
return matchOnce!(BacktrackingMatcher!true)(input, re);
}
/++
Initiate a search for all non-overlapping matches to the pattern $(D re)
in the given $(D input). The result is a lazy range of matches generated
as they are encountered in the input going left to right.
This function picks the most suitable regular expression engine
depending on the pattern properties.
$(D re) parameter can be one of three types:
$(UL
$(LI Plain string, in which case it's compiled to bytecode before matching. )
$(LI Regex!char (wchar/dchar) that contains a pattern in the form of
compiled bytecode. )
$(LI StaticRegex!char (wchar/dchar) that contains a pattern in the form of
compiled native machine code. )
)
Returns:
$(LREF RegexMatch) object that represents matcher state
after the first match was found or an empty one if not present.
+/
public auto matchAll(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == Regex!(BasicElementOf!R)))
{
import std.regex.internal.thompson;
return matchMany!ThompsonMatcher(input, re);
}
///ditto
public auto matchAll(R, String)(R input, String re)
if(isSomeString!R && isSomeString!String)
{
import std.regex.internal.thompson;
return matchMany!ThompsonMatcher(input, regex(re));
}
public auto matchAll(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == StaticRegex!(BasicElementOf!R)))
{
import std.regex.internal.backtracking;
return matchMany!(BacktrackingMatcher!true)(input, re);
}
// another set of tests just to cover the new API
@system unittest
{
import std.conv : to;
import std.algorithm : map, equal;
foreach(String; AliasSeq!(string, wstring, const(dchar)[]))
{
auto str1 = "blah-bleh".to!String();
auto pat1 = "bl[ae]h".to!String();
auto mf = matchFirst(str1, pat1);
assert(mf.equal(["blah".to!String()]));
auto mAll = matchAll(str1, pat1);
assert(mAll.equal!((a,b) => a.equal(b))
([["blah".to!String()], ["bleh".to!String()]]));
auto str2 = "1/03/12 - 3/03/12".to!String();
auto pat2 = regex(r"(\d+)/(\d+)/(\d+)".to!String());
auto mf2 = matchFirst(str2, pat2);
assert(mf2.equal(["1/03/12", "1", "03", "12"].map!(to!String)()));
auto mAll2 = matchAll(str2, pat2);
assert(mAll2.front.equal(mf2));
mAll2.popFront();
assert(mAll2.front.equal(["3/03/12", "3", "03", "12"].map!(to!String)()));
mf2.popFrontN(3);
assert(mf2.equal(["12".to!String()]));
auto ctPat = ctRegex!(`(?P<Quot>\d+)/(?P<Denom>\d+)`.to!String());
auto str = "2 + 34/56 - 6/1".to!String();
auto cmf = matchFirst(str, ctPat);
assert(cmf.equal(["34/56", "34", "56"].map!(to!String)()));
assert(cmf["Quot"] == "34".to!String());
assert(cmf["Denom"] == "56".to!String());
auto cmAll = matchAll(str, ctPat);
assert(cmAll.front.equal(cmf));
cmAll.popFront();
assert(cmAll.front.equal(["6/1", "6", "1"].map!(to!String)()));
}
}
/++
Start matching of $(D input) to regex pattern $(D re),
using traditional $(LUCKY backtracking) matching scheme.
The use of this function is $(RED discouraged) - use either of
$(LREF matchAll) or $(LREF matchFirst).
Delegating the kind of operation
to "g" flag is soon to be phased out along with the
ability to choose the exact matching scheme. The choice of
matching scheme to use depends highly on the pattern kind and
can done automatically on case by case basis.
Returns: a $(D RegexMatch) object holding engine
state after first match.
+/
public auto bmatch(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == Regex!(BasicElementOf!R)))
{
import std.regex.internal.backtracking;
return RegexMatch!(Unqual!(typeof(input)), BacktrackingMatcher!false)(input, re);
}
///ditto
public auto bmatch(R, String)(R input, String re)
if(isSomeString!R && isSomeString!String)
{
import std.regex.internal.backtracking;
return RegexMatch!(Unqual!(typeof(input)), BacktrackingMatcher!false)(input, regex(re));
}
public auto bmatch(R, RegEx)(R input, RegEx re)
if(isSomeString!R && is(RegEx == StaticRegex!(BasicElementOf!R)))
{
import std.regex.internal.backtracking;
return RegexMatch!(Unqual!(typeof(input)),BacktrackingMatcher!true)(input, re);
}
// produces replacement string from format using captures for substitution
package void replaceFmt(R, Capt, OutR)
(R format, Capt captures, OutR sink, bool ignoreBadSubs = false)
if(isOutputRange!(OutR, ElementEncodingType!R[]) &&
isOutputRange!(OutR, ElementEncodingType!(Capt.String)[]))
{
import std.algorithm, std.conv;
import std.ascii: isDigit, isAlpha;
enum State { Normal, Dollar }
auto state = State.Normal;
size_t offset;
L_Replace_Loop:
while(!format.empty)
final switch(state)
{
case State.Normal:
for(offset = 0; offset < format.length; offset++)//no decoding
{
if(format[offset] == '$')
{
state = State.Dollar;
sink.put(format[0 .. offset]);
format = format[offset+1 .. $];//ditto
continue L_Replace_Loop;
}
}
sink.put(format[0 .. offset]);
format = format[offset .. $];
break;
case State.Dollar:
if(isDigit(format[0]))
{
uint digit = parse!uint(format);
enforce(ignoreBadSubs || digit < captures.length, text("invalid submatch number ", digit));
if(digit < captures.length)
sink.put(captures[digit]);
}
else if(format[0] == '{')
{
auto x = find!(a => !isAlpha(a))(format[1..$]);
enforce(!x.empty && x[0] == '}', "no matching '}' in replacement format");
auto name = format[1 .. $ - x.length];
format = x[1..$];
enforce(!name.empty, "invalid name in ${...} replacement format");
sink.put(captures[name]);
}
else if(format[0] == '&')
{
sink.put(captures[0]);
format = format[1 .. $];
}
else if(format[0] == '`')
{
sink.put(captures.pre);
format = format[1 .. $];
}
else if(format[0] == '\'')
{
sink.put(captures.post);
format = format[1 .. $];
}
else if(format[0] == '$')
{
sink.put(format[0 .. 1]);
format = format[1 .. $];
}
state = State.Normal;
break;
}
enforce(state == State.Normal, "invalid format string in regex replace");
}
/++
Construct a new string from $(D input) by replacing the first match with
a string generated from it according to the $(D format) specifier.
To replace all matches use $(LREF replaceAll).
Params:
input = string to search
re = compiled regular expression to use
format = format string to generate replacements from,
see $(S_LINK Replace format string, the format string).
Returns:
A string of the same type with the first match (if any) replaced.
If no match is found returns the input string itself.
Example:
---
assert(replaceFirst("noon", regex("n"), "[$&]") == "[n]oon");
---
+/
public R replaceFirst(R, C, RegEx)(R input, RegEx re, const(C)[] format)
if(isSomeString!R && is(C : dchar) && isRegexFor!(RegEx, R))
{
return replaceFirstWith!((m, sink) => replaceFmt(format, m, sink))(input, re);
}
/++
This is a general replacement tool that construct a new string by replacing
matches of pattern $(D re) in the $(D input). Unlike the other overload
there is no format string instead captures are passed to
to a user-defined functor $(D fun) that returns a new string
to use as replacement.
This version replaces the first match in $(D input),
see $(LREF replaceAll) to replace the all of the matches.
Returns:
A new string of the same type as $(D input) with all matches
replaced by return values of $(D fun). If no matches found
returns the $(D input) itself.
Example:
---
string list = "#21 out of 46";
string newList = replaceFirst!(cap => to!string(to!int(cap.hit)+1))
(list, regex(`[0-9]+`));
assert(newList == "#22 out of 46");
---
+/
public R replaceFirst(alias fun, R, RegEx)(R input, RegEx re)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
return replaceFirstWith!((m, sink) => sink.put(fun(m)))(input, re);
}
/++
A variation on $(LREF replaceFirst) that instead of allocating a new string
on each call outputs the result piece-wise to the $(D sink). In particular
this enables efficient construction of a final output incrementally.
Like in $(LREF replaceFirst) family of functions there is an overload
for the substitution guided by the $(D format) string
and the one with the user defined callback.
Example:
---
import std.array;
string m1 = "first message\n";
string m2 = "second message\n";
auto result = appender!string();
replaceFirstInto(result, m1, regex(`([a-z]+) message`), "$1");
//equivalent of the above with user-defined callback
replaceFirstInto!(cap=>cap[1])(result, m2, regex(`([a-z]+) message`));
assert(result.data == "first\nsecond\n");
---
+/
public @trusted void replaceFirstInto(Sink, R, C, RegEx)
(ref Sink sink, R input, RegEx re, const(C)[] format)
if(isOutputRange!(Sink, dchar) && isSomeString!R
&& is(C : dchar) && isRegexFor!(RegEx, R))
{
replaceCapturesInto!((m, sink) => replaceFmt(format, m, sink))
(sink, input, matchFirst(input, re));
}
///ditto
public @trusted void replaceFirstInto(alias fun, Sink, R, RegEx)
(Sink sink, R input, RegEx re)
if(isOutputRange!(Sink, dchar) && isSomeString!R && isRegexFor!(RegEx, R))
{
replaceCapturesInto!fun(sink, input, matchFirst(input, re));
}
//examples for replaceFirst
@system unittest
{
import std.conv;
string list = "#21 out of 46";
string newList = replaceFirst!(cap => to!string(to!int(cap.hit)+1))
(list, regex(`[0-9]+`));
assert(newList == "#22 out of 46");
import std.array;
string m1 = "first message\n";
string m2 = "second message\n";
auto result = appender!string();
replaceFirstInto(result, m1, regex(`([a-z]+) message`), "$1");
//equivalent of the above with user-defined callback
replaceFirstInto!(cap=>cap[1])(result, m2, regex(`([a-z]+) message`));
assert(result.data == "first\nsecond\n");
}
/++
Construct a new string from $(D input) by replacing all of the
fragments that match a pattern $(D re) with a string generated
from the match according to the $(D format) specifier.
To replace only the first match use $(LREF replaceFirst).
Params:
input = string to search
re = compiled regular expression to use
format = format string to generate replacements from,
see $(S_LINK Replace format string, the format string).
Returns:
A string of the same type as $(D input) with the all
of the matches (if any) replaced.
If no match is found returns the input string itself.
Example:
---
// insert comma as thousands delimiter
auto re = regex(r"(?<=\d)(?=(\d\d\d)+\b)","g");
assert(replaceAll("12000 + 42100 = 54100", re, ",") == "12,000 + 42,100 = 54,100");
---
+/
public @trusted R replaceAll(R, C, RegEx)(R input, RegEx re, const(C)[] format)
if(isSomeString!R && is(C : dchar) && isRegexFor!(RegEx, R))
{
return replaceAllWith!((m, sink) => replaceFmt(format, m, sink))(input, re);
}
/++
This is a general replacement tool that construct a new string by replacing
matches of pattern $(D re) in the $(D input). Unlike the other overload
there is no format string instead captures are passed to
to a user-defined functor $(D fun) that returns a new string
to use as replacement.
This version replaces all of the matches found in $(D input),
see $(LREF replaceFirst) to replace the first match only.
Returns:
A new string of the same type as $(D input) with all matches
replaced by return values of $(D fun). If no matches found
returns the $(D input) itself.
Params:
input = string to search
re = compiled regular expression
fun = delegate to use
Example:
Capitalize the letters 'a' and 'r':
---
string baz(Captures!(string) m)
{
return std.string.toUpper(m.hit);
}
auto s = replaceAll!(baz)("Strap a rocket engine on a chicken.",
regex("[ar]"));
assert(s == "StRAp A Rocket engine on A chicken.");
---
+/
public @trusted R replaceAll(alias fun, R, RegEx)(R input, RegEx re)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
return replaceAllWith!((m, sink) => sink.put(fun(m)))(input, re);
}
/++
A variation on $(LREF replaceAll) that instead of allocating a new string
on each call outputs the result piece-wise to the $(D sink). In particular
this enables efficient construction of a final output incrementally.
As with $(LREF replaceAll) there are 2 overloads - one with a format string,
the other one with a user defined functor.
+/
public @trusted void replaceAllInto(Sink, R, C, RegEx)
(Sink sink, R input, RegEx re, const(C)[] format)
if(isOutputRange!(Sink, dchar) && isSomeString!R
&& is(C : dchar) && isRegexFor!(RegEx, R))
{
replaceMatchesInto!((m, sink) => replaceFmt(format, m, sink))
(sink, input, matchAll(input, re));
}
///ditto
public @trusted void replaceAllInto(alias fun, Sink, R, RegEx)
(Sink sink, R input, RegEx re)
if(isOutputRange!(Sink, dchar) && isSomeString!R && isRegexFor!(RegEx, R))
{
replaceMatchesInto!fun(sink, input, matchAll(input, re));
}
///
@system unittest
{
// insert comma as thousands delimiter in fifty randomly produced big numbers
import std.array, std.random, std.conv, std.range;
static re = regex(`(?<=\d)(?=(\d\d\d)+\b)`, "g");
auto sink = appender!(char [])();
enum ulong min = 10UL ^^ 10, max = 10UL ^^ 19;
foreach (i; 0 .. 50)
{
sink.clear();
replaceAllInto(sink, text(uniform(min, max)), re, ",");
foreach (pos; iota(sink.data.length - 4, 0, -4))
assert(sink.data[pos] == ',');
}
}
// exercise all of the replace APIs
@system unittest
{
import std.conv;
// try and check first/all simple substitution
foreach(S; AliasSeq!(string, wstring, dstring, char[], wchar[], dchar[]))
{
S s1 = "curt trial".to!S();
S s2 = "round dome".to!S();
S t1F = "court trial".to!S();
S t2F = "hound dome".to!S();
S t1A = "court trial".to!S();
S t2A = "hound home".to!S();
auto re1 = regex("curt".to!S());
auto re2 = regex("[dr]o".to!S());
assert(replaceFirst(s1, re1, "court") == t1F);
assert(replaceFirst(s2, re2, "ho") == t2F);
assert(replaceAll(s1, re1, "court") == t1A);
assert(replaceAll(s2, re2, "ho") == t2A);
auto rep1 = replaceFirst!(cap => cap[0][0]~"o".to!S()~cap[0][1..$])(s1, re1);
assert(rep1 == t1F);
assert(replaceFirst!(cap => "ho".to!S())(s2, re2) == t2F);
auto rep1A = replaceAll!(cap => cap[0][0]~"o".to!S()~cap[0][1..$])(s1, re1);
assert(rep1A == t1A);
assert(replaceAll!(cap => "ho".to!S())(s2, re2) == t2A);
auto sink = appender!S();
replaceFirstInto(sink, s1, re1, "court");
assert(sink.data == t1F);
replaceFirstInto(sink, s2, re2, "ho");
assert(sink.data == t1F~t2F);
replaceAllInto(sink, s1, re1, "court");
assert(sink.data == t1F~t2F~t1A);
replaceAllInto(sink, s2, re2, "ho");
assert(sink.data == t1F~t2F~t1A~t2A);
}
}
/++
Old API for replacement, operation depends on flags of pattern $(D re).
With "g" flag it performs the equivalent of $(LREF replaceAll) otherwise it
works the same as $(LREF replaceFirst).
The use of this function is $(RED discouraged), please use $(LREF replaceAll)
or $(LREF replaceFirst) explicitly.
+/
public R replace(alias scheme = match, R, C, RegEx)(R input, RegEx re, const(C)[] format)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
return replaceAllWith!((m, sink) => replaceFmt(format, m, sink), match)(input, re);
}
///ditto
public R replace(alias fun, R, RegEx)(R input, RegEx re)
if(isSomeString!R && isRegexFor!(RegEx, R))
{
return replaceAllWith!(fun, match)(input, re);
}
/++
Range that splits a string using a regular expression as a
separator.
Example:
----
auto s1 = ", abc, de, fg, hi, ";
assert(equal(splitter(s1, regex(", *")),
["", "abc", "de", "fg", "hi", ""]));
----
+/
public struct Splitter(Range, alias RegEx = Regex)
if(isSomeString!Range && isRegexFor!(RegEx, Range))
{
private:
Range _input;
size_t _offset;
alias Rx = typeof(match(Range.init,RegEx.init));
Rx _match;
@trusted this(Range input, RegEx separator)
{//@@@BUG@@@ generated opAssign of RegexMatch is not @trusted
_input = input;
separator.flags |= RegexOption.global;
if (_input.empty)
{
//there is nothing to match at all, make _offset > 0
_offset = 1;
}
else
{
_match = Rx(_input, separator);
}
}
public:
auto ref opSlice()
{
return this.save;
}
///Forward range primitives.
@property Range front()
{
import std.algorithm : min;
assert(!empty && _offset <= _match.pre.length
&& _match.pre.length <= _input.length);
return _input[_offset .. min($, _match.pre.length)];
}
///ditto
@property bool empty()
{
return _offset > _input.length;
}
///ditto
void popFront()
{
assert(!empty);
if (_match.empty)
{
//No more separators, work is done here
_offset = _input.length + 1;
}
else
{
//skip past the separator
_offset = _match.pre.length + _match.hit.length;
_match.popFront();
}
}
///ditto
@property auto save()
{
return this;
}
}
/**
A helper function, creates a $(D Splitter) on range $(D r) separated by regex $(D pat).
Captured subexpressions have no effect on the resulting range.
*/
public Splitter!(Range, RegEx) splitter(Range, RegEx)(Range r, RegEx pat)
if(is(BasicElementOf!Range : dchar) && isRegexFor!(RegEx, Range))
{
return Splitter!(Range, RegEx)(r, pat);
}
///An eager version of $(D splitter) that creates an array with splitted slices of $(D input).
public @trusted String[] split(String, RegEx)(String input, RegEx rx)
if(isSomeString!String && isRegexFor!(RegEx, String))
{
auto a = appender!(String[])();
foreach(e; splitter(input, rx))
a.put(e);
return a.data;
}
///Exception object thrown in case of errors during regex compilation.
public alias RegexException = std.regex.internal.ir.RegexException;
| D |
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/traits.d, _traits.d)
* Documentation: https://dlang.org/phobos/dmd_traits.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/traits.d
*/
module dmd.traits;
import core.stdc.stdio;
import dmd.aggregate;
import dmd.arraytypes;
import dmd.astcodegen;
import dmd.attrib;
import dmd.canthrow;
import dmd.dclass;
import dmd.declaration;
import dmd.denum;
import dmd.dimport;
import dmd.dmodule;
import dmd.dscope;
import dmd.dsymbol;
import dmd.dsymbolsem;
import dmd.dtemplate;
import dmd.errors;
import dmd.expression;
import dmd.expressionsem;
import dmd.func;
import dmd.globals;
import dmd.hdrgen;
import dmd.id;
import dmd.identifier;
import dmd.mtype;
import dmd.nogc;
import dmd.parse;
import dmd.root.array;
import dmd.root.speller;
import dmd.root.stringtable;
import dmd.target;
import dmd.tokens;
import dmd.typesem;
import dmd.visitor;
import dmd.root.rootobject;
import dmd.root.outbuffer;
import dmd.utils;
enum LOGSEMANTIC = false;
/************************ TraitsExp ************************************/
/**************************************
* Convert `Expression` or `Type` to corresponding `Dsymbol`, additionally
* stripping off expression contexts.
*
* Some symbol related `__traits` ignore arguments expression contexts.
* For example:
* ----
* struct S { void f() {} }
* S s;
* pragma(msg, __traits(isNested, s.f));
* // s.f is `DotVarExp`, but `__traits(isNested)`` needs a `FuncDeclaration`.
* ----
*
* This is used for that common `__traits` behavior.
*
* Input:
* oarg object to get the symbol for
* Returns:
* Dsymbol the corresponding symbol for oarg
*/
private Dsymbol getDsymbolWithoutExpCtx(RootObject oarg)
{
if (auto e = isExpression(oarg))
{
if (e.op == TOK.dotVariable)
return (cast(DotVarExp)e).var;
if (e.op == TOK.dotTemplateDeclaration)
return (cast(DotTemplateExp)e).td;
}
return getDsymbol(oarg);
}
private const StringTable!bool traitsStringTable;
shared static this()
{
static immutable string[] names =
[
"isAbstractClass",
"isArithmetic",
"isAssociativeArray",
"isDisabled",
"isDeprecated",
"isFuture",
"isFinalClass",
"isPOD",
"isNested",
"isFloating",
"isIntegral",
"isScalar",
"isStaticArray",
"isUnsigned",
"isVirtualFunction",
"isVirtualMethod",
"isAbstractFunction",
"isFinalFunction",
"isOverrideFunction",
"isStaticFunction",
"isModule",
"isPackage",
"isRef",
"isOut",
"isLazy",
"isReturnOnStack",
"hasMember",
"identifier",
"getProtection",
"parent",
"getLinkage",
"getMember",
"getOverloads",
"getVirtualFunctions",
"getVirtualMethods",
"classInstanceSize",
"allMembers",
"derivedMembers",
"isSame",
"compiles",
"parameters",
"getAliasThis",
"getAttributes",
"getFunctionAttributes",
"getFunctionVariadicStyle",
"getParameterStorageClasses",
"getUnitTests",
"getVirtualIndex",
"getPointerBitmap",
"isZeroInit",
"getTargetInfo",
"getLocation",
"hasPostblit",
"hasCopyConstructor",
];
StringTable!(bool)* stringTable = cast(StringTable!(bool)*) &traitsStringTable;
stringTable._init(names.length);
foreach (s; names)
{
auto sv = stringTable.insert(s, true);
assert(sv);
}
}
/**
* get an array of size_t values that indicate possible pointer words in memory
* if interpreted as the type given as argument
* Returns: the size of the type in bytes, d_uns64.max on error
*/
d_uns64 getTypePointerBitmap(Loc loc, Type t, Array!(d_uns64)* data)
{
d_uns64 sz;
if (t.ty == Tclass && !(cast(TypeClass)t).sym.isInterfaceDeclaration())
sz = (cast(TypeClass)t).sym.AggregateDeclaration.size(loc);
else
sz = t.size(loc);
if (sz == SIZE_INVALID)
return d_uns64.max;
const sz_size_t = Type.tsize_t.size(loc);
if (sz > sz.max - sz_size_t)
{
error(loc, "size overflow for type `%s`", t.toChars());
return d_uns64.max;
}
d_uns64 bitsPerWord = sz_size_t * 8;
d_uns64 cntptr = (sz + sz_size_t - 1) / sz_size_t;
d_uns64 cntdata = (cntptr + bitsPerWord - 1) / bitsPerWord;
data.setDim(cast(size_t)cntdata);
data.zero();
extern (C++) final class PointerBitmapVisitor : Visitor
{
alias visit = Visitor.visit;
public:
extern (D) this(Array!(d_uns64)* _data, d_uns64 _sz_size_t)
{
this.data = _data;
this.sz_size_t = _sz_size_t;
}
void setpointer(d_uns64 off)
{
d_uns64 ptroff = off / sz_size_t;
(*data)[cast(size_t)(ptroff / (8 * sz_size_t))] |= 1L << (ptroff % (8 * sz_size_t));
}
override void visit(Type t)
{
Type tb = t.toBasetype();
if (tb != t)
tb.accept(this);
}
override void visit(TypeError t)
{
visit(cast(Type)t);
}
override void visit(TypeNext t)
{
assert(0);
}
override void visit(TypeBasic t)
{
if (t.ty == Tvoid)
setpointer(offset);
}
override void visit(TypeVector t)
{
}
override void visit(TypeArray t)
{
assert(0);
}
override void visit(TypeSArray t)
{
d_uns64 arrayoff = offset;
d_uns64 nextsize = t.next.size();
if (nextsize == SIZE_INVALID)
error = true;
d_uns64 dim = t.dim.toInteger();
for (d_uns64 i = 0; i < dim; i++)
{
offset = arrayoff + i * nextsize;
t.next.accept(this);
}
offset = arrayoff;
}
override void visit(TypeDArray t)
{
setpointer(offset + sz_size_t);
}
// dynamic array is {length,ptr}
override void visit(TypeAArray t)
{
setpointer(offset);
}
override void visit(TypePointer t)
{
if (t.nextOf().ty != Tfunction) // don't mark function pointers
setpointer(offset);
}
override void visit(TypeReference t)
{
setpointer(offset);
}
override void visit(TypeClass t)
{
setpointer(offset);
}
override void visit(TypeFunction t)
{
}
override void visit(TypeDelegate t)
{
setpointer(offset);
}
// delegate is {context, function}
override void visit(TypeQualified t)
{
assert(0);
}
// assume resolved
override void visit(TypeIdentifier t)
{
assert(0);
}
override void visit(TypeInstance t)
{
assert(0);
}
override void visit(TypeTypeof t)
{
assert(0);
}
override void visit(TypeReturn t)
{
assert(0);
}
override void visit(TypeEnum t)
{
visit(cast(Type)t);
}
override void visit(TypeTuple t)
{
visit(cast(Type)t);
}
override void visit(TypeSlice t)
{
assert(0);
}
override void visit(TypeNull t)
{
// always a null pointer
}
override void visit(TypeStruct t)
{
d_uns64 structoff = offset;
foreach (v; t.sym.fields)
{
offset = structoff + v.offset;
if (v.type.ty == Tclass)
setpointer(offset);
else
v.type.accept(this);
}
offset = structoff;
}
// a "toplevel" class is treated as an instance, while TypeClass fields are treated as references
void visitClass(TypeClass t)
{
d_uns64 classoff = offset;
// skip vtable-ptr and monitor
if (t.sym.baseClass)
visitClass(cast(TypeClass)t.sym.baseClass.type);
foreach (v; t.sym.fields)
{
offset = classoff + v.offset;
v.type.accept(this);
}
offset = classoff;
}
Array!(d_uns64)* data;
d_uns64 offset;
d_uns64 sz_size_t;
bool error;
}
scope PointerBitmapVisitor pbv = new PointerBitmapVisitor(data, sz_size_t);
if (t.ty == Tclass)
pbv.visitClass(cast(TypeClass)t);
else
t.accept(pbv);
return pbv.error ? d_uns64.max : sz;
}
/**
* get an array of size_t values that indicate possible pointer words in memory
* if interpreted as the type given as argument
* the first array element is the size of the type for independent interpretation
* of the array
* following elements bits represent one word (4/8 bytes depending on the target
* architecture). If set the corresponding memory might contain a pointer/reference.
*
* Returns: [T.sizeof, pointerbit0-31/63, pointerbit32/64-63/128, ...]
*/
private Expression pointerBitmap(TraitsExp e)
{
if (!e.args || e.args.dim != 1)
{
error(e.loc, "a single type expected for trait pointerBitmap");
return new ErrorExp();
}
Type t = getType((*e.args)[0]);
if (!t)
{
error(e.loc, "`%s` is not a type", (*e.args)[0].toChars());
return new ErrorExp();
}
Array!(d_uns64) data;
d_uns64 sz = getTypePointerBitmap(e.loc, t, &data);
if (sz == d_uns64.max)
return new ErrorExp();
auto exps = new Expressions(data.dim + 1);
(*exps)[0] = new IntegerExp(e.loc, sz, Type.tsize_t);
foreach (size_t i; 1 .. exps.dim)
(*exps)[i] = new IntegerExp(e.loc, data[cast(size_t) (i - 1)], Type.tsize_t);
auto ale = new ArrayLiteralExp(e.loc, Type.tsize_t.sarrayOf(data.dim + 1), exps);
return ale;
}
Expression semanticTraits(TraitsExp e, Scope* sc)
{
static if (LOGSEMANTIC)
{
printf("TraitsExp::semantic() %s\n", e.toChars());
}
if (e.ident != Id.compiles &&
e.ident != Id.isSame &&
e.ident != Id.identifier &&
e.ident != Id.getProtection &&
e.ident != Id.getAttributes)
{
// Pretend we're in a deprecated scope so that deprecation messages
// aren't triggered when checking if a symbol is deprecated
const save = sc.stc;
if (e.ident == Id.isDeprecated)
sc.stc |= STC.deprecated_;
if (!TemplateInstance.semanticTiargs(e.loc, sc, e.args, 1))
{
sc.stc = save;
return new ErrorExp();
}
sc.stc = save;
}
size_t dim = e.args ? e.args.dim : 0;
Expression dimError(int expected)
{
e.error("expected %d arguments for `%s` but had %d", expected, e.ident.toChars(), cast(int)dim);
return new ErrorExp();
}
static IntegerExp True()
{
return IntegerExp.createBool(true);
}
static IntegerExp False()
{
return IntegerExp.createBool(false);
}
/********
* Gets the function type from a given AST node
* if the node is a function of some sort.
* Params:
* o = an AST node to check for a `TypeFunction`
* fdp = if `o` is a FuncDeclaration then fdp is set to that, otherwise `null`
* Returns:
* a type node if `o` is a declaration of
* a delegate, function, function-pointer or a variable of the former.
* Otherwise, `null`.
*/
static TypeFunction toTypeFunction(RootObject o, out FuncDeclaration fdp)
{
Type t;
if (auto s = getDsymbolWithoutExpCtx(o))
{
if (auto fd = s.isFuncDeclaration())
{
t = fd.type;
fdp = fd;
}
else if (auto vd = s.isVarDeclaration())
t = vd.type;
else
t = isType(o);
}
else
t = isType(o);
if (t)
{
if (t.ty == Tfunction)
return cast(TypeFunction)t;
else if (t.ty == Tdelegate)
return cast(TypeFunction)t.nextOf();
else if (t.ty == Tpointer && t.nextOf().ty == Tfunction)
return cast(TypeFunction)t.nextOf();
}
return null;
}
IntegerExp isX(T)(bool delegate(T) fp)
{
if (!dim)
return False();
foreach (o; *e.args)
{
static if (is(T == Type))
auto y = getType(o);
static if (is(T : Dsymbol))
{
auto s = getDsymbolWithoutExpCtx(o);
if (!s)
return False();
}
static if (is(T == Dsymbol))
alias y = s;
static if (is(T == Declaration))
auto y = s.isDeclaration();
static if (is(T == FuncDeclaration))
auto y = s.isFuncDeclaration();
static if (is(T == EnumMember))
auto y = s.isEnumMember();
if (!y || !fp(y))
return False();
}
return True();
}
alias isTypeX = isX!Type;
alias isDsymX = isX!Dsymbol;
alias isDeclX = isX!Declaration;
alias isFuncX = isX!FuncDeclaration;
alias isEnumMemX = isX!EnumMember;
Expression isPkgX(bool function(Package) fp)
{
return isDsymX((Dsymbol sym) {
Package p = resolveIsPackage(sym);
return (p !is null) && fp(p);
});
}
if (e.ident == Id.isArithmetic)
{
return isTypeX(t => t.isintegral() || t.isfloating());
}
if (e.ident == Id.isFloating)
{
return isTypeX(t => t.isfloating());
}
if (e.ident == Id.isIntegral)
{
return isTypeX(t => t.isintegral());
}
if (e.ident == Id.isScalar)
{
return isTypeX(t => t.isscalar());
}
if (e.ident == Id.isUnsigned)
{
return isTypeX(t => t.isunsigned());
}
if (e.ident == Id.isAssociativeArray)
{
return isTypeX(t => t.toBasetype().ty == Taarray);
}
if (e.ident == Id.isDeprecated)
{
if (global.params.vcomplex)
{
if (isTypeX(t => t.iscomplex() || t.isimaginary()).isBool(true))
return True();
}
return isDsymX(t => t.isDeprecated());
}
if (e.ident == Id.isFuture)
{
return isDeclX(t => t.isFuture());
}
if (e.ident == Id.isStaticArray)
{
return isTypeX(t => t.toBasetype().ty == Tsarray);
}
if (e.ident == Id.isAbstractClass)
{
return isTypeX(t => t.toBasetype().ty == Tclass &&
(cast(TypeClass)t.toBasetype()).sym.isAbstract());
}
if (e.ident == Id.isFinalClass)
{
return isTypeX(t => t.toBasetype().ty == Tclass &&
((cast(TypeClass)t.toBasetype()).sym.storage_class & STC.final_) != 0);
}
if (e.ident == Id.isTemplate)
{
if (dim != 1)
return dimError(1);
return isDsymX((s)
{
if (!s.toAlias().isOverloadable())
return false;
return overloadApply(s,
sm => sm.isTemplateDeclaration() !is null) != 0;
});
}
if (e.ident == Id.isPOD)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto t = isType(o);
if (!t)
{
e.error("type expected as second argument of __traits `%s` instead of `%s`",
e.ident.toChars(), o.toChars());
return new ErrorExp();
}
Type tb = t.baseElemOf();
if (auto sd = tb.ty == Tstruct ? (cast(TypeStruct)tb).sym : null)
{
return sd.isPOD() ? True() : False();
}
return True();
}
if (e.ident == Id.hasCopyConstructor || e.ident == Id.hasPostblit)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto t = isType(o);
if (!t)
{
e.error("type expected as second argument of __traits `%s` instead of `%s`",
e.ident.toChars(), o.toChars());
return new ErrorExp();
}
Type tb = t.baseElemOf();
if (auto sd = tb.ty == Tstruct ? (cast(TypeStruct)tb).sym : null)
{
return (e.ident == Id.hasPostblit) ? (sd.postblit ? True() : False())
: (sd.hasCopyCtor ? True() : False());
}
return False();
}
if (e.ident == Id.isNested)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbolWithoutExpCtx(o);
if (!s)
{
}
else if (auto ad = s.isAggregateDeclaration())
{
return ad.isNested() ? True() : False();
}
else if (auto fd = s.isFuncDeclaration())
{
return fd.isNested() ? True() : False();
}
e.error("aggregate or function expected instead of `%s`", o.toChars());
return new ErrorExp();
}
if (e.ident == Id.isDisabled)
{
if (dim != 1)
return dimError(1);
return isDeclX(f => f.isDisabled());
}
if (e.ident == Id.isAbstractFunction)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => f.isAbstract());
}
if (e.ident == Id.isVirtualFunction)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => f.isVirtual());
}
if (e.ident == Id.isVirtualMethod)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => f.isVirtualMethod());
}
if (e.ident == Id.isFinalFunction)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => f.isFinalFunc());
}
if (e.ident == Id.isOverrideFunction)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => f.isOverride());
}
if (e.ident == Id.isStaticFunction)
{
if (dim != 1)
return dimError(1);
return isFuncX(f => !f.needThis() && !f.isNested());
}
if (e.ident == Id.isModule)
{
if (dim != 1)
return dimError(1);
return isPkgX(p => p.isModule() || p.isPackageMod());
}
if (e.ident == Id.isPackage)
{
if (dim != 1)
return dimError(1);
return isPkgX(p => p.isModule() is null);
}
if (e.ident == Id.isRef)
{
if (dim != 1)
return dimError(1);
return isDeclX(d => d.isRef());
}
if (e.ident == Id.isOut)
{
if (dim != 1)
return dimError(1);
return isDeclX(d => d.isOut());
}
if (e.ident == Id.isLazy)
{
if (dim != 1)
return dimError(1);
return isDeclX(d => (d.storage_class & STC.lazy_) != 0);
}
if (e.ident == Id.identifier)
{
// Get identifier for symbol as a string literal
/* Specify 0 for bit 0 of the flags argument to semanticTiargs() so that
* a symbol should not be folded to a constant.
* Bit 1 means don't convert Parameter to Type if Parameter has an identifier
*/
if (!TemplateInstance.semanticTiargs(e.loc, sc, e.args, 2))
return new ErrorExp();
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
Identifier id;
if (auto po = isParameter(o))
{
if (!po.ident)
{
e.error("argument `%s` has no identifier", po.type.toChars());
return new ErrorExp();
}
id = po.ident;
}
else
{
Dsymbol s = getDsymbolWithoutExpCtx(o);
if (!s || !s.ident)
{
e.error("argument `%s` has no identifier", o.toChars());
return new ErrorExp();
}
id = s.ident;
}
auto se = new StringExp(e.loc, id.toString());
return se.expressionSemantic(sc);
}
if (e.ident == Id.getProtection)
{
if (dim != 1)
return dimError(1);
Scope* sc2 = sc.push();
sc2.flags = sc.flags | SCOPE.noaccesscheck | SCOPE.ignoresymbolvisibility;
bool ok = TemplateInstance.semanticTiargs(e.loc, sc2, e.args, 1);
sc2.pop();
if (!ok)
return new ErrorExp();
auto o = (*e.args)[0];
auto s = getDsymbolWithoutExpCtx(o);
if (!s)
{
if (!isError(o))
e.error("argument `%s` has no protection", o.toChars());
return new ErrorExp();
}
if (s.semanticRun == PASS.init)
s.dsymbolSemantic(null);
auto protName = protectionToString(s.prot().kind); // TODO: How about package(names)
assert(protName);
auto se = new StringExp(e.loc, protName);
return se.expressionSemantic(sc);
}
if (e.ident == Id.parent)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbolWithoutExpCtx(o);
if (s)
{
// https://issues.dlang.org/show_bug.cgi?id=12496
// Consider:
// class T1
// {
// class C(uint value) { }
// }
// __traits(parent, T1.C!2)
if (auto ad = s.isAggregateDeclaration()) // `s` is `C`
{
if (ad.isNested()) // `C` is nested
{
if (auto p = s.toParent()) // `C`'s parent is `C!2`, believe it or not
{
if (p.isTemplateInstance()) // `C!2` is a template instance
{
s = p; // `C!2`'s parent is `T1`
auto td = (cast(TemplateInstance)p).tempdecl;
if (td)
s = td; // get the declaration context just in case there's two contexts
}
}
}
}
if (auto fd = s.isFuncDeclaration()) // https://issues.dlang.org/show_bug.cgi?id=8943
s = fd.toAliasFunc();
if (!s.isImport()) // https://issues.dlang.org/show_bug.cgi?id=8922
s = s.toParent();
}
if (!s || s.isImport())
{
e.error("argument `%s` has no parent", o.toChars());
return new ErrorExp();
}
if (auto f = s.isFuncDeclaration())
{
if (auto td = getFuncTemplateDecl(f))
{
if (td.overroot) // if not start of overloaded list of TemplateDeclaration's
td = td.overroot; // then get the start
Expression ex = new TemplateExp(e.loc, td, f);
ex = ex.expressionSemantic(sc);
return ex;
}
if (auto fld = f.isFuncLiteralDeclaration())
{
// Directly translate to VarExp instead of FuncExp
Expression ex = new VarExp(e.loc, fld, true);
return ex.expressionSemantic(sc);
}
}
return symbolToExp(s, e.loc, sc, false);
}
if (e.ident == Id.hasMember ||
e.ident == Id.getMember ||
e.ident == Id.getOverloads ||
e.ident == Id.getVirtualMethods ||
e.ident == Id.getVirtualFunctions)
{
if (dim != 2 && !(dim == 3 && e.ident == Id.getOverloads))
return dimError(2);
auto o = (*e.args)[0];
auto ex = isExpression((*e.args)[1]);
if (!ex)
{
e.error("expression expected as second argument of __traits `%s`", e.ident.toChars());
return new ErrorExp();
}
ex = ex.ctfeInterpret();
bool includeTemplates = false;
if (dim == 3 && e.ident == Id.getOverloads)
{
auto b = isExpression((*e.args)[2]);
b = b.ctfeInterpret();
if (!b.type.equals(Type.tbool))
{
e.error("`bool` expected as third argument of `__traits(getOverloads)`, not `%s` of type `%s`", b.toChars(), b.type.toChars());
return new ErrorExp();
}
includeTemplates = b.isBool(true);
}
StringExp se = ex.toStringExp();
if (!se || se.len == 0)
{
e.error("string expected as second argument of __traits `%s` instead of `%s`", e.ident.toChars(), ex.toChars());
return new ErrorExp();
}
se = se.toUTF8(sc);
if (se.sz != 1)
{
e.error("string must be chars");
return new ErrorExp();
}
auto id = Identifier.idPool(se.peekString());
/* Prefer dsymbol, because it might need some runtime contexts.
*/
Dsymbol sym = getDsymbol(o);
if (sym)
{
if (e.ident == Id.hasMember)
{
if (auto sm = sym.search(e.loc, id))
return True();
}
ex = new DsymbolExp(e.loc, sym);
ex = new DotIdExp(e.loc, ex, id);
}
else if (auto t = isType(o))
ex = typeDotIdExp(e.loc, t, id);
else if (auto ex2 = isExpression(o))
ex = new DotIdExp(e.loc, ex2, id);
else
{
e.error("invalid first argument");
return new ErrorExp();
}
// ignore symbol visibility and disable access checks for these traits
Scope* scx = sc.push();
scx.flags |= SCOPE.ignoresymbolvisibility | SCOPE.noaccesscheck;
scope (exit) scx.pop();
if (e.ident == Id.hasMember)
{
/* Take any errors as meaning it wasn't found
*/
ex = ex.trySemantic(scx);
return ex ? True() : False();
}
else if (e.ident == Id.getMember)
{
if (ex.op == TOK.dotIdentifier)
// Prevent semantic() from replacing Symbol with its initializer
(cast(DotIdExp)ex).wantsym = true;
ex = ex.expressionSemantic(scx);
return ex;
}
else if (e.ident == Id.getVirtualFunctions ||
e.ident == Id.getVirtualMethods ||
e.ident == Id.getOverloads)
{
uint errors = global.errors;
Expression eorig = ex;
ex = ex.expressionSemantic(scx);
if (errors < global.errors)
e.error("`%s` cannot be resolved", eorig.toChars());
/* Create tuple of functions of ex
*/
auto exps = new Expressions();
Dsymbol f;
if (ex.op == TOK.variable)
{
VarExp ve = cast(VarExp)ex;
f = ve.var.isFuncDeclaration();
ex = null;
}
else if (ex.op == TOK.dotVariable)
{
DotVarExp dve = cast(DotVarExp)ex;
f = dve.var.isFuncDeclaration();
if (dve.e1.op == TOK.dotType || dve.e1.op == TOK.this_)
ex = null;
else
ex = dve.e1;
}
else if (ex.op == TOK.template_)
{
VarExp ve = cast(VarExp)ex;
auto td = ve.var.isTemplateDeclaration();
f = td;
if (td && td.funcroot)
f = td.funcroot;
ex = null;
}
bool[string] funcTypeHash;
/* Compute the function signature and insert it in the
* hashtable, if not present. This is needed so that
* traits(getOverlods, F3, "visit") does not count `int visit(int)`
* twice in the following example:
*
* =============================================
* interface F1 { int visit(int);}
* interface F2 { int visit(int); void visit(); }
* interface F3 : F2, F1 {}
*==============================================
*/
void insertInterfaceInheritedFunction(FuncDeclaration fd, Expression e)
{
auto signature = fd.type.toString();
//printf("%s - %s\n", fd.toChars, signature);
if (signature !in funcTypeHash)
{
funcTypeHash[signature] = true;
exps.push(e);
}
}
int dg(Dsymbol s)
{
if (includeTemplates)
{
exps.push(new DsymbolExp(Loc.initial, s, false));
return 0;
}
auto fd = s.isFuncDeclaration();
if (!fd)
return 0;
if (e.ident == Id.getVirtualFunctions && !fd.isVirtual())
return 0;
if (e.ident == Id.getVirtualMethods && !fd.isVirtualMethod())
return 0;
auto fa = new FuncAliasDeclaration(fd.ident, fd, false);
fa.protection = fd.protection;
auto e = ex ? new DotVarExp(Loc.initial, ex, fa, false)
: new DsymbolExp(Loc.initial, fa, false);
// if the parent is an interface declaration
// we must check for functions with the same signature
// in different inherited interfaces
if (sym && sym.isInterfaceDeclaration())
insertInterfaceInheritedFunction(fd, e);
else
exps.push(e);
return 0;
}
InterfaceDeclaration ifd = null;
if (sym)
ifd = sym.isInterfaceDeclaration();
// If the symbol passed as a parameter is an
// interface that inherits other interfaces
overloadApply(f, &dg);
if (ifd && ifd.interfaces && f)
{
// check the overloads of each inherited interface individually
foreach (bc; ifd.interfaces)
{
if (auto fd = bc.sym.search(e.loc, f.ident))
overloadApply(fd, &dg);
}
}
auto tup = new TupleExp(e.loc, exps);
return tup.expressionSemantic(scx);
}
else
assert(0);
}
if (e.ident == Id.classInstanceSize)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbol(o);
auto cd = s ? s.isClassDeclaration() : null;
if (!cd)
{
e.error("first argument is not a class");
return new ErrorExp();
}
if (cd.sizeok != Sizeok.done)
{
cd.size(e.loc);
}
if (cd.sizeok != Sizeok.done)
{
e.error("%s `%s` is forward referenced", cd.kind(), cd.toChars());
return new ErrorExp();
}
return new IntegerExp(e.loc, cd.structsize, Type.tsize_t);
}
if (e.ident == Id.getAliasThis)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbol(o);
auto ad = s ? s.isAggregateDeclaration() : null;
auto exps = new Expressions();
if (ad && ad.aliasthis)
exps.push(new StringExp(e.loc, ad.aliasthis.ident.toString()));
Expression ex = new TupleExp(e.loc, exps);
ex = ex.expressionSemantic(sc);
return ex;
}
if (e.ident == Id.getAttributes)
{
/* Specify 0 for bit 0 of the flags argument to semanticTiargs() so that
* a symbol should not be folded to a constant.
* Bit 1 means don't convert Parameter to Type if Parameter has an identifier
*/
if (!TemplateInstance.semanticTiargs(e.loc, sc, e.args, 3))
return new ErrorExp();
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto po = isParameter(o);
auto s = getDsymbolWithoutExpCtx(o);
UserAttributeDeclaration udad = null;
if (po)
{
udad = po.userAttribDecl;
}
else if (s)
{
if (s.isImport())
{
s = s.isImport().mod;
}
//printf("getAttributes %s, attrs = %p, scope = %p\n", s.toChars(), s.userAttribDecl, s.scope);
udad = s.userAttribDecl;
}
else
{
version (none)
{
Expression x = isExpression(o);
Type t = isType(o);
if (x)
printf("e = %s %s\n", Token.toChars(x.op), x.toChars());
if (t)
printf("t = %d %s\n", t.ty, t.toChars());
}
e.error("first argument is not a symbol");
return new ErrorExp();
}
auto exps = udad ? udad.getAttributes() : new Expressions();
auto tup = new TupleExp(e.loc, exps);
return tup.expressionSemantic(sc);
}
if (e.ident == Id.getFunctionAttributes)
{
/* Extract all function attributes as a tuple (const/shared/inout/pure/nothrow/etc) except UDAs.
* https://dlang.org/spec/traits.html#getFunctionAttributes
*/
if (dim != 1)
return dimError(1);
FuncDeclaration fd;
TypeFunction tf = toTypeFunction((*e.args)[0], fd);
if (!tf)
{
e.error("first argument is not a function");
return new ErrorExp();
}
auto mods = new Expressions();
void addToMods(string str)
{
mods.push(new StringExp(Loc.initial, str));
}
tf.modifiersApply(&addToMods);
tf.attributesApply(&addToMods, TRUSTformatSystem);
auto tup = new TupleExp(e.loc, mods);
return tup.expressionSemantic(sc);
}
if (e.ident == Id.isReturnOnStack)
{
/* Extract as a boolean if function return value is on the stack
* https://dlang.org/spec/traits.html#isReturnOnStack
*/
if (dim != 1)
return dimError(1);
RootObject o = (*e.args)[0];
FuncDeclaration fd;
TypeFunction tf = toTypeFunction(o, fd);
if (!tf)
{
e.error("argument to `__traits(isReturnOnStack, %s)` is not a function", o.toChars());
return new ErrorExp();
}
bool value = target.isReturnOnStack(tf, fd && fd.needThis());
return IntegerExp.createBool(value);
}
if (e.ident == Id.getFunctionVariadicStyle)
{
/* Accept a symbol or a type. Returns one of the following:
* "none" not a variadic function
* "argptr" extern(D) void dstyle(...), use `__argptr` and `__arguments`
* "stdarg" extern(C) void cstyle(int, ...), use core.stdc.stdarg
* "typesafe" void typesafe(T[] ...)
*/
// get symbol linkage as a string
if (dim != 1)
return dimError(1);
LINK link;
VarArg varargs;
auto o = (*e.args)[0];
FuncDeclaration fd;
TypeFunction tf = toTypeFunction(o, fd);
if (tf)
{
link = tf.linkage;
varargs = tf.parameterList.varargs;
}
else
{
if (!fd)
{
e.error("argument to `__traits(getFunctionVariadicStyle, %s)` is not a function", o.toChars());
return new ErrorExp();
}
link = fd.linkage;
varargs = fd.getParameterList().varargs;
}
string style;
final switch (varargs)
{
case VarArg.none: style = "none"; break;
case VarArg.variadic: style = (link == LINK.d)
? "argptr"
: "stdarg"; break;
case VarArg.typesafe: style = "typesafe"; break;
}
auto se = new StringExp(e.loc, style);
return se.expressionSemantic(sc);
}
if (e.ident == Id.getParameterStorageClasses)
{
/* Accept a function symbol or a type, followed by a parameter index.
* Returns a tuple of strings of the parameter's storage classes.
*/
// get symbol linkage as a string
if (dim != 2)
return dimError(2);
auto o = (*e.args)[0];
auto o1 = (*e.args)[1];
FuncDeclaration fd;
TypeFunction tf = toTypeFunction(o, fd);
ParameterList fparams;
if (tf)
fparams = tf.parameterList;
else if (fd)
fparams = fd.getParameterList();
else
{
e.error("first argument to `__traits(getParameterStorageClasses, %s, %s)` is not a function",
o.toChars(), o1.toChars());
return new ErrorExp();
}
StorageClass stc;
// Set stc to storage class of the ith parameter
auto ex = isExpression((*e.args)[1]);
if (!ex)
{
e.error("expression expected as second argument of `__traits(getParameterStorageClasses, %s, %s)`",
o.toChars(), o1.toChars());
return new ErrorExp();
}
ex = ex.ctfeInterpret();
auto ii = ex.toUInteger();
if (ii >= fparams.length)
{
e.error("parameter index must be in range 0..%u not %s", cast(uint)fparams.length, ex.toChars());
return new ErrorExp();
}
uint n = cast(uint)ii;
Parameter p = fparams[n];
stc = p.storageClass;
// This mirrors hdrgen.visit(Parameter p)
if (p.type && p.type.mod & MODFlags.shared_)
stc &= ~STC.shared_;
auto exps = new Expressions;
void push(string s)
{
exps.push(new StringExp(e.loc, s));
}
if (stc & STC.auto_)
push("auto");
if (stc & STC.return_)
push("return");
if (stc & STC.out_)
push("out");
else if (stc & STC.ref_)
push("ref");
else if (stc & STC.in_)
push("in");
else if (stc & STC.lazy_)
push("lazy");
else if (stc & STC.alias_)
push("alias");
if (stc & STC.const_)
push("const");
if (stc & STC.immutable_)
push("immutable");
if (stc & STC.wild)
push("inout");
if (stc & STC.shared_)
push("shared");
if (stc & STC.scope_ && !(stc & STC.scopeinferred))
push("scope");
auto tup = new TupleExp(e.loc, exps);
return tup.expressionSemantic(sc);
}
if (e.ident == Id.getLinkage)
{
// get symbol linkage as a string
if (dim != 1)
return dimError(1);
LINK link;
auto o = (*e.args)[0];
FuncDeclaration fd;
TypeFunction tf = toTypeFunction(o, fd);
if (tf)
link = tf.linkage;
else
{
auto s = getDsymbol(o);
Declaration d;
AggregateDeclaration agg;
if (!s || ((d = s.isDeclaration()) is null && (agg = s.isAggregateDeclaration()) is null))
{
e.error("argument to `__traits(getLinkage, %s)` is not a declaration", o.toChars());
return new ErrorExp();
}
if (d !is null)
link = d.linkage;
else final switch (agg.classKind)
{
case ClassKind.d:
link = LINK.d;
break;
case ClassKind.cpp:
link = LINK.cpp;
break;
case ClassKind.objc:
link = LINK.objc;
break;
}
}
auto linkage = linkageToChars(link);
auto se = new StringExp(e.loc, linkage.toDString());
return se.expressionSemantic(sc);
}
if (e.ident == Id.allMembers ||
e.ident == Id.derivedMembers)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbol(o);
if (!s)
{
e.error("argument has no members");
return new ErrorExp();
}
if (auto imp = s.isImport())
{
// https://issues.dlang.org/show_bug.cgi?id=9692
s = imp.mod;
}
auto sds = s.isScopeDsymbol();
if (!sds || sds.isTemplateDeclaration())
{
e.error("%s `%s` has no members", s.kind(), s.toChars());
return new ErrorExp();
}
auto idents = new Identifiers();
int pushIdentsDg(size_t n, Dsymbol sm)
{
if (!sm)
return 1;
// skip local symbols, such as static foreach loop variables
if (auto decl = sm.isDeclaration())
{
if (decl.storage_class & STC.local)
{
return 0;
}
}
//printf("\t[%i] %s %s\n", i, sm.kind(), sm.toChars());
if (sm.ident)
{
const idx = sm.ident.toChars();
if (idx[0] == '_' &&
idx[1] == '_' &&
sm.ident != Id.ctor &&
sm.ident != Id.dtor &&
sm.ident != Id.__xdtor &&
sm.ident != Id.postblit &&
sm.ident != Id.__xpostblit)
{
return 0;
}
if (sm.ident == Id.empty)
{
return 0;
}
if (sm.isTypeInfoDeclaration()) // https://issues.dlang.org/show_bug.cgi?id=15177
return 0;
if (!sds.isModule() && sm.isImport()) // https://issues.dlang.org/show_bug.cgi?id=17057
return 0;
//printf("\t%s\n", sm.ident.toChars());
/* Skip if already present in idents[]
*/
foreach (id; *idents)
{
if (id == sm.ident)
return 0;
// Avoid using strcmp in the first place due to the performance impact in an O(N^2) loop.
debug
{
import core.stdc.string : strcmp;
assert(strcmp(id.toChars(), sm.ident.toChars()) != 0);
}
}
idents.push(sm.ident);
}
else if (auto ed = sm.isEnumDeclaration())
{
ScopeDsymbol._foreach(null, ed.members, &pushIdentsDg);
}
return 0;
}
ScopeDsymbol._foreach(sc, sds.members, &pushIdentsDg);
auto cd = sds.isClassDeclaration();
if (cd && e.ident == Id.allMembers)
{
if (cd.semanticRun < PASS.semanticdone)
cd.dsymbolSemantic(null); // https://issues.dlang.org/show_bug.cgi?id=13668
// Try to resolve forward reference
void pushBaseMembersDg(ClassDeclaration cd)
{
for (size_t i = 0; i < cd.baseclasses.dim; i++)
{
auto cb = (*cd.baseclasses)[i].sym;
assert(cb);
ScopeDsymbol._foreach(null, cb.members, &pushIdentsDg);
if (cb.baseclasses.dim)
pushBaseMembersDg(cb);
}
}
pushBaseMembersDg(cd);
}
// Turn Identifiers into StringExps reusing the allocated array
assert(Expressions.sizeof == Identifiers.sizeof);
auto exps = cast(Expressions*)idents;
foreach (i, id; *idents)
{
auto se = new StringExp(e.loc, id.toString());
(*exps)[i] = se;
}
/* Making this a tuple is more flexible, as it can be statically unrolled.
* To make an array literal, enclose __traits in [ ]:
* [ __traits(allMembers, ...) ]
*/
Expression ex = new TupleExp(e.loc, exps);
ex = ex.expressionSemantic(sc);
return ex;
}
if (e.ident == Id.compiles)
{
/* Determine if all the objects - types, expressions, or symbols -
* compile without error
*/
if (!dim)
return False();
foreach (o; *e.args)
{
uint errors = global.startGagging();
Scope* sc2 = sc.push();
sc2.tinst = null;
sc2.minst = null;
sc2.flags = (sc.flags & ~(SCOPE.ctfe | SCOPE.condition)) | SCOPE.compile | SCOPE.fullinst;
bool err = false;
auto t = isType(o);
while (t)
{
if (auto tm = t.isTypeMixin())
{
/* The mixin string could be a type or an expression.
* Have to try compiling it to see.
*/
OutBuffer buf;
if (expressionsToString(buf, sc, tm.exps))
{
err = true;
break;
}
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(e.loc, sc._module, str, false, diagnosticReporter);
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);
o = p.parseTypeOrAssignExp();
if (p.errors ||
p.token.value != TOK.endOfFile)
{
err = true;
break;
}
t = o.isType();
}
else
break;
}
if (!err)
{
auto ex = t ? t.typeToExpression() : isExpression(o);
if (!ex && t)
{
Dsymbol s;
t.resolve(e.loc, sc2, &ex, &t, &s);
if (t)
{
t.typeSemantic(e.loc, sc2);
if (t.ty == Terror)
err = true;
}
else if (s && s.errors)
err = true;
}
if (ex)
{
ex = ex.expressionSemantic(sc2);
ex = resolvePropertiesOnly(sc2, ex);
ex = ex.optimize(WANTvalue);
if (sc2.func && sc2.func.type.ty == Tfunction)
{
const tf = cast(TypeFunction)sc2.func.type;
err |= tf.isnothrow && canThrow(ex, sc2.func, false);
}
ex = checkGC(sc2, ex);
if (ex.op == TOK.error)
err = true;
}
}
// Carefully detach the scope from the parent and throw it away as
// we only need it to evaluate the expression
// https://issues.dlang.org/show_bug.cgi?id=15428
sc2.detach();
if (global.endGagging(errors) || err)
{
return False();
}
}
return True();
}
if (e.ident == Id.isSame)
{
/* Determine if two symbols are the same
*/
if (dim != 2)
return dimError(2);
if (!TemplateInstance.semanticTiargs(e.loc, sc, e.args, 0))
return new ErrorExp();
auto o1 = (*e.args)[0];
auto o2 = (*e.args)[1];
static FuncLiteralDeclaration isLambda(RootObject oarg)
{
if (auto t = isDsymbol(oarg))
{
if (auto td = t.isTemplateDeclaration())
{
if (td.members && td.members.dim == 1)
{
if (auto fd = (*td.members)[0].isFuncLiteralDeclaration())
return fd;
}
}
}
else if (auto ea = isExpression(oarg))
{
if (ea.op == TOK.function_)
{
if (auto fe = cast(FuncExp)ea)
return fe.fd;
}
}
return null;
}
auto l1 = isLambda(o1);
auto l2 = isLambda(o2);
if (l1 && l2)
{
import dmd.lambdacomp : isSameFuncLiteral;
if (isSameFuncLiteral(l1, l2, sc))
return True();
}
// issue 12001, allow isSame, <BasicType>, <BasicType>
Type t1 = isType(o1);
Type t2 = isType(o2);
if (t1 && t2 && t1.equals(t2))
return True();
auto s1 = getDsymbol(o1);
auto s2 = getDsymbol(o2);
//printf("isSame: %s, %s\n", o1.toChars(), o2.toChars());
version (none)
{
printf("o1: %p\n", o1);
printf("o2: %p\n", o2);
if (!s1)
{
if (auto ea = isExpression(o1))
printf("%s\n", ea.toChars());
if (auto ta = isType(o1))
printf("%s\n", ta.toChars());
return False();
}
else
printf("%s %s\n", s1.kind(), s1.toChars());
}
if (!s1 && !s2)
{
auto ea1 = isExpression(o1);
auto ea2 = isExpression(o2);
if (ea1 && ea2)
{
if (ea1.equals(ea2))
return True();
}
}
if (!s1 || !s2)
return False();
s1 = s1.toAlias();
s2 = s2.toAlias();
if (auto fa1 = s1.isFuncAliasDeclaration())
s1 = fa1.toAliasFunc();
if (auto fa2 = s2.isFuncAliasDeclaration())
s2 = fa2.toAliasFunc();
// https://issues.dlang.org/show_bug.cgi?id=11259
// compare import symbol to a package symbol
static bool cmp(Dsymbol s1, Dsymbol s2)
{
auto imp = s1.isImport();
return imp && imp.pkg && imp.pkg == s2.isPackage();
}
if (cmp(s1,s2) || cmp(s2,s1))
return True();
if (s1 == s2)
return True();
// https://issues.dlang.org/show_bug.cgi?id=18771
// OverloadSets are equal if they contain the same functions
auto overSet1 = s1.isOverloadSet();
if (!overSet1)
return False();
auto overSet2 = s2.isOverloadSet();
if (!overSet2)
return False();
if (overSet1.a.dim != overSet2.a.dim)
return False();
// OverloadSets contain array of Dsymbols => O(n*n)
// to compare for equality as the order of overloads
// might not be the same
Lnext:
foreach(overload1; overSet1.a)
{
foreach(overload2; overSet2.a)
{
if (overload1 == overload2)
continue Lnext;
}
return False();
}
return True();
}
if (e.ident == Id.getUnitTests)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbolWithoutExpCtx(o);
if (!s)
{
e.error("argument `%s` to __traits(getUnitTests) must be a module or aggregate",
o.toChars());
return new ErrorExp();
}
if (auto imp = s.isImport()) // https://issues.dlang.org/show_bug.cgi?id=10990
s = imp.mod;
auto sds = s.isScopeDsymbol();
if (!sds)
{
e.error("argument `%s` to __traits(getUnitTests) must be a module or aggregate, not a %s",
s.toChars(), s.kind());
return new ErrorExp();
}
auto exps = new Expressions();
if (global.params.useUnitTests)
{
bool[void*] uniqueUnitTests;
void symbolDg(Dsymbol s)
{
if (auto ad = s.isAttribDeclaration())
{
ad.include(null).foreachDsymbol(&symbolDg);
}
else if (auto ud = s.isUnitTestDeclaration())
{
if (cast(void*)ud in uniqueUnitTests)
return;
uniqueUnitTests[cast(void*)ud] = true;
auto ad = new FuncAliasDeclaration(ud.ident, ud, false);
ad.protection = ud.protection;
auto e = new DsymbolExp(Loc.initial, ad, false);
exps.push(e);
}
}
sds.members.foreachDsymbol(&symbolDg);
}
auto te = new TupleExp(e.loc, exps);
return te.expressionSemantic(sc);
}
if (e.ident == Id.getVirtualIndex)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto s = getDsymbolWithoutExpCtx(o);
auto fd = s ? s.isFuncDeclaration() : null;
if (!fd)
{
e.error("first argument to __traits(getVirtualIndex) must be a function");
return new ErrorExp();
}
fd = fd.toAliasFunc(); // Necessary to support multiple overloads.
return new IntegerExp(e.loc, fd.vtblIndex, Type.tptrdiff_t);
}
if (e.ident == Id.getPointerBitmap)
{
return pointerBitmap(e);
}
if (e.ident == Id.isZeroInit)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
Type t = isType(o);
if (!t)
{
e.error("type expected as second argument of __traits `%s` instead of `%s`",
e.ident.toChars(), o.toChars());
return new ErrorExp();
}
Type tb = t.baseElemOf();
return tb.isZeroInit(e.loc) ? True() : False();
}
if (e.ident == Id.getTargetInfo)
{
if (dim != 1)
return dimError(1);
auto ex = isExpression((*e.args)[0]);
StringExp se = ex ? ex.ctfeInterpret().toStringExp() : null;
if (!ex || !se || se.len == 0)
{
e.error("string expected as argument of __traits `%s` instead of `%s`", e.ident.toChars(), ex.toChars());
return new ErrorExp();
}
se = se.toUTF8(sc);
const slice = se.peekString();
Expression r = target.getTargetInfo(slice.ptr, e.loc); // BUG: reliance on terminating 0
if (!r)
{
e.error("`getTargetInfo` key `\"%.*s\"` not supported by this implementation",
cast(int)slice.length, slice.ptr);
return new ErrorExp();
}
return r.expressionSemantic(sc);
}
if (e.ident == Id.getLocation)
{
if (dim != 1)
return dimError(1);
auto arg0 = (*e.args)[0];
Dsymbol s = getDsymbolWithoutExpCtx(arg0);
if (!s || !s.loc.isValid())
{
e.error("can only get the location of a symbol, not `%s`", arg0.toChars());
return new ErrorExp();
}
const fd = s.isFuncDeclaration();
// FIXME:td.overnext is always set, even when using an index on it
//const td = s.isTemplateDeclaration();
if ((fd && fd.overnext) /*|| (td && td.overnext)*/)
{
e.error("cannot get location of an overload set, " ~
"use `__traits(getOverloads, ..., \"%s\"%s)[N]` " ~
"to get the Nth overload",
arg0.toChars(), /*td ? ", true".ptr :*/ "".ptr);
return new ErrorExp();
}
auto exps = new Expressions(3);
(*exps)[0] = new StringExp(e.loc, s.loc.filename.toDString());
(*exps)[1] = new IntegerExp(e.loc, s.loc.linnum,Type.tint32);
(*exps)[2] = new IntegerExp(e.loc, s.loc.charnum,Type.tint32);
auto tup = new TupleExp(e.loc, exps);
return tup.expressionSemantic(sc);
}
static const(char)[] trait_search_fp(const(char)[] seed, ref int cost)
{
//printf("trait_search_fp('%s')\n", seed);
if (!seed.length)
return null;
cost = 0;
const sv = traitsStringTable.lookup(seed);
return sv ? sv.toString() : null;
}
if (auto sub = speller!trait_search_fp(e.ident.toString()))
e.error("unrecognized trait `%s`, did you mean `%.*s`?", e.ident.toChars(), sub.length, sub.ptr);
else
e.error("unrecognized trait `%s`", e.ident.toChars());
return new ErrorExp();
}
| D |
module source.swar.bin;
/**
* Check we have enough digits in front of us to use SWAR.
*/
bool startsWith8BinDigits(string s, ref ulong state) {
import source.swar.util;
auto v = read!ulong(s);
// If the input is valid, make it all '1's.
state = v | 0x0101010101010101;
return state == 0x3131313131313131;
}
bool hasMoreDigits(ulong state) {
return (state & 0xff) == 0x31;
}
uint getDigitCount(ulong state) in(state != 0x3131313131313131) {
state ^= 0x3131313131313131;
state |= state + 0x7f7f7f7f7f7f7f7f;
state &= 0x8080808080808080;
import core.bitop, util.math;
return bsf(mulhi(state, 0x0204081020408100));
}
unittest {
static check(string s, uint count) {
ulong state;
if (startsWith8BinDigits(s, state)) {
assert(count >= 8);
} else {
assert(hasMoreDigits(state) == (count > 0));
assert(getDigitCount(state) == count);
}
}
check("", 0);
static bool isBinChar(char c) {
return c == '0' || c == '1';
}
// Test all combinations of 2 characters.
foreach (char c0; 0 .. 256) {
immutable char[1] s0 = [c0];
auto isC0Bin = isBinChar(c0);
check(s0[], isC0Bin);
foreach (char c1; 0 .. 256) {
immutable char[2] s1 = [c0, c1];
auto isC1Bin = isBinChar(c1);
check(s1[], isC0Bin + (isC0Bin && isC1Bin));
static immutable char[] Chars = ['0', '1'];
foreach (char c3; Chars) {
foreach (char c4; Chars) {
immutable char[4] s2 = [c0, c1, c3, c4];
check(s2[], isC0Bin + 3 * (isC0Bin && isC1Bin));
immutable char[4] s3 = [c4, c3, c1, c0];
check(s3[], 2 + isC1Bin + (isC0Bin && isC1Bin));
immutable char[8] s4 = [c0, c1, c0, c1, c0, c1, c3, c4];
check(s4[], isC0Bin + 7 * (isC0Bin && isC1Bin));
immutable char[8] s5 = [c4, c3, c3, c4, c3, c4, c1, c0];
check(s5[], 6 + isC1Bin + (isC0Bin && isC1Bin));
}
}
}
}
}
/**
* Parse binary numbers using SWAR.
*/
private ubyte computeValue(ulong v) {
v &= 0x0101010101010101;
v *= 0x8040201008040201;
return v >> 56;
}
ubyte decodeBinDigits(string s) in(s.length >= 8) {
import source.swar.util;
auto v = unalignedLoad!ulong(s);
return computeValue(v);
}
unittest {
foreach (s, v;
["00000000": 0x00, "01001001": 0x49, "01010101": 0x55, "10101010": 0xaa,
"11000000": 0xc0, "11100111": 0xe7, "11011011": 0xdb, "11111111": 0xff]
) {
ulong state;
assert(startsWith8BinDigits(s, state), s);
assert(decodeBinDigits(s) == v, s);
}
}
ubyte decodeBinDigits(string s, uint count) in(count < 8 && s.length >= count) {
import source.swar.util;
auto v = read!ulong(s);
return computeValue(v) >> (8 - count);
}
unittest {
foreach (s, v;
["0000a000": 0x00, "001001P0": 0x09, "1010101+": 0x55, "101010^!": 0x2a,
"1000011z": 0x43, "1011011": 0x5b, "1111111": 0x7f]) {
ulong state;
assert(!startsWith8BinDigits(s, state), s);
assert(hasMoreDigits(state));
assert(decodeBinDigits(s, getDigitCount(state)) == v, s);
}
}
| D |
/Users/abelfernandez/projects/vapor-server/Hello/.build/debug/FluentTester.build/Tester.swift.o : /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Schema.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+InsertAndFind.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Compound.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Paginate.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+SoftDelete.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Chunk.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Atom.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Transaction.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Utilities.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+PivotsAndRelations.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Timestamps.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+CustomKeys.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Student.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Index.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+ForeignKey.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/libc.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Node.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/PathIndexable.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Core.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/SQLite.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Debugging.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Fluent.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/sqlite.git--8232814251736334455/Sources/CSQLite/include/sqlite3.h /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CHTTP.build/module.modulemap /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CSQLite.build/module.modulemap
/Users/abelfernandez/projects/vapor-server/Hello/.build/debug/FluentTester.build/Tester~partial.swiftmodule : /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Schema.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+InsertAndFind.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Compound.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Paginate.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+SoftDelete.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Chunk.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Atom.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Transaction.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Utilities.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+PivotsAndRelations.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Timestamps.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+CustomKeys.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Student.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Index.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+ForeignKey.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/libc.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Node.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/PathIndexable.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Core.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/SQLite.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Debugging.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Fluent.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/sqlite.git--8232814251736334455/Sources/CSQLite/include/sqlite3.h /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CHTTP.build/module.modulemap /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CSQLite.build/module.modulemap
/Users/abelfernandez/projects/vapor-server/Hello/.build/debug/FluentTester.build/Tester~partial.swiftdoc : /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Schema.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+InsertAndFind.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Compound.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Paginate.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+SoftDelete.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Chunk.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Atom.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Transaction.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Utilities.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+PivotsAndRelations.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Timestamps.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+CustomKeys.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Student.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+Index.swift /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/fluent.git-6251908308727715749/Sources/FluentTester/Tester+ForeignKey.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/libc.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Node.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/PathIndexable.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Core.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/SQLite.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Debugging.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/Fluent.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/abelfernandez/projects/vapor-server/Hello/.build/checkouts/sqlite.git--8232814251736334455/Sources/CSQLite/include/sqlite3.h /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CHTTP.build/module.modulemap /Users/abelfernandez/projects/vapor-server/Hello/.build/debug/CSQLite.build/module.modulemap
| D |
module armos.utils.gui.widgets.label;
import armos.utils.gui.widgets.widget;
/++
文字列を表示するWidgetを継承したclassです.
+/
class Label : Widget{
public{
/++
表示する文字列を指定して初期化を行います.
+/
this(string str){
_str = str;
_height = 16;
};
/++
+/
override void draw(){
import armos.graphics.renderer:color,
drawRectangle;
color(_style.colors["background"]);
drawRectangle(0, 0, _style.width, _style.font.height*2);
_style.font.material.uniform("diffuse", _style.colors["font1"]);
_style.font.draw(_str, _style.font.width, 0);
};
}//public
private{
string _str;
}//private
}//class Label
| D |
// Copyright Steve Teale 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Written in the D programming language
module rgradient;
import mainwin;
import constants;
import acomp;
import common;
import types;
import controlset;
import mol;
import std.stdio;
import std.math;
import std.conv;
import gtk.Widget;
import gtk.Label;
import gtk.Button;
import gtk.SpinButton;
import gtk.CheckButton;
import gtk.ComboBoxText;
import gdk.RGBA;
import cairo.Context;
import cairo.Pattern;
import gtkc.cairotypes;
class RGradient: ACBase
{
static int nextOid = 0;
double outrad, inrad;
double[50] opStops;
Coord center;
int nStops;
double maxOpacity;
bool mark, revfade;
int gType;
Pattern pat;
Label ov;
CheckButton outlineCB;
override void syncControls()
{
cSet.toggling(false);
cSet.setToggle(Purpose.SOLID, mark);
cSet.toggling(true);
cSet.setHostName(name);
}
this(RGradient other)
{
this(other.aw, other.parent);
hOff = other.hOff;
vOff = other.vOff;
baseColor = other.baseColor.copy();
outrad = other.outrad;
inrad = other.inrad;
gType = other.gType;
nStops = other.nStops;
center = other.center;
maxOpacity= other.maxOpacity;
mark = other.mark;
revfade = other.revfade;
setupStops();
syncControls();
}
this(AppWindow w, ACBase parent)
{
mixin(initString!RGradient());
super(w, parent, sname, AC_RGRADIENT, ACGroups.EFFECTS, ahdg);
baseColor = new RGBA(1,1,1);
maxOpacity = 1.0;
gType = 0;
nStops = 50;
center.x = width/2;
center.y = height/2;
if (width > height)
{
outrad = 0.5*height;
inrad = 0.3*height;
}
else
{
outrad = 0.5*width;
inrad = 0.3*width;
}
setupControls();
positionControls(true);
mark = true;
revfade = false;
setupStops();
}
override int getNextOid()
{
return ++nextOid;
}
override void extendControls()
{
int vp = cSet.cy;
Button b = new Button("Color");
cSet.add(b, ICoord(0, vp), Purpose.COLOR);
Label l = new Label("Max Opacity");
cSet.add(l, ICoord(163, vp), Purpose.LABEL);
new MoreLess(cSet, 0, ICoord(270, vp), true);
ov = new Label("1.0");
cSet.add(ov, ICoord(310, vp), Purpose.LABEL);
vp += 30;
CheckButton cb = new CheckButton("Show Guidelines");
cb.setActive(1);
cSet.add(cb, ICoord(0, vp), Purpose.SOLID);
l = new Label("Inner Radius");
l.setTooltipText("Adjust the radius at which the gradient starts");
cSet.add(l, ICoord(177, vp+3), Purpose.LABEL);
new MoreLess(cSet, 1, ICoord(270, vp+3), true);
l = new Label("Outer Radius");
l.setTooltipText("Adjust the radius at which the gradient ends");
cSet.add(l, ICoord(177, vp+23), Purpose.LABEL);
new MoreLess(cSet, 2, ICoord(270, vp+23), true);
vp += 25;
new InchTool(cSet, 0, ICoord(0, vp), true);
vp += 20;
l = new Label("Gradient Rule");
cSet.add(l, ICoord(95, vp+5), Purpose.LABEL);
ComboBoxText cbb = new ComboBoxText(false);
cbb.setTooltipText("Select Gradient Type");
cbb.setSizeRequest(148, -1);
cbb.appendText("Gamma 2.2");
cbb.appendText("Gamma 1.5");
cbb.appendText("Gamma 3.0");
cbb.appendText("Cosine 90");
cbb.appendText("Cosine 180");
cbb.appendText("Exponential");
cbb.appendText("Linear");
cbb.appendText("Bezier");
cbb.setActive(0);
cSet.add(cbb, ICoord(195, vp), Purpose.PATTERN);
vp += 30;
cb = new CheckButton("Reverse fade");
cSet.add(cb, ICoord(0, vp), Purpose.FADELEFT);
cSet.cy = vp+30;
}
override void afterDeserialize()
{
cSet.setComboIndex(Purpose.PATTERN, gType);
setupStops();
}
override void preResize(int oldW, int oldH)
{
if (width > height)
outrad = height;
else
outrad = width;
}
override bool notifyHandler(Widget w, Purpose p)
{
switch (p)
{
case Purpose.SOLID:
mark = !mark;
break;
case Purpose.FADELEFT:
revfade = !revfade;
dirty = true;
break;
case Purpose.PATTERN:
gType = (cast(ComboBoxText) w).getActive();
dirty = true;
break;
default:
return false;
}
return true;
}
override bool undoHandler(CheckPoint cp)
{
switch (cp.type)
{
case OP_OPACITY:
maxOpacity = cp.dVal;
break;
case OP_VSIZE:
inrad = cp.dVal;
break;
case OP_HSIZE:
outrad = cp.dVal;
break;
default:
return false;
}
dirty = true;
lastOp = OP_UNDEF;
return true;
}
override void onCSMoreLess(int instance, bool more, bool quickly)
{
focusLayout();
dirty = true;
switch (instance)
{
case 0:
double result = maxOpacity;
if (!molA!double(more, quickly, result, 0.01, 0, 1))
return;
lastOp = pushC!double(this, maxOpacity, OP_OPACITY);
maxOpacity = result;
string t = to!string(maxOpacity);
if (t.length > 4)
t = t[0..4];
ov.setText(t);
break;
case 1:
double result = inrad;
if (!molA!double(more, quickly, result, 0.5, 5, outrad))
return;
lastOp = pushC!double(this, inrad, OP_VSIZE);
inrad = result;
break;
case 2:
double result = outrad;
if (!molA!double(more, quickly, result, 0.5, 5, 1000))
return;
lastOp = pushC!double(this, outrad, OP_HSIZE);
outrad = result;
break;
default:
dirty = false;
return;
}
aw.dirty = true;
reDraw();
}
void setupStops()
{
double delta = 1.0/nStops;
void gtkDefault()
{
opStops[0] = double.init;
}
void linear()
{
double op = 1;
for (int i = 0; i < nStops; i++)
{
opStops[i] = op;
op -= delta;
}
}
void gamma(double g)
{
double x = 0;
for (int i = 0; i < nStops; i++)
{
opStops[i] = 1-pow(x, g);
x += delta;
}
}
void cosine90()
{
double a = 0;
double op;
for (int i=0; i < nStops; i++)
{
op = cos(a);
opStops[i] = op;
a += PI/2/nStops;
}
}
void cosine180()
{
double a = 0;
double op;
for (int i=0; i < nStops; i++)
{
op = cos(a);
opStops[i] = (op+1)/2;
a += PI/nStops;
}
}
Coord bezierPoint(double t, Coord p0, Coord p1, Coord p2)
{
Coord c;
c.x = pow(1-t, 2) * p0.x + 2 * (1-t) * t * p1.x + pow(t, 2) * p2.x;
c.y = pow(1-t, 2) * p0.y + 2 * (1-t) * t * p1.y + pow(t, 2) * p2.y;
return c;
}
void quadbezier(double x, double y)
{
Coord start = Coord(0, 1), end = Coord(1, 0), control = Coord(x, y);
double t = 0;
for (int i = 0; i < nStops; i++)
{
Coord a = bezierPoint(t, start, control, end);
opStops[i] = a.y;
t += delta;
}
}
void exponential(double howClose)
{
double x = 0;
double op;
for (int i=0; i < nStops; i++)
{
op = exp(x);
opStops[i] = op;
x -= howClose;
}
}
switch (gType)
{
case 0:
gamma(2.2);
break;
case 1:
gamma(1.5);
break;
case 2:
gamma(3.0);
break;
case 3:
cosine90();
break;
case 4:
cosine180();
break;
case 5:
exponential(0.02);
break;
case 6:
quadbezier(0.8, 0);
break;
default:
gtkDefault();
break;
}
}
void addStops(double r, double g, double b)
{
double offset = 0;
if (revfade)
{
if (isNaN(opStops[0]))
{
pat.addColorStopRgba (0, r, g, b, 0);
pat.addColorStopRgba (1, r, g, b, 1);
return;
}
for (int i = 49; i >= 0; i--)
{
pat.addColorStopRgba (offset, r, g, b, opStops[i]*maxOpacity);
offset += 0.02;
}
}
else
{
if (isNaN(opStops[0]))
{
pat.addColorStopRgba (0, r, g, b, 1);
pat.addColorStopRgba (1, r, g, b, 0);
return;
}
for (int i = 0; i < nStops; i++)
{
pat.addColorStopRgba (offset, r, g, b, opStops[i]*maxOpacity);
offset += 0.02;
}
}
}
void createPattern()
{
pat = Pattern.createRadial(hOff+center.x, vOff+center.y, inrad, hOff+center.x, vOff+center.y, outrad);
}
override void render(Context c)
{
if (dirty)
{
setupStops();
dirty = false;
}
createPattern();
double r = baseColor.red();
double g = baseColor.green();
double b = baseColor.blue();
addStops(r, g, b);
c.rectangle(hOff, vOff, width, height);
c.setSource(pat);
c.fill();
double[2] da = [2,2];
if (!printFlag && mark)
{
c.save();
c.setDash(da, 0);
c.setOperator(CairoOperator.SOURCE);
c.setSourceRgb(0,0,0);
c.moveTo(hOff+center.x-10, vOff+center.y);
c.lineTo(hOff+center.x+10, vOff+center.y);
c.moveTo(hOff+center.x, vOff+center.y-10);
c.lineTo(hOff+center.x, vOff+center.y+10);
c.setLineWidth(1);
c.stroke();
c.arc(hOff+center.x, vOff+center.y, inrad, 0, 2*PI);
c.stroke();
c.arc(hOff+center.x, vOff+center.y, outrad, 0, 2*PI);
c.stroke();
c.setSourceRgb(1,1,1);
c.setDash(da, 2);
c.moveTo(hOff+center.x-10, vOff+center.y);
c.lineTo(hOff+center.x+10, vOff+center.y);
c.moveTo(hOff+center.x, vOff+center.y-10);
c.lineTo(hOff+center.x, vOff+center.y+10);
c.setLineWidth(1);
c.stroke();
c.arc(hOff+center.x, vOff+center.y, inrad, 0, 2*PI);
c.stroke();
c.arc(hOff+center.x, vOff+center.y, outrad, 0, 2*PI);
c.stroke();
c.restore();
}
}
}
| D |
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Port to the D programming language:
* Frank Benoit <[email protected]>
*******************************************************************************/
module org.eclipse.swt.events.TreeAdapter;
import org.eclipse.swt.events.TreeListener;
/**
* This adapter class provides default implementations for the
* methods described by the <code>TreeListener</code> interface.
* <p>
* Classes that wish to deal with <code>TreeEvent</code>s can
* extend this class and override only the methods which they are
* interested in.
* </p>
*
* @see TreeListener
* @see TreeEvent
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/
public abstract class TreeAdapter : TreeListener {
/**
* Sent when a tree branch is collapsed.
* The default behavior is to do nothing.
*
* @param e an event containing information about the tree operation
*/
public void treeCollapsed(TreeEvent e) {
}
/**
* Sent when a tree branch is expanded.
* The default behavior is to do nothing.
*
* @param e an event containing information about the tree operation
*/
public void treeExpanded(TreeEvent e) {
}
}
| D |
module android.java.android.app.TabActivity;
public import android.java.android.app.TabActivity_d_interface;
import arsd.jni : ImportExportImpl;
mixin ImportExportImpl!TabActivity;
import import6 = android.java.android.view.WindowManager;
import import5 = android.java.android.app.Application;
import import46 = android.java.android.content.ComponentName;
import import7 = android.java.android.view.Window;
import import85 = android.java.android.content.res.ColorStateList;
import import24 = android.java.android.app.FragmentManager;
import import28 = android.java.android.app.ActionBar;
import import4 = android.java.android.content.Intent;
import import3 = android.java.android.app.LocalActivityManager;
import import71 = android.java.java.io.FileOutputStream;
import import8 = android.java.android.app.LoaderManager;
import import47 = android.java.android.app.PendingIntent;
import import9 = android.java.android.view.View;
import import61 = android.java.android.content.res.AssetManager;
import import2 = android.java.android.app.Activity;
import import59 = android.java.android.view.DragAndDropPermissions;
import import0 = android.java.android.widget.TabHost;
import import67 = android.java.java.util.concurrent.Executor;
import import26 = android.java.android.database.Cursor;
import import65 = android.java.android.content.ContentResolver;
import import66 = android.java.android.os.Looper;
import import72 = android.java.java.io.File;
import import1 = android.java.android.widget.TabWidget;
import import56 = android.java.android.view.ActionMode;
import import68 = android.java.java.lang.ClassLoader;
import import73 = android.java.android.database.sqlite.SQLiteDatabase;
import import64 = android.java.android.content.pm.PackageManager;
import import32 = android.java.android.transition.Scene;
import import43 = android.java.android.view.LayoutInflater;
import import44 = android.java.android.view.MenuInflater;
import import70 = android.java.java.io.FileInputStream;
import import16 = android.java.java.lang.CharSequence;
import import62 = android.java.android.content.res.Resources;
import import48 = android.java.android.content.SharedPreferences;
import import31 = android.java.android.transition.TransitionManager;
import import86 = android.java.android.content.res.TypedArray;
import import13 = android.java.android.app.VoiceInteractor;
import import69 = android.java.android.content.pm.ApplicationInfo;
| D |
/Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Vapor.build/JSON/JSON.swift.o : /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Body+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+FormData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/FormData+Polymorphic.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/StructuredData+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/Request+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Command.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Log+Convenience.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringCharacterSequence.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Resource.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/HTTP+Node.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/AcceptLanguage.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cache/Config+Cache.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Configurable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSONRepresentable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/RequestInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Vapor+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/MediaType.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Config+Middleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Date/DateMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/File+Response.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Resolve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Serve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/DumpConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Config+ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoEncoding.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Droplet+Routing.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Config+Log.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RoutesLog.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Config+Hash.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogLevel.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Config+Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/ProviderInstall.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/HashProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CipherProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Int+Random.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Version.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSConfiguration.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RouteCollection.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Subscription.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Run.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mailgun.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Config+Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Responder.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileManager.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/ConsoleLogger.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/Config+Cipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoCipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/CryptoHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/BCryptHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/StaticViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/EngineServer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/SecurityLayer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/AbortError.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider+Resources.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Directories.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Bytes.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/InitProtocols.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Sessions/Config+Sessions.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Responder+Helpers.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/WebSockets/WebSockets.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Exports.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/EngineClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/FoundationClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Response+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Request+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Event.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/Accept.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+Multipart.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/Abort.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer+Request.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/Config+View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorView.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/Config+ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Config+ClientFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactory.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/URI.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/JSON.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/SMTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/HTTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/TLS.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/FormData.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/libc.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Node.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cache.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/PathIndexable.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Console.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Core.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Debugging.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Routing.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreFoundation.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Crypto.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Branches.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cookies.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Configs.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sessions.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/WebSockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/BCrypt.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Multipart.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Transport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/engine.git-3311994267206676365/Sources/CHTTP/include/http_parser.h /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/ctls.git-9210868160426949823/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CHTTP.build/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CSQLite.build/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/Darwin.apinotes
/Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Vapor.build/JSON~partial.swiftmodule : /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Body+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+FormData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/FormData+Polymorphic.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/StructuredData+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/Request+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Command.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Log+Convenience.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringCharacterSequence.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Resource.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/HTTP+Node.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/AcceptLanguage.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cache/Config+Cache.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Configurable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSONRepresentable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/RequestInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Vapor+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/MediaType.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Config+Middleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Date/DateMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/File+Response.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Resolve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Serve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/DumpConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Config+ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoEncoding.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Droplet+Routing.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Config+Log.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RoutesLog.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Config+Hash.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogLevel.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Config+Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/ProviderInstall.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/HashProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CipherProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Int+Random.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Version.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSConfiguration.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RouteCollection.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Subscription.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Run.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mailgun.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Config+Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Responder.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileManager.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/ConsoleLogger.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/Config+Cipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoCipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/CryptoHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/BCryptHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/StaticViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/EngineServer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/SecurityLayer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/AbortError.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider+Resources.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Directories.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Bytes.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/InitProtocols.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Sessions/Config+Sessions.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Responder+Helpers.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/WebSockets/WebSockets.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Exports.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/EngineClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/FoundationClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Response+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Request+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Event.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/Accept.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+Multipart.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/Abort.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer+Request.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/Config+View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorView.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/Config+ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Config+ClientFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactory.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/URI.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/JSON.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/SMTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/HTTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/TLS.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/FormData.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/libc.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Node.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cache.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/PathIndexable.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Console.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Core.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Debugging.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Routing.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreFoundation.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Crypto.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Branches.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cookies.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Configs.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sessions.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/WebSockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/BCrypt.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Multipart.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Transport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/engine.git-3311994267206676365/Sources/CHTTP/include/http_parser.h /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/ctls.git-9210868160426949823/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CHTTP.build/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CSQLite.build/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/Darwin.apinotes
/Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Vapor.build/JSON~partial.swiftdoc : /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Body+JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSON.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+FormData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewData.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/FormData+Polymorphic.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/StructuredData+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/FormURLEncoded/Request+FormURLEncoded.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Command.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Log+Convenience.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringCharacterSequence.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Resource.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/HTTP+Node.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/AcceptLanguage.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cache/Config+Cache.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Message+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/HTTP/Response+Codable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Configurable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/JSON/JSONRepresentable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/StringInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/RequestInitializable.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Config+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Vapor+Console.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/MediaType.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Config+Middleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Date/DateMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorMiddleware.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/File+Response.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Resolve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Serve.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/DumpConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/Config+ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Serve/ServerConfig.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoEncoding.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/Droplet+Routing.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/Config+Log.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RoutesLog.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Config+Hash.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogLevel.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Config+Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mail.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/ProviderInstall.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/LogProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/HashProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CipherProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactoryProtocol.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/Int+Random.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Commands/Version.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/CORS/CORSConfiguration.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Routing/RouteCollection.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Subscription.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Run.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Mail/Mailgun.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Config+Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet+Responder.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileManager.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Log/ConsoleLogger.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/Config+Cipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Cipher/CryptoCipher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/CryptoHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Hash/BCryptHasher.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/StaticViewRenderer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/EngineServer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/SecurityLayer.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/AbortError.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Provider/Provider+Resources.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Config/Directories.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Bytes.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/InitProtocols.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Sessions/Config+Sessions.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Responder+Helpers.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/WebSockets/WebSockets.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Utilities/Exports.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/EngineClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/FoundationClient.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Response+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Request+Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Content/Content.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Event/Event.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/HTTP/Accept.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Multipart/Request+Multipart.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/Abort.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/ViewRenderer+Request.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/Config+View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/View/View.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorView.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/Config+ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Server/ServerFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/Config+ClientFactory.swift /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Engine/Client/ClientFactory.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/URI.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/JSON.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/SMTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/HTTP.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/TLS.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/FormData.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/libc.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Node.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cache.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/PathIndexable.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Console.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Core.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Debugging.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Routing.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Random.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreFoundation.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Crypto.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Branches.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Cookies.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Configs.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sessions.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Sockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/WebSockets.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Bits.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/BCrypt.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Multipart.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/Transport.swiftmodule /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/engine.git-3311994267206676365/Sources/CHTTP/include/http_parser.h /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/checkouts/ctls.git-9210868160426949823/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CHTTP.build/module.modulemap /Users/AleixDiaz/Desktop/VaporProject/LaSalleChat/.build/x86_64-apple-macosx10.10/debug/CSQLite.build/module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/Darwin.apinotes
| D |
module android.java.android.renderscript.ScriptGroup_Builder2;
public import android.java.android.renderscript.ScriptGroup_Builder2_d_interface;
import arsd.jni : ImportExportImpl;
mixin ImportExportImpl!ScriptGroup_Builder2;
import import1 = android.java.android.renderscript.ScriptGroup_Input;
import import2 = android.java.android.renderscript.ScriptGroup_Closure;
import import8 = android.java.java.lang.Class;
import import6 = android.java.android.renderscript.ScriptGroup;
| D |
// Author: Ivan Kazmenko ([email protected])
import std.algorithm;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
int [] [] a;
foreach (i; 0..n)
{
a ~= readln.splitter.map !(to !(int)).array;
}
int res = 0;
foreach (i; 0..n)
{
res += a[i][i];
}
int rows = 0;
foreach (i; 0..n)
{
bool [int] s;
foreach (j; 0..n)
{
s[a[i][j]] = true;
}
rows += (s.length < n);
}
int cols = 0;
foreach (j; 0..n)
{
bool [int] s;
foreach (i; 0..n)
{
s[a[i][j]] = true;
}
cols += (s.length < n);
}
write ("Case #", test + 1, ":");
writeln (" ", res, " ", rows, " ", cols);
}
}
| D |
instance PAL_252_Parcival(Npc_Default)
{
name[0] = "Парсиваль";
guild = GIL_PAL;
id = 252;
voice = 13;
flags = 0;
npcType = NPCTYPE_OCMAIN;
B_SetAttributesToChapter(self,4);
fight_tactic = FAI_HUMAN_MASTER;
EquipItem(self,ItMw_1h_Pal_Sword);
B_CreateAmbientInv(self);
B_SetNpcVisual(self,MALE,"Hum_Head_Pony",Face_P_Tough_Drago,BodyTex_P,ItAr_PAl_H);
Mdl_SetModelFatness(self,0);
Mdl_ApplyOverlayMds(self,"Humans_Militia.mds");
B_GiveNpcTalents(self);
B_SetFightSkills(self,65);
daily_routine = Rtn_Start_252;
};
func void Rtn_Start_252()
{
TA_Smalltalk(8,0,21,0,"OC_EBR_HALL_CENTER");
TA_Sleep(21,0,8,0,"OC_EBR_ROOM_01_SLEEP");
};
| D |
//Written in the D programming language
/*
* MySQL database connection tool
*
* Copyright 2009-2013 Jaypha
*
* Distributed under the Boost Software License, Version 1.0.
* (See http://www.boost.org/LICENSE_1_0.txt)
*
* Authors: Jason den Dulk
*/
module jaypha.dbsql.mysql.database;
import jaypha.dbsql.mysql.c.mysql;
import jaypha.dbsql.exception;
import jaypha.algorithm;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
//-----------------------------------------------------------------------------
//
// Database
//
//-----------------------------------------------------------------------------
final class MySqlDatabase
{
alias MySQLRange ResultType;
string host;
string dbname;
string username;
string password = null;
uint port = 0;
//---------------------------------------------------------------------------
~this() { close(); }
//---------------------------------------------------------------------------
void connect()
{
if (mysql is null)
{
mysql = mysql_init(mysql);
if
(
mysql_real_connect
(
mysql,
toStringz(host),
toStringz(username),
toStringz(password),
toStringz(dbname),
port,
null,
0
) is null
)
{
throw new DBException(to!string(mysql_error(mysql)), mysql_errno(mysql), null);
}
}
}
//---------------------------------------------------------------------------
void close()
{
if (mysql !is null)
{
mysql_close(mysql);
mysql = null;
}
}
//---------------------------------------------------------------------------
string quote(string s)
{
if (s == "") { return "''"; }
if (s is null) { return "null"; }
char[] result;
result.length = s.length * 2+1;
if (mysql is null) connect();
// string doesn't need to be 0-term
result.length = mysql_real_escape_string
(
mysql,
result.ptr,
s.ptr,
s.length
);
if (mysql_errno(mysql) != 0)
throw new DBException(to!string(mysql_error(mysql)), mysql_errno(mysql), s);
return "'"~result.idup~"'";
}
//---------------------------------------------------------------------------
string inList(T)(T[] list)
{
if (list.empty) return ("0");
static if (is(T == string))
return "("~map!(a => quote(a))(list).join(",")~")";
else
return "("~map!(to!string)(list).join(",")~")";
}
//---------------------------------------------------------------------------
// General query function. Can be used with both retrieval and modification.
//---------------------------------------------------------------------------
ResultType query(string sql)
{
MYSQL_RES* res = query_raw(sql);
return ResultType(res);
}
//---------------------------------------------------------------------------
// Retireval functions
//---------------------------------------------------------------------------
string queryValue(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
string result;
if (!get_single(res, result))
return null;
while (mysql_fetch_row(res) !is null) {}
return result;
}
//---------------------------------------------------------------------------
string[string] queryRow(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
string[string] result = get_row(res);
while (mysql_fetch_row(res) !is null) {}
return result;
}
//---------------------------------------------------------------------------
string[string][] queryData(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
auto data = appender!(string[string][])();
//string[string][] data;
string[string] row;
while ((row = get_row(res)) !is null)
data.put(row);
return data.data;
}
//---------------------------------------------------------------------------
T[] queryColumn(T = string)(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
auto data = appender!(T[])();
//string[] data;
string v;
while (get_single(res,v))
data.put(to!T(v));
return data.data;
}
//---------------------------------------------------------------------------
//
// constraints
// first column is used as the index.
// first column must be unique, and of the correct type.
//
string[string][T] queryIndexedData(T = string)(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
bool ok = false;
int numFields = mysql_num_fields(res);
MYSQL_FIELD* fields = mysql_fetch_fields(res);
auto idColumn = to!string(fields[0].name);
// TODO test type of id_column
string[string][T] data;
string[string] row;
while ((row = get_row(res)) !is null)
data[to!(T)(row[idColumn])] = row;
return data;
}
//---------------------------------------------------------------------------
//
// constraints
// first column is used as the index.
// first column must be unique, and of the correct type.
//
U[T] queryIndexedColumn(T = string,U = string)(string sql)
{
MYSQL_RES* res = query_raw(sql);
scope(exit) { mysql_free_result(res); }
U[T] data;
if (mysql_num_fields(res) != 2)
throw new DBException
(
"query_indexed_column must be called with a query that returns "
"two columns",0, sql
);
// TODO test type of id_column
MYSQL_ROW row;
while ((row = mysql_fetch_row(res)) !is null)
{
ulong* lengths = mysql_fetch_lengths(res);
data[to!(T)(row[0][0..lengths[0]])] = to!U(row[1][0..lengths[1]]);
}
return data;
}
//---------------------------------------------------------------------------
// Database write methods
//---------------------------------------------------------------------------
//
// constraints
// values are expected to be already vetted. Functions will enquote.
//
@property string insertId() { return to!string(mysql_insert_id(mysql)); }
string getInsertId() { return insertId; }
//---------------------------------------------------------------------------
// Insert a single row. Names and values are given as an AA. Return the ID
// for the row
string insert(string tablename, string[string] values)
{
return insert(tablename, values.keys, values.values);
}
//---------------------------------------------------------------------------
// Insert a single row. Names and values are given separately. Return the ID
// for the row
string insert(string tablename, string[] columns, string[] values)
{
query_raw
(
"insert into `"~tablename~"` (`" ~
columns.join("`,`") ~
"`) values (" ~
values.map!((a) => quote(a)).join(",") ~
")"
);
return getInsertId();
}
//---------------------------------------------------------------------------
// Insert a number of rows.
void insert(string tablename, string[] columns, string[][] values)
{
auto str = appender!string();
str.put("insert into `");
str.put(tablename);
str.put("` (");
str.put(columns.join(","));
str.put(") values (");
//... TODO may be flakey.
string[] vSql;
foreach (v;values)
vSql ~= v.map!((a) => quote(a)).join(",");
str.put(vSql.join("),("));
str.put(")");
query(str.data);
}
//---------------------------------------------------------------------------
void update(string tablename, string[string] values, string where)
{
update(tablename, values, [ where ]);
}
//---------------------------------------------------------------------------
void update(string tablename, string[string] values, string[] wheres)
{
query_raw
(
"update `"~tablename~"` set "~
meld!
(
(a,b) => (a~"="~quote(b))
)
(values).join(",")~" where "~wheres.join(" and ")
);
}
//---------------------------------------------------------------------------
void update(string tablename, string[] columns, string[] values, string where)
{
update(tablename, columns, values, [ where ]);
}
//---------------------------------------------------------------------------
void update(string tablename, string[] columns, string[] values, string[] wheres)
{
string[] s;
for (int i=0; i<columns.length; ++i)
s~= columns[i] ~ "=" ~ quote(values[i]);
query_raw("update `"~tablename~"` set "~join(s,",")~" where "~wheres.join(" and "));
}
//---------------------------------------------------------------------------
void replace(string tablename, string[string] values)
{
query_raw
(
"replace into `"~tablename~"` set "~
meld!
(
(a,b) => (a~"="~quote(b))
)
(values).join(",")
);
}
//---------------------------------------------------------------------------
// CRUD Shortcuts for use with ids
//---------------------------------------------------------------------------
// Assumes the table has a column `id` of type unigned integer (or long)
// and has a unique value index. We use strings to reduce the back-and-forth
// conversion between string and ulong that occurs in websites.
//---------------------------------------------------------------------------
alias insert create;
//---------------------------------------------------------------------------
string[string] get(string table, string id)
{
return queryRow("select * from `"~table~"` where id="~id);
}
//---------------------------------------------------------------------------
// If you want to insert a row with a non-empty id, use 'insert'.
string set(string tablename, string[string] values, string id = null)
{
if (id is null)
return insert(tablename, values);
else
{
update(tablename, values, [ "id="~id ]);
return id;
}
}
//---------------------------------------------------------------------------
void remove(string tablename, string id)
{
query("delete from `"~tablename~"` where id="~id);
}
void remove(string tablename, string[] ids)
{
if (ids.empty)
return;
else
query("delete from `"~tablename~"` where id in "~inList(ids));
}
//---------------------------------------------------------------------------
// Database reflection methods
//---------------------------------------------------------------------------
bool tableExists(string tablename)
{
return (queryValue("show tables like "~quote(tablename)) !is null);
}
//---------------------------------------------------------------------------
string[] getTables()
{
return queryColumn("show tables");
}
//---------------------------------------------------------------------------
bool isConnected() { return mysql !is null; }
//---------------------------------------------------------------------------
// The following allow direct access, use with caution
MYSQL* get_handle() { return mysql; }
MYSQL_RES* query_raw(string sql)
{
if (mysql is null) connect();
if (mysql_real_query(mysql, sql.ptr, sql.length) != 0)
throw new DBException(to!string(mysql_error(mysql)), mysql_errno(mysql), sql);
MYSQL_RES* res = mysql_use_result(mysql);
if (mysql_errno(mysql) != 0)
throw new DBException(to!string(mysql_error(mysql)), mysql_errno(mysql), sql);
return res;
}
struct MySQLRange
{
this(MYSQL_RES* r)
{
res = r;
if (r !is null)
popFront();
}
@property bool empty() { return row is null; }
@property string[string] front() { return row; }
void popFront()
{
row = get_row(res);
if (row is null)
{
mysql_free_result(res);
res = null;
}
}
private:
MYSQL_RES* res;
string[string] row = null;
}
void cancel(ref ResultType r)
{
mysql_free_result(r.res);
}
private:
MYSQL* mysql = null;
int error_code;
//-------------------------------------------------------------------------
}
package:
bool get_single(MYSQL_RES* res, ref string v)
{
MYSQL_ROW row = mysql_fetch_row(res);
if (row is null)
{
if (mysql_errno(res.handle) != 0)
throw new DBException(to!string(mysql_error(res.handle)), mysql_errno(res.handle),"");
else
return false;
}
auto lengths = mysql_fetch_lengths(res);
if (row[0] is null)
v = null;
else
v = row[0][0..lengths[0]].idup;
return true;
}
//-------------------------------------------------------------------------
string[string] get_row(MYSQL_RES* res)
{
string[string] r;
MYSQL_ROW row = mysql_fetch_row(res);
if (row is null)
{
if (mysql_errno(res.handle) != 0)
throw new DBException(to!string(mysql_error(res.handle)), mysql_errno(res.handle),"");
else
return null;
}
uint numFields = mysql_num_fields(res);
MYSQL_FIELD* fields = mysql_fetch_fields(res);
auto lengths = mysql_fetch_lengths(res);
for (int i = 0; i < numFields; ++i)
{
auto s = fields[i].name[0..fields[i].name_length].idup;
if (row[i] is null)
r[s] = null;
else
r[s] = row[i][0..lengths[i]].idup;
}
return r;
}
| D |
/*
Copyright © 2020, Luna Nielsen
Distributed under the 2-Clause BSD License, see LICENSE file.
Authors: Luna Nielsen
*/
module engine.vn.script.instr;
import engine.vn.script;
import engine;
/**
Instruction that shows a character
*/
class CGInstr : IScriptInstr {
public:
string cgfile;
this(string cgfile = null) {
this.cgfile = cgfile;
}
bool execute(Script script) {
script.state.cg = cgfile is null ? null : new Texture("assets/textures/backgrounds/"~cgfile);
return false;
}
bool isBlocking() {
return false;
}
}
/**
Instruction that plays a sound effect
*/
class SFXInstr : IScriptInstr {
public:
string sfxfile;
this(string sfxfile) {
this.sfxfile = sfxfile;
}
bool execute(Script script) {
(new Sound(sfxfile)).play();
return false;
}
bool isBlocking() {
return false;
}
}
/**
Instruction that sets the scene's music
*/
class MusicInstr : IScriptInstr {
public:
string musicFile;
this(string musicFile) {
this.musicFile = musicFile;
}
bool execute(Script script) {
if (script.state.music !is null) {
script.state.music.stop();
}
script.state.music = new Music(musicFile);
script.state.music.setLooping(true);
script.state.music.play();
return false;
}
bool isBlocking() {
return false;
}
}
/**
Instruction that shows a character
*/
class ShowInstr : IScriptInstr {
public:
bool side;
string texture;
string character;
this(string character, string texture=null, bool side=false) {
this.character = character;
this.texture = texture;
this.side = side;
}
bool execute(Script script) {
if (character in script.state.characters) {
script.state.characters[character].shown = true;
if (texture !is null) {
script.state.characters[character].setTexture(texture);
}
script.state.characters[character].position = !side ?
vec2(256, 1080) : vec2(1920-256, 1080);
script.state.characters[character].isFlipped = side;
}
return false;
}
bool isBlocking() {
return false;
}
}
/**
Instruction that hides a character
*/
class HideInstr : IScriptInstr {
public:
string character;
this(string character) {
this.character = character;
}
bool execute(Script script) {
if (character in script.state.characters) {
script.state.characters[character].shown = false;
}
return false;
}
bool isBlocking() {
return false;
}
}
/**
Instruction that causes a character to say something
*/
class SayInstr : IScriptInstr {
public:
bool show;
string origin;
string text;
this(string text, string origin=null, bool show=false) {
this.origin = origin;
this.text = text;
this.show = show;
}
/**
Executes the instruction
*/
bool execute(Script script) {
script.state.dialogue.push(text.toEngineString(), origin.toEngineString());
// If show is enabled show the character
if (origin in script.state.characters) {
// Activates the character
script.state.characters[origin].activate();
if (show) {
script.state.characters[origin].shown = true;
}
}
return true;
}
bool isBlocking() {
return true;
}
}
/**
Instruction that causes a character to say something, this is nonblocking
*/
class NSayInstr : SayInstr {
public:
bool show;
string origin;
string text;
this(string text, string origin=null, bool show=false) {
super(text, origin, show);
}
/**
Executes the instruction
*/
override bool execute(Script script) {
script.state.markAutoNext();
return super.execute(script);
}
override bool isBlocking() {
return super.isBlocking();
}
}
/**
Instruction that executes D code
*/
class CodeInstr : IScriptInstr {
public:
void delegate(Script script) instr;
this(void delegate(Script script) instr) {
this.instr = instr;
}
/**
Executes the instruction
*/
bool execute(Script script) {
instr(script);
return false;
}
bool isBlocking() {
return false;
}
} | D |
//Written in the D programming language
/++
Module containing Date/Time functionality.
This module provides:
$(UL
$(LI Types to represent points in time: $(D SysTime), $(D Date),
$(D TimeOfDay), and $(D DateTime).)
$(LI Types to represent intervals of time.)
$(LI Types to represent ranges over intervals of time.)
$(LI Types to represent time zones (used by $(D SysTime)).)
$(LI A platform-independent, high precision stopwatch type:
$(D StopWatch))
$(LI Benchmarking functions.)
$(LI Various helper functions.)
)
Closely related to std.datetime is <a href="core_time.html">$(D core.time)</a>,
and some of the time types used in std.datetime come from there - such as
$(CXREF time, Duration), $(CXREF time, TickDuration), and
$(CXREF time, FracSec).
core.time is publically imported into std.datetime, it isn't necessary
to import it separately.
Three of the main concepts used in this module are time points, time
durations, and time intervals.
A time point is a specific point in time. e.g. January 5th, 2010
or 5:00.
A time duration is a length of time with units. e.g. 5 days or 231 seconds.
A time interval indicates a period of time associated with a fixed point in
time. It is either two time points associated with each other,
indicating the time starting at the first point up to, but not including,
the second point - e.g. [January 5th, 2010 - March 10th, 2010$(RPAREN) - or
it is a time point and a time duration associated with one another. e.g.
January 5th, 2010 and 5 days, indicating [January 5th, 2010 -
January 10th, 2010$(RPAREN).
Various arithmetic operations are supported between time points and
durations (e.g. the difference between two time points is a time duration),
and ranges can be gotten from time intervals, so range-based operations may
be done on a series of time points.
The types that the typical user is most likely to be interested in are
$(D Date) (if they want dates but don't care about time), $(D DateTime)
(if they want dates and times but don't care about time zones), $(D SysTime)
(if they want the date and time from the OS and/or do care about time
zones), and StopWatch (a platform-independent, high precision stop watch).
$(D Date) and $(D DateTime) are optimized for calendar-based operations,
while $(D SysTime) is designed for dealing with time from the OS. Check out
their specific documentation for more details.
To get the current time, use $(D Clock.currTime). It will return the current
time as a $(D SysTime). To print it, $(D toString) is
sufficient, but if using $(D toISOString), $(D toISOExtString), or
$(D toSimpleString), use the corresponding $(D fromISOString),
$(D fromISOExtString), or $(D fromISOExtString) to create a
$(D SysTime) from the string.
--------------------
auto currentTime = Clock.currTime();
auto timeString = currentTime.toISOExtString();
auto restoredTime = SysTime.fromISOExtString(timeString);
--------------------
Various functions take a string (or strings) to represent a unit of time
(e.g. $(D convert!("days", "hours")(numDays))). The valid strings to use
with such functions are $(D "years"), $(D "months"), $(D "weeks"),
$(D "days"), $(D "hours"), $(D "minutes"), $(D "seconds"),
$(D "msecs") (milliseconds), $(D "usecs") (microseconds),
$(D "hnsecs") (hecto-nanoseconds - i.e. 100 ns), or some subset thereof.
There are a few functions in core.time which take $(D "nsecs"), but because
nothing in std.datetime has precision greater than hnsecs, and very little
in core.time does, no functions in std.datetime accept $(D "nsecs").
To remember which units are abbreviated and which aren't,
all units seconds and greater use their full names, and all
sub-second units are abbreviated (since they'd be rather long if they
weren't).
Note:
$(D DateTimeException) is an alias for core.time's $(D TimeException),
so you don't need to worry about core.time functions and std.datetime
functions throwing different exception types (except in the rare case
that they throw something other than $(D TimeException) or
$(D DateTimeException)).
See_Also:
<a href="../intro-to-datetime.html">Introduction to std._datetime </a><br>
$(WEB en.wikipedia.org/wiki/ISO_8601, ISO 8601)<br>
$(WEB en.wikipedia.org/wiki/Tz_database,
Wikipedia entry on TZ Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones,
List of Time Zones)<br>
Copyright: Copyright 2010 - 2011
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Jonathan M Davis and Kato Shoichi
Source: $(PHOBOSSRC std/_datetime.d)
+/
module std.datetime;
public import core.time;
import core.exception;
import core.stdc.time;
import std.array;
import std.algorithm;
import std.ascii;
import std.conv;
import std.exception;
import std.file;
import std.functional;
import std.math;
import std.metastrings;
import std.path;
import std.range;
import std.stdio;
import std.string;
import std.system;
import std.traits;
import std.typecons;
import std.utf;
version(Windows)
{
import core.sys.windows.windows;
import std.c.windows.winsock;
import std.windows.registry;
}
else version(Posix)
{
import core.sys.posix.arpa.inet;
import core.sys.posix.stdlib;
import core.sys.posix.time;
import core.sys.posix.sys.time;
}
//Comment this out to disable std.datetime's unit tests.
version = testStdDateTime;
version(unittest)
{
import std.c.string;
import std.stdio;
}
//I'd just alias it to indexOf, but
//http://d.puremagic.com/issues/show_bug.cgi?id=6013 would mean that that would
//pollute the global namespace. So, for now, I've created an alias which is
//highly unlikely to conflict with anything that anyone else is doing.
private alias std.string.indexOf stds_indexOf;
version(testStdDateTime) unittest
{
initializeTests();
}
//Verify module example.
version(testStdDateTime) unittest
{
auto currentTime = Clock.currTime();
auto timeString = currentTime.toISOExtString();
auto restoredTime = SysTime.fromISOExtString(timeString);
}
//Verify Examples for core.time.Duration which couldn't be in core.time.
version(testStdDateTime) unittest
{
assert(std.datetime.Date(2010, 9, 7) + dur!"days"(5) ==
std.datetime.Date(2010, 9, 12));
assert(std.datetime.Date(2010, 9, 7) - std.datetime.Date(2010, 10, 3) ==
dur!"days"(-26));
}
//Note: There various functions which void as their return type and ref of the
// struct type which they're in as a commented out return type. Ideally,
// they would return the ref, but there are several dmd bugs which prevent
// that, relating to both ref and invariants. So, I've left the ref return
// types commented out with the idea that those functions can be made to
// return a ref to this once those bugs have been fixed.
//==============================================================================
// Section with public enums and constants.
//==============================================================================
/++
Represents the 12 months of the Gregorian year (January is 1).
+/
enum Month : ubyte { jan = 1, ///
feb, ///
mar, ///
apr, ///
may, ///
jun, ///
jul, ///
aug, ///
sep, ///
oct, ///
nov, ///
dec ///
}
/++
Represents the 7 days of the Gregorian week (Sunday is 0).
+/
enum DayOfWeek : ubyte { sun = 0, ///
mon, ///
tue, ///
wed, ///
thu, ///
fri, ///
sat ///
}
/++
In some date calculations, adding months or years can cause the date to fall
on a day of the month which is not valid (e.g. February 29th 2001 or
June 31st 2000). If overflow is allowed (as is the default), then the month
will be incremented accordingly (so, February 29th 2001 would become
March 1st 2001, and June 31st 2000 would become July 1st 2000). If overflow
is not allowed, then the day will be adjusted to the last valid day in that
month (so, February 29th 2001 would become February 28th 2001 and
June 31st 2000 would become June 30th 2000).
AllowDayOverflow only applies to calculations involving months or years.
+/
enum AllowDayOverflow
{
/// No, don't allow day overflow.
no,
/// Yes, allow day overflow.
yes
}
/++
Indicates a direction in time. One example of its use is $(D Interval)'s
$(D expand) function which uses it to indicate whether the interval should
be expanded backwards (into the past), forwards (into the future), or both.
+/
enum Direction
{
/// Backward.
bwd,
/// Forward.
fwd,
/// Both backward and forward.
both
}
/++
Used to indicate whether $(D popFront) should be called immediately upon
creating a range. The idea is that for some functions used to generate a
range for an interval, $(D front) is not necessarily a time point which
would ever be generated by the range. To get the first time point
in the range to match what the function generates, then use
$(D PopFirst.yes) to indicate that the range should have $(D popFront)
called on it before the range is returned so that $(D front) is a time point
which the function would generate.
For instance, if the function used to generate a range of time points
generated successive Easters (i.e. you're iterating over all of the Easters
within the interval), the initial date probably isn't an Easter. Using
$(D PopFirst.yes) would tell the function which returned the
range that $(D popFront) was to be called so that front would then be
an Easter - the next one generated by the function (which when
iterating forward would be the Easter following the original $(D front),
while when iterating backward, it would be the Easter prior to the
original $(D front)). If $(D PopFirst.no) were used, then $(D front) would
remain the original time point and it would not necessarily be a time point
which would be generated by the range-generating function (which in many
cases is exactly what is desired -
e.g. if iterating over every day starting at the beginning
of the interval).
+/
enum PopFirst
{
/// No, don't call popFront() before returning the range.
no,
/// Yes, call popFront() before returning the range.
yes
}
/++
Used by StopWatch to indicate whether it should start immediately upon
construction.
+/
enum AutoStart
{
/// No, don't start the StopWatch when it is constructed.
no,
/// Yes, do start the StopWatch when it is constructed.
yes
}
/++
Array of the strings representing time units, starting with the smallest
unit and going to the largest. It does not include $(D "nsecs").
Includes $(D "hnsecs") (hecto-nanoseconds (100 ns)),
$(D "usecs") (microseconds), $(D "msecs") (milliseconds), $(D "seconds"),
$(D "minutes"), $(D "hours"), $(D "days"), $(D "weeks"), $(D "months"), and
$(D "years")
+/
immutable string[] timeStrings = ["hnsecs", "usecs", "msecs", "seconds", "minutes",
"hours", "days", "weeks", "months", "years"];
//==============================================================================
// Section with private constants.
//==============================================================================
/++
Array of integers representing the last days of each month in a year.
+/
private immutable int[13] lastDayNonLeap = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
/++
Array of integers representing the last days of each month in a leap year.
+/
private immutable int[13] lastDayLeap = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366];
/++
Array of the long names of each month.
+/
private immutable string[12] longMonthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
/++
Array of the short (three letter) names of each month.
+/
private immutable string[12] shortMonthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
];
//==============================================================================
// Section with other types.
//==============================================================================
/++
Exception type used by std.datetime. It's an alias to TimeException, which
is what core.time uses. Either can be caught without concern about which
module it came from.
+/
alias TimeException DateTimeException;
/++
Effectively a namespace to make it clear that the methods it contains are
getting the time from the system clock. It cannot be instantiated.
+/
final class Clock
{
public:
/++
Returns the current time in the given time zone.
Throws:
$(D ErrnoException) (on Posix) or $(D Exception) (on Windows)
if it fails to get the time of day.
+/
static SysTime currTime(immutable TimeZone tz = LocalTime())
{
return SysTime(currStdTime, tz);
}
version(testStdDateTime) unittest
{
assert(currTime(UTC()).timezone is UTC());
//I have no idea why, but for some reason, Windows/Wine likes to get
//time_t wrong when getting it with core.stdc.time.time. On one box
//I have (which has its local time set to UTC), it always gives time_t
//in the real local time (America/Los_Angeles), and after the most recent
//DST switch, every Windows box that I've tried it in is reporting
//time_t as being 1 hour off of where it's supposed to be. So, I really
//don't know what the deal is, but given what I'm seeing, I don't trust
//core.stdc.time.time on Windows, so I'm just going to disable this test
//on Windows.
version(Posix)
{
immutable unixTimeD = currTime().toUnixTime();
immutable unixTimeC = core.stdc.time.time(null);
immutable diff = unixTimeC - unixTimeD;
_assertPred!">="(diff, -2);
_assertPred!"<="(diff, 2);
}
}
/++
Returns the number of hnsecs since midnight, January 1st, 1 A.D. for the
current time.
Throws:
$(D DateTimeException) if it fails to get the time.
+/
@trusted
static @property long currStdTime()
{
version(Windows)
{
FILETIME fileTime;
GetSystemTimeAsFileTime(&fileTime);
return FILETIMEToStdTime(&fileTime);
}
else version(Posix)
{
enum hnsecsToUnixEpoch = 621_355_968_000_000_000L;
static if(is(typeof(clock_gettime)))
{
timespec ts;
if(clock_gettime(CLOCK_REALTIME, &ts) != 0)
throw new TimeException("Failed in clock_gettime().");
return convert!("seconds", "hnsecs")(ts.tv_sec) +
ts.tv_nsec / 100 +
hnsecsToUnixEpoch;
}
else
{
timeval tv;
if(gettimeofday(&tv, null) != 0)
throw new TimeException("Failed in gettimeofday().");
return convert!("seconds", "hnsecs")(tv.tv_sec) +
convert!("usecs", "hnsecs")(tv.tv_usec) +
hnsecsToUnixEpoch;
}
}
}
/++
The current system tick. The number of ticks per second varies from
system to system. currSystemTick uses a monotonic clock, so it's
intended for precision timing by comparing relative time values, not
for getting the current system time.
Warning:
On some systems, the monotonic clock may stop counting when
the computer goes to sleep or hibernates. So, the monotonic
clock could be off if that occurs. This is known to happen
on Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
Throws:
$(D DateTimeException) if it fails to get the time.
+/
@safe
static @property TickDuration currSystemTick()
{
return TickDuration.currSystemTick;
}
version(testStdDateTime) unittest
{
assert(Clock.currSystemTick.length > 0);
}
/++
The current number of system ticks since the application started.
The number of ticks per second varies from system to system.
This uses a monotonic clock.
Warning:
On some systems, the monotonic clock may stop counting when
the computer goes to sleep or hibernates. So, the monotonic
clock could be off if that occurs. This is known to happen
on Mac OS X. It has not been tested whether it occurs on
either Windows or on Linux.
Throws:
$(D DateTimeException) if it fails to get the time.
+/
@safe
static @property TickDuration currAppTick()
{
return currSystemTick - TickDuration.appOrigin;
}
version(testStdDateTime) unittest
{
auto a = Clock.currSystemTick;
auto b = Clock.currAppTick;
assert(a.length);
assert(b.length);
assert(a > b);
}
private:
@disable this() {}
}
//==============================================================================
// Section with time points.
//==============================================================================
/++
$(D SysTime) is the type used to get the current time from the
system or doing anything that involves time zones. Unlike
$(D DateTime), the time zone is an integral part of $(D SysTime) (though for
local time applications, time zones can be ignored and
it will work, since it defaults to using the local time zone). It holds its
internal time in std time (hnsecs since midnight, January 1st, 1 A.D. UTC),
so it interfaces well with the system time. However, that means that, unlike
$(D DateTime), it is not optimized for calendar-based operations, and
getting individual units from it such as years or days is going to involve
conversions and be less efficient.
For calendar-based operations that don't
care about time zones, then $(D DateTime) would be the type to
use. For system time, use $(D SysTime).
$(D Clock.currTime) will return the current time as a $(D SysTime).
To convert a $(D SysTime) to a $(D Date) or $(D DateTime), simply cast
it. To convert a $(D Date) or $(D DateTime) to a
$(D SysTime), use $(D SysTime)'s constructor, and pass in the
intended time zone with it (or don't pass in a $(D TimeZone), and the local
time zone will be used). Be aware, however, that converting from a
$(D DateTime) to a $(D SysTime) will not necessarily be 100% accurate due to
DST (one hour of the year doesn't exist and another occurs twice).
To not risk any conversion errors, keep times as
$(D SysTime)s. Aside from DST though, there shouldn't be any conversion
problems.
For using time zones other than local time or UTC, use
$(D PosixTimeZone) on Posix systems (or on Windows, if providing the TZ
Database files), and use $(D WindowsTimeZone) on Windows systems.
The time in $(D SysTime) is kept internally in hnsecs from midnight,
January 1st, 1 A.D. UTC. Conversion error cannot happen when changing
the time zone of a $(D SysTime). $(D LocalTime) is the $(D TimeZone) class
which represents the local time, and $(D UTC) is the $(D TimeZone) class
which represents UTC. $(D SysTime) uses $(D LocalTime) if no $(D TimeZone)
is provided. For more details on time zones, see the documentation for
$(D TimeZone), $(D PosixTimeZone), and $(D WindowsTimeZone).
$(D SysTime)'s range is from approximately 29,000 B.C. to approximately
29,000 A.D.
+/
struct SysTime
{
public:
/++
Params:
dateTime = The $(D DateTime) to use to set this $(D SysTime)'s
internal std time. As $(D DateTime) has no concept of
time zone, tz is used as its time zone.
tz = The $(D TimeZone) to use for this $(D SysTime). If null,
$(D LocalTime) will be used. The given $(D DateTime) is
assumed to be in the given time zone.
+/
this(in DateTime dateTime, immutable TimeZone tz = null) nothrow
{
try
this(dateTime, FracSec.from!"hnsecs"(0), tz);
catch(Exception e)
assert(0, "FracSec's constructor threw when it shouldn't have.");
}
version(testStdDateTime) unittest
{
static void test(DateTime dt, immutable TimeZone tz, long expected)
{
auto sysTime = SysTime(dt, tz);
_assertPred!"=="(sysTime._stdTime, expected);
assert(sysTime._timezone is (tz is null ? LocalTime() : tz),
format("Given DateTime: %s", dt));
}
test(DateTime.init, UTC(), 0);
test(DateTime(1, 1, 1, 12, 30, 33), UTC(), 450_330_000_000L);
test(DateTime(0, 12, 31, 12, 30, 33), UTC(), -413_670_000_000L);
test(DateTime(1, 1, 1, 0, 0, 0), UTC(), 0);
test(DateTime(1, 1, 1, 0, 0, 1), UTC(), 10_000_000L);
test(DateTime(0, 12, 31, 23, 59, 59), UTC(), -10_000_000L);
test(DateTime(1, 1, 1, 0, 0, 0), new SimpleTimeZone(dur!"minutes"(-60)), 36_000_000_000L);
test(DateTime(1, 1, 1, 0, 0, 0), new SimpleTimeZone(Duration.zero), 0);
test(DateTime(1, 1, 1, 0, 0, 0), new SimpleTimeZone(dur!"minutes"(60)), -36_000_000_000L);
}
/++
Params:
dateTime = The $(D DateTime) to use to set this $(D SysTime)'s
internal std time. As $(D DateTime) has no concept of
time zone, tz is used as its time zone.
fracSec = The fractional seconds portion of the time.
tz = The $(D TimeZone) to use for this $(D SysTime). If null,
$(D LocalTime) will be used. The given $(D DateTime) is
assumed to be in the given time zone.
Throws:
$(D DateTimeException) if $(D fracSec) is negative.
+/
this(in DateTime dateTime, in FracSec fracSec, immutable TimeZone tz = null)
{
immutable fracHNSecs = fracSec.hnsecs;
enforce(fracHNSecs >= 0, new DateTimeException("A SysTime cannot have negative fractional seconds."));
_timezone = tz is null ? LocalTime() : tz;
try
{
immutable dateDiff = (dateTime.date - Date(1, 1, 1)).total!"hnsecs";
immutable todDiff = (dateTime.timeOfDay - TimeOfDay(0, 0, 0)).total!"hnsecs";
immutable adjustedTime = dateDiff + todDiff + fracHNSecs;
immutable standardTime = _timezone.tzToUTC(adjustedTime);
this(standardTime, _timezone);
}
catch(Exception e)
{
assert(0, "Date, TimeOfDay, or DateTime's constructor threw when " ~
"it shouldn't have.");
}
}
version(testStdDateTime) unittest
{
static void test(DateTime dt,
FracSec fracSec,
immutable TimeZone tz,
long expected)
{
auto sysTime = SysTime(dt, fracSec, tz);
_assertPred!"=="(sysTime._stdTime, expected);
assert(sysTime._timezone is (tz is null ? LocalTime() : tz),
format("Given DateTime: %s, Given FracSec: %s", dt, fracSec));
}
test(DateTime.init, FracSec.init, UTC(), 0);
test(DateTime(1, 1, 1, 12, 30, 33), FracSec.init, UTC(), 450_330_000_000L);
test(DateTime(0, 12, 31, 12, 30, 33), FracSec.init, UTC(), -413_670_000_000L);
test(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(1), UTC(), 10_000L);
test(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999), UTC(), -10_000L);
test(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC(), -1);
test(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1), UTC(), -9_999_999);
test(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0), UTC(), -10_000_000);
assertThrown!DateTimeException(SysTime(DateTime.init, FracSec.from!"hnsecs"(-1), UTC()));
}
/++
Params:
date = The $(D Date) to use to set this $(D SysTime)'s internal std
time. As $(D Date) has no concept of time zone, tz is used as
its time zone.
tz = The $(D TimeZone) to use for this $(D SysTime). If null,
$(D LocalTime) will be used. The given $(D Date) is assumed
to be in the given time zone.
+/
this(in Date date, immutable TimeZone tz = null) nothrow
{
_timezone = tz is null ? LocalTime() : tz;
try
{
immutable adjustedTime = (date - Date(1, 1, 1)).total!"hnsecs";
immutable standardTime = _timezone.tzToUTC(adjustedTime);
this(standardTime, _timezone);
}
catch(Exception e)
assert(0, "Date's constructor through when it shouldn't have.");
}
version(testStdDateTime) unittest
{
static void test(Date d, immutable TimeZone tz, long expected)
{
auto sysTime = SysTime(d, tz);
_assertPred!"=="(sysTime._stdTime, expected);
assert(sysTime._timezone is (tz is null ? LocalTime() : tz),
format("Given Date: %s", d));
}
test(Date.init, UTC(), 0);
test(Date(1, 1, 1), UTC(), 0);
test(Date(1, 1, 2), UTC(), 864000000000);
test(Date(0, 12, 31), UTC(), -864000000000);
}
/++
Note:
Whereas the other constructors take in the given date/time, assume
that it's in the given time zone, and convert it to hnsecs in UTC
since midnight, January 1st, 1 A.D. UTC - i.e. std time - this
constructor takes a std time, which is specifically already in UTC,
so no conversion takes place. Of course, the various getter
properties and functions will use the given time zone's conversion
function to convert the results to that time zone, but no conversion
of the arguments to this constructor takes place.
Params:
stdTime = The number of hnsecs since midnight, January 1st, 1 A.D. UTC.
tz = The $(D TimeZone) to use for this $(D SysTime). If null,
$(D LocalTime) will be used.
+/
this(long stdTime, immutable TimeZone tz = null) pure nothrow
{
_stdTime = stdTime;
_timezone = tz is null ? LocalTime() : tz;
}
version(testStdDateTime) unittest
{
static void test(long stdTime, immutable TimeZone tz)
{
auto sysTime = SysTime(stdTime, tz);
_assertPred!"=="(sysTime._stdTime, stdTime);
assert(sysTime._timezone is (tz is null ? LocalTime() : tz),
format("Given stdTime: %s", stdTime));
}
foreach(stdTime; [-1234567890L, -250, 0, 250, 1235657390L])
{
foreach(tz; testTZs)
test(stdTime, tz);
}
}
/++
Params:
rhs = The $(D SysTime) to assign to this one.
+/
ref SysTime opAssign(const ref SysTime rhs) pure nothrow
{
_stdTime = rhs._stdTime;
_timezone = rhs._timezone;
return this;
}
/++
Params:
rhs = The $(D SysTime) to assign to this one.
+/
ref SysTime opAssign(SysTime rhs) pure nothrow
{
_stdTime = rhs._stdTime;
_timezone = rhs._timezone;
return this;
}
/++
Checks for equality between this $(D SysTime) and the given
$(D SysTime).
Note that the time zone is ignored. Only the internal
std times (which are in UTC) are compared.
+/
bool opEquals(const SysTime rhs) const pure nothrow
{
return opEquals(rhs);
}
/// ditto
bool opEquals(const ref SysTime rhs) const pure nothrow
{
return _stdTime == rhs._stdTime;
}
version(testStdDateTime) unittest
{
_assertPred!"=="(SysTime(DateTime.init, UTC()), SysTime(0, UTC()));
_assertPred!"=="(SysTime(DateTime.init, UTC()), SysTime(0));
_assertPred!"=="(SysTime(Date.init, UTC()), SysTime(0));
_assertPred!"=="(SysTime(0), SysTime(0));
static void test(DateTime dt,
immutable TimeZone tz1,
immutable TimeZone tz2)
{
auto st1 = SysTime(dt);
st1.timezone = tz1;
auto st2 = SysTime(dt);
st2.timezone = tz2;
_assertPred!"=="(st1, st2);
}
foreach(tz1; testTZs)
{
foreach(tz2; testTZs)
{
foreach(dt; chain(testDateTimesBC, testDateTimesAD))
test(dt, tz1, tz2);
}
}
auto st = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
const cst = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
static assert(__traits(compiles, st == st));
static assert(__traits(compiles, st == cst));
//static assert(__traits(compiles, st == ist));
static assert(__traits(compiles, cst == st));
static assert(__traits(compiles, cst == cst));
//static assert(__traits(compiles, cst == ist));
//static assert(__traits(compiles, ist == st));
//static assert(__traits(compiles, ist == cst));
//static assert(__traits(compiles, ist == ist));
}
/++
Compares this $(D SysTime) with the given $(D SysTime).
Time zone is irrelevant when comparing $(D SysTime)s.
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
+/
int opCmp(in SysTime rhs) const pure nothrow
{
if(_stdTime < rhs._stdTime)
return -1;
if(_stdTime > rhs._stdTime)
return 1;
return 0;
}
version(testStdDateTime) unittest
{
_assertPred!("opCmp", "==")(SysTime(DateTime.init, UTC()),
SysTime(0, UTC()));
_assertPred!("opCmp", "==")(SysTime(DateTime.init, UTC()), SysTime(0));
_assertPred!("opCmp", "==")(SysTime(Date.init, UTC()), SysTime(0));
_assertPred!("opCmp", "==")(SysTime(0), SysTime(0));
static void testEqual(SysTime st,
immutable TimeZone tz1,
immutable TimeZone tz2)
{
auto st1 = st;
st1.timezone = tz1;
auto st2 = st;
st2.timezone = tz2;
_assertPred!("opCmp", "==")(st1, st2);
}
auto sts = array(map!SysTime(chain(testDateTimesBC, testDateTimesAD)));
foreach(st; sts)
foreach(tz1; testTZs)
foreach(tz2; testTZs)
testEqual(st, tz1, tz2);
static void testCmp(SysTime st1,
immutable TimeZone tz1,
SysTime st2,
immutable TimeZone tz2)
{
st1.timezone = tz1;
st2.timezone = tz2;
_assertPred!("opCmp", "<")(st1, st2);
_assertPred!("opCmp", ">")(st2, st1);
}
foreach(si, st1; sts)
foreach(st2; sts[si+1 .. $])
foreach(tz1; testTZs)
foreach(tz2; testTZs)
testCmp(st1, tz1, st2, tz2);
auto st = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
const cst = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 33, 30));
static assert(__traits(compiles, st.opCmp(st)));
static assert(__traits(compiles, st.opCmp(cst)));
//static assert(__traits(compiles, st.opCmp(ist)));
static assert(__traits(compiles, cst.opCmp(st)));
static assert(__traits(compiles, cst.opCmp(cst)));
//static assert(__traits(compiles, cst.opCmp(ist)));
//static assert(__traits(compiles, ist.opCmp(st)));
//static assert(__traits(compiles, ist.opCmp(cst)));
//static assert(__traits(compiles, ist.opCmp(ist)));
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
+/
@property short year() const nothrow
{
return (cast(Date)this).year;
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, long expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.year, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), 1);
test(SysTime(1, UTC()), 1);
test(SysTime(-1, UTC()), 0);
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(tod; testTODs)
{
auto dt = DateTime(Date(year, md.month, md.day), tod);
foreach(tz; testTZs)
{
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), year);
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.year));
//static assert(__traits(compiles, ist.year));
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Params:
year = The year to set this $(D SysTime)'s year to.
Throws:
$(D DateTimeException) if the new year is not a leap year and the
resulting date would be on February 29th.
Examples:
--------------------
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).year == 1999);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).year == 2010);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).year == -7);
--------------------
+/
@property void year(int year)
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.year = year;
immutable newDaysHNSecs = convert!("days", "hnsecs")(date.dayOfGregorianCal - 1);
adjTime = newDaysHNSecs + hnsecs;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).year == 1999);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).year == 2010);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).year == -7);
}
version(testStdDateTime) unittest
{
static void test(SysTime st, int year, in SysTime expected, size_t line = __LINE__)
{
st.year = year;
_assertPred!"=="(st, expected, "", __FILE__, line);
}
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
foreach(year; chain(testYearsBC, testYearsAD))
{
auto e = SysTime(DateTime(year, dt.month, dt.day, dt.hour, dt.minute, dt.second),
st.fracSec,
st.timezone);
test(st, year, e);
}
}
foreach(fs; testFracSecs)
{
foreach(tz; testTZs)
{
foreach(tod; testTODs)
{
test(SysTime(DateTime(Date(1999, 2, 28), tod), fs, tz), 2000,
SysTime(DateTime(Date(2000, 2, 28), tod), fs, tz));
test(SysTime(DateTime(Date(2000, 2, 28), tod), fs, tz), 1999,
SysTime(DateTime(Date(1999, 2, 28), tod), fs, tz));
}
foreach(tod; testTODsThrown)
{
auto st = SysTime(DateTime(Date(2000, 2, 29), tod), fs, tz);
assertThrown!DateTimeException(st.year = 1999);
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.year = 7));
//static assert(!__traits(compiles, ist.year = 7));
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Throws:
$(D DateTimeException) if $(D isAD) is true.
Examples:
--------------------
assert(SysTime(DateTime(0, 1, 1, 12, 30, 33)).yearBC == 1);
assert(SysTime(DateTime(-1, 1, 1, 10, 7, 2)).yearBC == 2);
assert(SysTime(DateTime(-100, 1, 1, 4, 59, 0)).yearBC == 101);
--------------------
+/
@property ushort yearBC() const
{
return (cast(Date)this).yearBC;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(SysTime(DateTime(0, 1, 1, 12, 30, 33)).yearBC == 1);
assert(SysTime(DateTime(-1, 1, 1, 10, 7, 2)).yearBC == 2);
assert(SysTime(DateTime(-100, 1, 1, 4, 59, 0)).yearBC == 101);
}
version(testStdDateTime) unittest
{
foreach(st; testSysTimesBC)
{
auto msg = format("SysTime: %s", st);
assertNotThrown!DateTimeException(st.yearBC, msg);
_assertPred!"=="(st.yearBC, (st.year * -1) + 1, msg);
}
foreach(st; [testSysTimesAD[0], testSysTimesAD[$/2], testSysTimesAD[$-1]])
assertThrown!DateTimeException(st.yearBC, format("SysTime: %s", st));
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.year = 12));
static assert(!__traits(compiles, cst.year = 12));
//static assert(!__traits(compiles, ist.year = 12));
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Params:
year = The year B.C. to set this $(D SysTime)'s year to.
Throws:
$(D DateTimeException) if a non-positive value is given.
Examples:
--------------------
auto st = SysTime(DateTime(2010, 1, 1, 7, 30, 0));
st.yearBC = 1;
assert(st == SysTime(DateTime(0, 1, 1, 7, 30, 0)));
st.yearBC = 10;
assert(st == SysTime(DateTime(-9, 1, 1, 7, 30, 0)));
--------------------
+/
@property void yearBC(int year)
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.yearBC = year;
immutable newDaysHNSecs = convert!("days", "hnsecs")(date.dayOfGregorianCal - 1);
adjTime = newDaysHNSecs + hnsecs;
}
//Verify Examples
version(testStdDateTime) unittest
{
auto st = SysTime(DateTime(2010, 1, 1, 7, 30, 0));
st.yearBC = 1;
assert(st == SysTime(DateTime(0, 1, 1, 7, 30, 0)));
st.yearBC = 10;
assert(st == SysTime(DateTime(-9, 1, 1, 7, 30, 0)));
}
version(testStdDateTime) unittest
{
static void test(SysTime st, int year, in SysTime expected, size_t line = __LINE__)
{
st.yearBC = year;
_assertPred!"=="(st, expected, format("SysTime: %s", st), __FILE__, line);
}
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
foreach(year; testYearsBC)
{
auto e = SysTime(DateTime(year, dt.month, dt.day, dt.hour, dt.minute, dt.second),
st.fracSec,
st.timezone);
test(st, (year * -1) + 1, e);
}
}
foreach(st; [testSysTimesBC[0], testSysTimesBC[$ - 1],
testSysTimesAD[0], testSysTimesAD[$ - 1]])
{
foreach(year; testYearsBC)
assertThrown!DateTimeException(st.yearBC = year);
}
foreach(fs; testFracSecs)
{
foreach(tz; testTZs)
{
foreach(tod; testTODs)
{
test(SysTime(DateTime(Date(-1999, 2, 28), tod), fs, tz), 2001,
SysTime(DateTime(Date(-2000, 2, 28), tod), fs, tz));
test(SysTime(DateTime(Date(-2000, 2, 28), tod), fs, tz), 2000,
SysTime(DateTime(Date(-1999, 2, 28), tod), fs, tz));
}
foreach(tod; testTODsThrown)
{
auto st = SysTime(DateTime(Date(-2000, 2, 29), tod), fs, tz);
assertThrown!DateTimeException(st.year = -1999);
}
}
}
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.yearBC = 12));
static assert(!__traits(compiles, cst.yearBC = 12));
//static assert(!__traits(compiles, ist.yearBC = 12));
}
/++
Month of a Gregorian Year.
Examples:
--------------------
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).month == 7);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).month == 10);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).month == 4);
--------------------
+/
@property Month month() const nothrow
{
return (cast(Date)this).month;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).month == 7);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).month == 10);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).month == 4);
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, Month expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.month, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), Month.jan);
test(SysTime(1, UTC()), Month.jan);
test(SysTime(-1, UTC()), Month.dec);
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(tod; testTODs)
{
auto dt = DateTime(Date(year, md.month, md.day), tod);
foreach(fs; testFracSecs)
{
foreach(tz; testTZs)
test(SysTime(dt, fs, tz), md.month);
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.month));
//static assert(__traits(compiles, ist.month));
}
/++
Month of a Gregorian Year.
Params:
month = The month to set this $(D SysTime)'s month to.
Throws:
$(D DateTimeException) if the given month is not a valid month.
+/
@property void month(Month month)
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.month = month;
immutable newDaysHNSecs = convert!("days", "hnsecs")(date.dayOfGregorianCal - 1);
adjTime = newDaysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
static void test(SysTime st, Month month, in SysTime expected, size_t line = __LINE__)
{
st.month = cast(Month)month;
_assertPred!"=="(st, expected, "", __FILE__, line);
}
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
foreach(md; testMonthDays)
{
if(st.day > maxDay(dt.year, md.month))
continue;
auto e = SysTime(DateTime(dt.year, md.month, dt.day, dt.hour, dt.minute, dt.second),
st.fracSec,
st.timezone);
test(st, md.month, e);
}
}
foreach(fs; testFracSecs)
{
foreach(tz; testTZs)
{
foreach(tod; testTODs)
{
foreach(year; filter!((a){return yearIsLeapYear(a);})
(chain(testYearsBC, testYearsAD)))
{
test(SysTime(DateTime(Date(year, 1, 29), tod), fs, tz),
Month.feb,
SysTime(DateTime(Date(year, 2, 29), tod), fs, tz));
}
foreach(year; chain(testYearsBC, testYearsAD))
{
test(SysTime(DateTime(Date(year, 1, 28), tod), fs, tz),
Month.feb,
SysTime(DateTime(Date(year, 2, 28), tod), fs, tz));
test(SysTime(DateTime(Date(year, 7, 30), tod), fs, tz),
Month.jun,
SysTime(DateTime(Date(year, 6, 30), tod), fs, tz));
}
}
}
}
foreach(fs; [testFracSecs[0], testFracSecs[$-1]])
{
foreach(tz; testTZs)
{
foreach(tod; testTODsThrown)
{
foreach(year; [testYearsBC[$-3], testYearsBC[$-2],
testYearsBC[$-2], testYearsAD[0],
testYearsAD[$-2], testYearsAD[$-1]])
{
auto day = yearIsLeapYear(year) ? 30 : 29;
auto st1 = SysTime(DateTime(Date(year, 1, day), tod), fs, tz);
assertThrown!DateTimeException(st1.month = Month.feb);
auto st2 = SysTime(DateTime(Date(year, 7, 31), tod), fs, tz);
assertThrown!DateTimeException(st2.month = Month.jun);
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.month = 12));
//static assert(!__traits(compiles, ist.month = 12));
}
/++
Day of a Gregorian Month.
Examples:
--------------------
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).day == 6);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).day == 4);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).day == 5);
--------------------
+/
@property ubyte day() const nothrow
{
return (cast(Date)this).day;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).day == 6);
assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).day == 4);
assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).day == 5);
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, int expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.day, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), 1);
test(SysTime(1, UTC()), 1);
test(SysTime(-1, UTC()), 31);
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(tod; testTODs)
{
auto dt = DateTime(Date(year, md.month, md.day), tod);
foreach(tz; testTZs)
{
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), md.day);
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.day));
//static assert(__traits(compiles, ist.day));
}
/++
Day of a Gregorian Month.
Params:
day = The day of the month to set this $(D SysTime)'s day to.
Throws:
$(D DateTimeException) if the given day is not a valid day of the
current month.
+/
@property void day(int day)
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.day = day;
immutable newDaysHNSecs = convert!("days", "hnsecs")(date.dayOfGregorianCal - 1);
adjTime = newDaysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
foreach(day; chain(testDays))
{
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
if(day > maxDay(dt.year, dt.month))
continue;
auto expected = SysTime(DateTime(dt.year, dt.month, day, dt.hour, dt.minute, dt.second),
st.fracSec,
st.timezone);
st.day = day;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
foreach(tz; testTZs)
{
foreach(tod; testTODs)
{
foreach(fs; testFracSecs)
{
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(month; EnumMembers!Month)
{
auto st = SysTime(DateTime(Date(year, month, 1), tod), fs, tz);
immutable max = maxDay(year, month);
auto expected = SysTime(DateTime(Date(year, month, max), tod), fs, tz);
st.day = max;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
}
}
}
foreach(tz; testTZs)
{
foreach(tod; testTODsThrown)
{
foreach(fs; [testFracSecs[0], testFracSecs[$-1]])
{
foreach(year; [testYearsBC[$-3], testYearsBC[$-2],
testYearsBC[$-2], testYearsAD[0],
testYearsAD[$-2], testYearsAD[$-1]])
{
foreach(month; EnumMembers!Month)
{
auto st = SysTime(DateTime(Date(year, month, 1), tod), fs, tz);
immutable max = maxDay(year, month);
assertThrown!DateTimeException(st.day = max + 1);
}
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.day = 27));
//static assert(!__traits(compiles, ist.day = 27));
}
/++
Hours past midnight.
+/
@property ubyte hour() const nothrow
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
return cast(ubyte)getUnitsFromHNSecs!"hours"(hnsecs);
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, int expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.hour, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), 0);
test(SysTime(1, UTC()), 0);
test(SysTime(-1, UTC()), 23);
foreach(tz; testTZs)
{
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(hour; testHours)
{
foreach(minute; testMinSecs)
{
foreach(second; testMinSecs)
{
auto dt = DateTime(Date(year, md.month, md.day),
TimeOfDay(hour, minute, second));
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), hour);
}
}
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.hour));
//static assert(__traits(compiles, ist.hour));
}
/++
Hours past midnight.
Params:
hour = The hours to set this $(D SysTime)'s hour to.
Throws:
$(D DateTimeException) if the given hour are not a valid hour of
the day.
+/
@property void hour(int hour)
{
enforceValid!"hours"(hour);
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs);
immutable daysHNSecs = convert!("days", "hnsecs")(days);
immutable negative = hnsecs < 0;
if(negative)
hnsecs += convert!("hours", "hnsecs")(24);
hnsecs = removeUnitsFromHNSecs!"hours"(hnsecs);
hnsecs += convert!("hours", "hnsecs")(hour);
if(negative)
hnsecs -= convert!("hours", "hnsecs")(24);
adjTime = daysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
foreach(hour; chain(testHours))
{
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
auto expected = SysTime(DateTime(dt.year, dt.month, dt.day, hour, dt.minute, dt.second),
st.fracSec,
st.timezone);
st.hour = hour;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
auto st = testSysTimesAD[0];
assertThrown!DateTimeException(st.hour = -1);
assertThrown!DateTimeException(st.hour = 60);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.hour = 27));
//static assert(!__traits(compiles, ist.hour = 27));
}
/++
Minutes past the current hour.
+/
@property ubyte minute() const nothrow
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
hnsecs = removeUnitsFromHNSecs!"hours"(hnsecs);
return cast(ubyte)getUnitsFromHNSecs!"minutes"(hnsecs);
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, int expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.minute, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), 0);
test(SysTime(1, UTC()), 0);
test(SysTime(-1, UTC()), 59);
foreach(tz; testTZs)
{
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(hour; testHours)
{
foreach(minute; testMinSecs)
{
foreach(second; testMinSecs)
{
auto dt = DateTime(Date(year, md.month, md.day),
TimeOfDay(hour, minute, second));
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), minute);
}
}
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.minute));
//static assert(__traits(compiles, ist.minute));
}
/++
Minutes past the current hour.
Params:
minutes = The minute to set this $(D SysTime)'s minute to.
Throws:
$(D DateTimeException) if the given minute are not a valid minute
of an hour.
+/
@property void minute(int minute)
{
enforceValid!"minutes"(minute);
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs);
immutable daysHNSecs = convert!("days", "hnsecs")(days);
immutable negative = hnsecs < 0;
if(negative)
hnsecs += convert!("hours", "hnsecs")(24);
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
hnsecs = removeUnitsFromHNSecs!"minutes"(hnsecs);
hnsecs += convert!("hours", "hnsecs")(hour);
hnsecs += convert!("minutes", "hnsecs")(minute);
if(negative)
hnsecs -= convert!("hours", "hnsecs")(24);
adjTime = daysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
foreach(minute; testMinSecs)
{
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
auto expected = SysTime(DateTime(dt.year, dt.month, dt.day, dt.hour, minute, dt.second),
st.fracSec,
st.timezone);
st.minute = minute;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
auto st = testSysTimesAD[0];
assertThrown!DateTimeException(st.minute = -1);
assertThrown!DateTimeException(st.minute = 60);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.minute = 27));
//static assert(!__traits(compiles, ist.minute = 27));
}
/++
Seconds past the current minute.
+/
@property ubyte second() const nothrow
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
hnsecs = removeUnitsFromHNSecs!"hours"(hnsecs);
hnsecs = removeUnitsFromHNSecs!"minutes"(hnsecs);
return cast(ubyte)getUnitsFromHNSecs!"seconds"(hnsecs);
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, int expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.second, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), 0);
test(SysTime(1, UTC()), 0);
test(SysTime(-1, UTC()), 59);
foreach(tz; testTZs)
{
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(hour; testHours)
{
foreach(minute; testMinSecs)
{
foreach(second; testMinSecs)
{
auto dt = DateTime(Date(year, md.month, md.day),
TimeOfDay(hour, minute, second));
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), second);
}
}
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.second));
//static assert(__traits(compiles, ist.second));
}
/++
Seconds past the current minute.
Params:
second = The second to set this $(D SysTime)'s second to.
Throws:
$(D DateTimeException) if the given second are not a valid second
of a minute.
+/
@property void second(int second)
{
enforceValid!"seconds"(second);
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs);
immutable daysHNSecs = convert!("days", "hnsecs")(days);
immutable negative = hnsecs < 0;
if(negative)
hnsecs += convert!("hours", "hnsecs")(24);
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
hnsecs = removeUnitsFromHNSecs!"seconds"(hnsecs);
hnsecs += convert!("hours", "hnsecs")(hour);
hnsecs += convert!("minutes", "hnsecs")(minute);
hnsecs += convert!("seconds", "hnsecs")(second);
if(negative)
hnsecs -= convert!("hours", "hnsecs")(24);
adjTime = daysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
foreach(second; testMinSecs)
{
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
auto expected = SysTime(DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, second),
st.fracSec,
st.timezone);
st.second = second;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
auto st = testSysTimesAD[0];
assertThrown!DateTimeException(st.second = -1);
assertThrown!DateTimeException(st.second = 60);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.seconds = 27));
//static assert(!__traits(compiles, ist.seconds = 27));
}
/++
Fractional seconds passed the second.
+/
@property FracSec fracSec() const nothrow
{
try
{
auto hnsecs = removeUnitsFromHNSecs!"days"(adjTime);
if(hnsecs < 0)
hnsecs += convert!("hours", "hnsecs")(24);
hnsecs = removeUnitsFromHNSecs!"seconds"(hnsecs);
return FracSec.from!"hnsecs"(cast(int)hnsecs);
}
catch(Exception e)
assert(0, "FracSec.from!\"hnsecs\"() threw.");
}
version(testStdDateTime) unittest
{
static void test(SysTime sysTime, FracSec expected, size_t line = __LINE__)
{
_assertPred!"=="(sysTime.fracSec, expected,
format("Value given: %s", sysTime), __FILE__, line);
}
test(SysTime(0, UTC()), FracSec.from!"hnsecs"(0));
test(SysTime(1, UTC()), FracSec.from!"hnsecs"(1));
test(SysTime(-1, UTC()), FracSec.from!"hnsecs"(9_999_999));
foreach(tz; testTZs)
{
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(hour; testHours)
{
foreach(minute; testMinSecs)
{
foreach(second; testMinSecs)
{
auto dt = DateTime(Date(year, md.month, md.day),
TimeOfDay(hour, minute, second));
foreach(fs; testFracSecs)
test(SysTime(dt, fs, tz), fs);
}
}
}
}
}
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.fracSec));
//static assert(__traits(compiles, ist.fracSec));
}
/++
Fractional seconds passed the second.
Params:
fracSec = The fractional seconds to set this $(D SysTimes)'s
fractional seconds to.
Throws:
$(D DateTimeException) if $(D fracSec) is negative.
+/
@property void fracSec(FracSec fracSec)
{
immutable fracHNSecs = fracSec.hnsecs;
enforce(fracHNSecs >= 0, new DateTimeException("A SysTime cannot have negative fractional seconds."));
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs);
immutable daysHNSecs = convert!("days", "hnsecs")(days);
immutable negative = hnsecs < 0;
if(negative)
hnsecs += convert!("hours", "hnsecs")(24);
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable second = getUnitsFromHNSecs!"seconds"(hnsecs);
hnsecs = fracHNSecs;
hnsecs += convert!("hours", "hnsecs")(hour);
hnsecs += convert!("minutes", "hnsecs")(minute);
hnsecs += convert!("seconds", "hnsecs")(second);
if(negative)
hnsecs -= convert!("hours", "hnsecs")(24);
adjTime = daysHNSecs + hnsecs;
}
version(testStdDateTime) unittest
{
foreach(fracSec; testFracSecs)
{
foreach(st; chain(testSysTimesBC, testSysTimesAD))
{
auto dt = cast(DateTime)st;
auto expected = SysTime(DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second),
fracSec,
st.timezone);
st.fracSec = fracSec;
assert(st == expected, format("[%s] [%s]", st, expected));
}
}
auto st = testSysTimesAD[0];
assertThrown!DateTimeException(st.fracSec = FracSec.from!"hnsecs"(-1));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.fracSec = FracSec.from!"msecs"(7)));
//static assert(!__traits(compiles, ist.fracSec = FracSec.from!"msecs"(7)));
}
/++
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the
internal representation of $(D SysTime).
+/
@property long stdTime() const pure nothrow
{
return _stdTime;
}
version(testStdDateTime) unittest
{
_assertPred!"=="(SysTime(0).stdTime, 0);
_assertPred!"=="(SysTime(1).stdTime, 1);
_assertPred!"=="(SysTime(-1).stdTime, -1);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 33), FracSec.from!"hnsecs"(502), UTC()).stdTime,
330000502L);
_assertPred!"=="(SysTime(DateTime(1970, 1, 1, 0, 0, 0), UTC()).stdTime,
621355968000000000L);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.stdTime));
//static assert(__traits(compiles, ist.stdTime));
}
/++
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the
internal representation of $(D SysTime).
Params:
stdTime = The number of hnsecs since January 1st, 1 A.D. UTC.
+/
@property void stdTime(long stdTime) pure nothrow
{
_stdTime = stdTime;
}
version(testStdDateTime) unittest
{
static void test(long stdTime, in SysTime expected, size_t line = __LINE__)
{
auto st = SysTime(0, UTC());
st.stdTime = stdTime;
_assertPred!"=="(st, expected);
}
test(0, SysTime(Date(1, 1, 1), UTC()));
test(1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1), UTC()));
test(-1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()));
test(330_000_502L, SysTime(DateTime(1, 1, 1, 0, 0, 33), FracSec.from!"hnsecs"(502), UTC()));
test(621_355_968_000_000_000L, SysTime(DateTime(1970, 1, 1, 0, 0, 0), UTC()));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.stdTime = 27));
//static assert(!__traits(compiles, ist.stdTime = 27));
}
/++
The current time zone of this $(D SysTime). Its internal time is always
kept in UTC, so there are no conversion issues between time zones due to
DST. Functions which return all or part of the time - such as hours -
adjust the time to this $(D SysTime)'s time zone before returning.
+/
@property immutable(TimeZone) timezone() const pure nothrow
{
return _timezone;
}
/++
The current time zone of this $(D SysTime). It's internal time is always
kept in UTC, so there are no conversion issues between time zones due to
DST. Functions which return all or part of the time - such as hours -
adjust the time to this $(D SysTime)'s time zone before returning.
Params:
tz = The $(D TimeZone) to set this $(D SysTime)'s time zone to.
+/
@property void timezone(immutable TimeZone timezone) pure nothrow
{
if(timezone is null)
_timezone = LocalTime();
else
_timezone = timezone;
}
/++
Returns whether DST is in effect for this $(D SysTime).
+/
@property bool dstInEffect() const nothrow
{
return _timezone.dstInEffect(_stdTime);
//This function's unit testing is done in the time zone classes.
}
/++
Returns what the offset from UTC is for this $(D SysTime).
It includes the DST offset in effect at that time (if any).
+/
@property Duration utcOffset() const nothrow
{
return _timezone.utcOffsetAt(_stdTime);
}
/++
Returns a $(D SysTime) with the same std time as this one, but with
$(D LocalTime) as its time zone.
+/
SysTime toLocalTime() const nothrow
{
return SysTime(_stdTime, LocalTime());
}
unittest
{
version(testStdDateTime)
{
{
auto sysTime = SysTime(DateTime(1982, 1, 4, 8, 59, 7), FracSec.from!"hnsecs"(27));
_assertPred!"=="(sysTime, sysTime.toLocalTime());
_assertPred!"=="(sysTime._stdTime, sysTime.toLocalTime()._stdTime);
assert(sysTime.toLocalTime().timezone is LocalTime());
assert(sysTime.toLocalTime().timezone is sysTime.timezone);
assert(sysTime.toLocalTime().timezone !is UTC());
}
{
immutable stz = new SimpleTimeZone(dur!"minutes"(-3 * 60));
auto sysTime = SysTime(DateTime(1982, 1, 4, 8, 59, 7), FracSec.from!"hnsecs"(27), stz);
_assertPred!"=="(sysTime, sysTime.toLocalTime());
_assertPred!"=="(sysTime._stdTime, sysTime.toLocalTime()._stdTime);
assert(sysTime.toLocalTime().timezone is LocalTime());
assert(sysTime.toLocalTime().timezone !is UTC());
assert(sysTime.toLocalTime().timezone !is stz);
}
}
}
/++
Returns a $(D SysTime) with the same std time as this one, but with
$(D UTC) as its time zone.
+/
SysTime toUTC() const pure nothrow
{
return SysTime(_stdTime, UTC());
}
unittest
{
version(testStdDateTime)
{
auto sysTime = SysTime(DateTime(1982, 1, 4, 8, 59, 7), FracSec.from!"hnsecs"(27));
_assertPred!"=="(sysTime, sysTime.toUTC());
_assertPred!"=="(sysTime._stdTime, sysTime.toUTC()._stdTime);
assert(sysTime.toUTC().timezone is UTC());
assert(sysTime.toUTC().timezone !is LocalTime());
assert(sysTime.toUTC().timezone !is sysTime.timezone);
}
}
/++
Returns a $(D SysTime) with the same std time as this one, but with
given time zone as its time zone.
+/
SysTime toOtherTZ(immutable TimeZone tz) const pure nothrow
{
if(tz is null)
return SysTime(_stdTime, LocalTime());
else
return SysTime(_stdTime, tz);
}
unittest
{
version(testStdDateTime)
{
immutable stz = new SimpleTimeZone(dur!"minutes"(11 * 60));
auto sysTime = SysTime(DateTime(1982, 1, 4, 8, 59, 7), FracSec.from!"hnsecs"(27));
_assertPred!"=="(sysTime, sysTime.toOtherTZ(stz));
_assertPred!"=="(sysTime._stdTime, sysTime.toOtherTZ(stz)._stdTime);
assert(sysTime.toOtherTZ(stz).timezone is stz);
assert(sysTime.toOtherTZ(stz).timezone !is LocalTime());
assert(sysTime.toOtherTZ(stz).timezone !is UTC());
}
}
/++
Returns a $(D time_t) which represents the same time as this
$(D SysTime).
Note that like all conversions in std.datetime, this is a truncating
conversion.
If $(D time_t) is 32 bits, rather than 64, and the result can't fit in a
32-bit value, then the closest value that can be held in 32 bits will be
used (so $(D time_t.max) if it goes over and $(D time_t.min) if it goes
under).
+/
time_t toUnixTime() const pure nothrow
{
return stdTimeToUnixTime(_stdTime);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(SysTime(DateTime(1970, 1, 1), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1970, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1970, 1, 1, 0, 0, 0), FracSec.from!"usecs"(1), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1970, 1, 1, 0, 0, 0), FracSec.from!"msecs"(1), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1970, 1, 1, 0, 0, 1), UTC()).toUnixTime(), 1);
_assertPred!"=="(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"usecs"(999_999), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999), UTC()).toUnixTime(), 0);
_assertPred!"=="(SysTime(DateTime(1969, 12, 31, 23, 59, 59), UTC()).toUnixTime(), -1);
}
}
/++
Returns a $(D timeval) which represents this $(D SysTime).
Note that like all conversions in std.datetime, this is a truncating
conversion.
If $(D time_t) is 32 bits, rather than 64, and the result can't fit in a
32-bit value, then the closest value that can be held in 32 bits will be
used for $(D tv_sec). (so $(D time_t.max) if it goes over and
$(D time_t.min) if it goes under).
+/
timeval toTimeVal() const pure nothrow
{
immutable tv_sec = toUnixTime();
immutable fracHNSecs = removeUnitsFromHNSecs!"seconds"(_stdTime - 621355968000000000L);
immutable tv_usec = cast(int)convert!("hnsecs", "usecs")(fracHNSecs);
return timeval(tv_sec, tv_usec);
}
unittest
{
version(testStdDateTime)
{
assert(SysTime(DateTime(1970, 1, 1), UTC()).toTimeVal() == timeval(0, 0));
assert(SysTime(DateTime(1970, 1, 1), FracSec.from!"hnsecs"(9), UTC()).toTimeVal() == timeval(0, 0));
assert(SysTime(DateTime(1970, 1, 1), FracSec.from!"hnsecs"(10), UTC()).toTimeVal() == timeval(0, 1));
assert(SysTime(DateTime(1970, 1, 1), FracSec.from!"usecs"(7), UTC()).toTimeVal() == timeval(0, 7));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), UTC()).toTimeVal() == timeval(1, 0));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), FracSec.from!"hnsecs"(9), UTC()).toTimeVal() == timeval(1, 0));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), FracSec.from!"hnsecs"(10), UTC()).toTimeVal() == timeval(1, 1));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), FracSec.from!"usecs"(7), UTC()).toTimeVal() == timeval(1, 7));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()).toTimeVal() ==
timeval(0, 0));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_990), UTC()).toTimeVal() ==
timeval(0, -1));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"usecs"(999_999), UTC()).toTimeVal() ==
timeval(0, -1));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"usecs"(999), UTC()).toTimeVal() ==
timeval(0, -999_001));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999), UTC()).toTimeVal() ==
timeval(0, -1000));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 59), UTC()).toTimeVal() == timeval(-1, 0));
assert(SysTime(DateTime(1969, 12, 31, 23, 59, 58), FracSec.from!"usecs"(17), UTC()).toTimeVal() ==
timeval(-1, -999_983));
}
}
/++
Returns a $(D tm) which represents this $(D SysTime).
+/
tm toTM() const nothrow
{
try
{
auto dateTime = cast(DateTime)this;
tm timeInfo;
timeInfo.tm_sec = dateTime.second;
timeInfo.tm_min = dateTime.minute;
timeInfo.tm_hour = dateTime.hour;
timeInfo.tm_mday = dateTime.day;
timeInfo.tm_mon = dateTime.month - 1;
timeInfo.tm_year = dateTime.year - 1900;
timeInfo.tm_wday = dateTime.dayOfWeek;
timeInfo.tm_yday = dateTime.dayOfYear - 1;
timeInfo.tm_isdst = _timezone.dstInEffect(_stdTime);
version(Posix)
{
char[] zone = (timeInfo.tm_isdst ? _timezone.dstName : _timezone.stdName).dup;
zone ~= "\0";
timeInfo.tm_gmtoff = cast(int)convert!("hnsecs", "seconds")(adjTime - _stdTime);
timeInfo.tm_zone = zone.ptr;
}
return timeInfo;
}
catch(Exception e)
assert(0, "Either DateTime's constructor threw.");
}
unittest
{
version(testStdDateTime)
{
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("America/Los_Angeles");
}
{
auto timeInfo = SysTime(DateTime(1970, 1, 1)).toTM();
_assertPred!"=="(timeInfo.tm_sec, 0);
_assertPred!"=="(timeInfo.tm_min, 0);
_assertPred!"=="(timeInfo.tm_hour, 0);
_assertPred!"=="(timeInfo.tm_mday, 1);
_assertPred!"=="(timeInfo.tm_mon, 0);
_assertPred!"=="(timeInfo.tm_year, 70);
_assertPred!"=="(timeInfo.tm_wday, 4);
_assertPred!"=="(timeInfo.tm_yday, 0);
version(Posix)
_assertPred!"=="(timeInfo.tm_isdst, 0);
else version(Windows)
assert(timeInfo.tm_isdst == 0 || timeInfo.tm_isdst == 1);
version(Posix)
{
_assertPred!"=="(timeInfo.tm_gmtoff, -8 * 60 * 60);
_assertPred!"=="(to!string(timeInfo.tm_zone), "PST");
}
}
{
auto timeInfo = SysTime(DateTime(2010, 7, 4, 12, 15, 7), FracSec.from!"hnsecs"(15)).toTM();
_assertPred!"=="(timeInfo.tm_sec, 7);
_assertPred!"=="(timeInfo.tm_min, 15);
_assertPred!"=="(timeInfo.tm_hour, 12);
_assertPred!"=="(timeInfo.tm_mday, 4);
_assertPred!"=="(timeInfo.tm_mon, 6);
_assertPred!"=="(timeInfo.tm_year, 110);
_assertPred!"=="(timeInfo.tm_wday, 0);
_assertPred!"=="(timeInfo.tm_yday, 184);
version(Posix)
_assertPred!"=="(timeInfo.tm_isdst, 1);
else version(Windows)
assert(timeInfo.tm_isdst == 0 || timeInfo.tm_isdst == 1);
version(Posix)
{
_assertPred!"=="(timeInfo.tm_gmtoff, -7 * 60 * 60);
_assertPred!"=="(to!string(timeInfo.tm_zone), "PDT");
}
}
}
}
/++
Adds the given number of years or months to this $(D SysTime). A
negative number will subtract.
Note that if day overflow is allowed, and the date with the adjusted
year/month overflows the number of days in the new month, then the month
will be incremented by one, and the day set to the number of days
overflowed. (e.g. if the day were 31 and the new month were June, then
the month would be incremented to July, and the new day would be 1). If
day overflow is not allowed, then the day will be set to the last valid
day in the month (e.g. June 31st would become June 30th).
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D SysTime).
allowOverflow = Whether the days should be allowed to overflow,
causing the month to increment.
Examples:
--------------------
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 30, 33));
st1.add!"months"(11);
assert(st1 == SysTime(DateTime(2010, 12, 1, 12, 30, 33)));
auto st2 = SysTime(DateTime(2010, 1, 1, 12, 30, 33));
st2.add!"months"(-11);
assert(st2 == SysTime(DateTime(2009, 2, 1, 12, 30, 33)));
auto st3 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st3.add!"years"(1);
assert(st3 == SysTime(DateTime(2001, 3, 1, 12, 30, 33)));
auto st4 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st4.add!"years"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
--------------------
+/
ref SysTime add(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) nothrow
if(units == "years" ||
units == "months")
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.add!units(value, allowOverflow);
days = date.dayOfGregorianCal - 1;
if(days < 0)
{
hnsecs -= convert!("hours", "hnsecs")(24);
++days;
}
immutable newDaysHNSecs = convert!("days", "hnsecs")(days);
adjTime = newDaysHNSecs + hnsecs;
return this;
}
//Verify Examples.
unittest
{
version (testStdDateTime)
{
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 30, 33));
st1.add!"months"(11);
assert(st1 == SysTime(DateTime(2010, 12, 1, 12, 30, 33)));
auto st2 = SysTime(DateTime(2010, 1, 1, 12, 30, 33));
st2.add!"months"(-11);
assert(st2 == SysTime(DateTime(2009, 2, 1, 12, 30, 33)));
auto st3 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st3.add!"years"(1);
assert(st3 == SysTime(DateTime(2001, 3, 1, 12, 30, 33)));
auto st4 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st4.add!"years"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
}
}
//Test add!"years"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"years"(7);
_assertPred!"=="(sysTime, SysTime(Date(2006, 7, 6)));
sysTime.add!"years"(-9);
_assertPred!"=="(sysTime, SysTime(Date(1997, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 3, 1)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234));
sysTime.add!"years"(7);
_assertPred!"=="(sysTime, SysTime(DateTime(2006, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
sysTime.add!"years"(-9);
_assertPred!"=="(sysTime, SysTime(DateTime(1997, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
}
{
auto sysTime = SysTime(DateTime(1999, 2, 28, 0, 7, 2), FracSec.from!"usecs"(1207));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(2000, 2, 28, 0, 7, 2), FracSec.from!"usecs"(1207)));
}
{
auto sysTime = SysTime(DateTime(2000, 2, 29, 0, 7, 2), FracSec.from!"usecs"(1207));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 3, 1, 0, 7, 2), FracSec.from!"usecs"(1207)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"years"(-7);
_assertPred!"=="(sysTime, SysTime(Date(-2006, 7, 6)));
sysTime.add!"years"(9);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 3, 1)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234));
sysTime.add!"years"(-7);
_assertPred!"=="(sysTime, SysTime(DateTime(-2006, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
sysTime.add!"years"(9);
_assertPred!"=="(sysTime, SysTime(DateTime(-1997, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
}
{
auto sysTime = SysTime(DateTime(-1999, 2, 28, 3, 3, 3), FracSec.from!"hnsecs"(3));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(-2000, 2, 28, 3, 3, 3), FracSec.from!"hnsecs"(3)));
}
{
auto sysTime = SysTime(DateTime(-2000, 2, 29, 3, 3, 3), FracSec.from!"hnsecs"(3));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 3, 1, 3, 3, 3), FracSec.from!"hnsecs"(3)));
}
//Test Both
{
auto sysTime = SysTime(Date(4, 7, 6));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(Date(-1, 7, 6)));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 7, 6));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 6)));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
}
{
auto sysTime = SysTime(Date(4, 7, 6));
sysTime.add!"years"(-8);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
sysTime.add!"years"(8);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 7, 6));
sysTime.add!"years"(8);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
sysTime.add!"years"(-8);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 2, 29));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(Date(1, 3, 1)));
}
{
auto sysTime = SysTime(Date(4, 2, 29));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(Date(-1, 3, 1)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"years"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"years"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(DateTime(-1, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
}
{
auto sysTime = SysTime(DateTime(-4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(DateTime(-4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
}
{
auto sysTime = SysTime(DateTime(-4, 2, 29, 5, 5, 5), FracSec.from!"msecs"(555));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 3, 1, 5, 5, 5), FracSec.from!"msecs"(555)));
}
{
auto sysTime = SysTime(DateTime(4, 2, 29, 5, 5, 5), FracSec.from!"msecs"(555));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(DateTime(-1, 3, 1, 5, 5, 5), FracSec.from!"msecs"(555)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.add!"years"(4)));
//static assert(!__traits(compiles, ist.add!"years"(4)));
}
}
//Test add!"years"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"years"(7, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2006, 7, 6)));
sysTime.add!"years"(-9, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234));
sysTime.add!"years"(7, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(2006, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
sysTime.add!"years"(-9, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1997, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
}
{
auto sysTime = SysTime(DateTime(1999, 2, 28, 0, 7, 2), FracSec.from!"usecs"(1207));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(2000, 2, 28, 0, 7, 2), FracSec.from!"usecs"(1207)));
}
{
auto sysTime = SysTime(DateTime(2000, 2, 29, 0, 7, 2), FracSec.from!"usecs"(1207));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 2, 28, 0, 7, 2), FracSec.from!"usecs"(1207)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"years"(-7, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2006, 7, 6)));
sysTime.add!"years"(9, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 28)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234));
sysTime.add!"years"(-7, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2006, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
sysTime.add!"years"(9, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1997, 7, 6, 12, 7, 3), FracSec.from!"msecs"(234)));
}
{
auto sysTime = SysTime(DateTime(-1999, 2, 28, 3, 3, 3), FracSec.from!"hnsecs"(3));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2000, 2, 28, 3, 3, 3), FracSec.from!"hnsecs"(3)));
}
{
auto sysTime = SysTime(DateTime(-2000, 2, 29, 3, 3, 3), FracSec.from!"hnsecs"(3));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 2, 28, 3, 3, 3), FracSec.from!"hnsecs"(3)));
}
//Test Both
{
auto sysTime = SysTime(Date(4, 7, 6));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1, 7, 6)));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 7, 6));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 6)));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
}
{
auto sysTime = SysTime(Date(4, 7, 6));
sysTime.add!"years"(-8, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
sysTime.add!"years"(8, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 7, 6));
sysTime.add!"years"(8, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 7, 6)));
sysTime.add!"years"(-8, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 7, 6)));
}
{
auto sysTime = SysTime(Date(-4, 2, 29));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1, 2, 28)));
}
{
auto sysTime = SysTime(Date(4, 2, 29));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1, 2, 28)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329));
sysTime.add!"years"(-5);
_assertPred!"=="(sysTime, SysTime(DateTime(-1, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
sysTime.add!"years"(5);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
}
{
auto sysTime = SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
}
{
auto sysTime = SysTime(DateTime(-4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-4, 7, 6, 14, 7, 1), FracSec.from!"usecs"(54329)));
}
{
auto sysTime = SysTime(DateTime(-4, 2, 29, 5, 5, 5), FracSec.from!"msecs"(555));
sysTime.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 2, 28, 5, 5, 5), FracSec.from!"msecs"(555)));
}
{
auto sysTime = SysTime(DateTime(4, 2, 29, 5, 5, 5), FracSec.from!"msecs"(555));
sysTime.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1, 2, 28, 5, 5, 5), FracSec.from!"msecs"(555)));
}
}
}
//Test add!"months"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(3);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.add!"months"(-4);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(6);
_assertPred!"=="(sysTime, SysTime(Date(2000, 1, 6)));
sysTime.add!"months"(-6);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(27);
_assertPred!"=="(sysTime, SysTime(Date(2001, 10, 6)));
sysTime.add!"months"(-28);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 1)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 5, 1)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.add!"months"(12);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.add!"months"(12);
_assertPred!"=="(sysTime, SysTime(Date(2001, 3, 1)));
}
{
auto sysTime = SysTime(Date(1999, 7, 31));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 8, 31)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 1)));
}
{
auto sysTime = SysTime(Date(1998, 8, 31));
sysTime.add!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 1)));
sysTime.add!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(1998, 9, 1)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.add!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 31)));
sysTime.add!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(1999, 3, 3)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(1998, 1, 3)));
}
{
auto sysTime = SysTime(Date(1998, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(2000, 3, 2)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 2)));
}
{
auto sysTime = SysTime(Date(1999, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(2001, 3, 3)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(2000, 1, 3)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.add!"months"(3);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.add!"months"(-4);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(1998, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(2000, 3, 2, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 1, 2, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(1999, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(2001, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(2000, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(3);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 6)));
sysTime.add!"months"(-4);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(6);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 1, 6)));
sysTime.add!"months"(-6);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(-27);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 4, 6)));
sysTime.add!"months"(28);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 5, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.add!"months"(-12);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.add!"months"(-12);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 3, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 31));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 31)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 1)));
}
{
auto sysTime = SysTime(Date(-1998, 8, 31));
sysTime.add!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 10, 1)));
sysTime.add!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 9, 1)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.add!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(-1995, 1, 31)));
sysTime.add!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-1995, 3, 3)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-1996, 1, 3)));
}
{
auto sysTime = SysTime(Date(-2002, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 3, 2)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 1, 2)));
}
{
auto sysTime = SysTime(Date(-2001, 12, 31));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 3, 3)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 1, 3)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.add!"months"(3);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.add!"months"(-4);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(-2002, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2000, 3, 2, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 1, 2, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(-2001, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2000, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test Both
{
auto sysTime = SysTime(Date(1, 1, 1));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(0, 12, 1)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 1, 1));
sysTime.add!"months"(-48);
_assertPred!"=="(sysTime, SysTime(Date(0, 1, 1)));
sysTime.add!"months"(48);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.add!"months"(-49);
_assertPred!"=="(sysTime, SysTime(Date(0, 3, 2)));
sysTime.add!"months"(49);
_assertPred!"=="(sysTime, SysTime(Date(4, 4, 2)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.add!"months"(-85);
_assertPred!"=="(sysTime, SysTime(Date(-3, 3, 3)));
sysTime.add!"months"(85);
_assertPred!"=="(sysTime, SysTime(Date(4, 4, 3)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17));
sysTime.add!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
sysTime.add!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
}
{
auto sysTime = SysTime(DateTime(4, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.add!"months"(-85);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 3, 3, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.add!"months"(85);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 4, 3, 12, 11, 10), FracSec.from!"msecs"(9)));
}
{
auto sysTime = SysTime(DateTime(-3, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.add!"months"(85);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 5, 1, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.add!"months"(-85);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 4, 1, 12, 11, 10), FracSec.from!"msecs"(9)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.add!"months"(4)));
//static assert(!__traits(compiles, ist.add!"months"(4)));
}
}
//Test add!"months"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2000, 1, 6)));
sysTime.add!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.add!"months"(27, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2001, 10, 6)));
sysTime.add!"months"(-28, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 4, 30)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.add!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.add!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2001, 2, 28)));
}
{
auto sysTime = SysTime(Date(1999, 7, 31));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 8, 31)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 9, 30)));
}
{
auto sysTime = SysTime(Date(1998, 8, 31));
sysTime.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 9, 30)));
sysTime.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 8, 30)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 31)));
sysTime.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 28)));
}
{
auto sysTime = SysTime(Date(1998, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 29)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 12, 29)));
}
{
auto sysTime = SysTime(Date(1999, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2001, 2, 28)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 12, 28)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(1998, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(2000, 2, 29, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1998, 12, 29, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(1999, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(2001, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 6)));
sysTime.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 1, 6)));
sysTime.add!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.add!"months"(-27, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 4, 6)));
sysTime.add!"months"(28, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 4, 30)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.add!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.add!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 2, 28)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 31));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 31)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 9, 30)));
}
{
auto sysTime = SysTime(Date(-1998, 8, 31));
sysTime.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 9, 30)));
sysTime.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 8, 30)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1995, 1, 31)));
sysTime.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1995, 2, 28)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 28)));
}
{
auto sysTime = SysTime(Date(-2002, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 29)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2002, 12, 29)));
}
{
auto sysTime = SysTime(Date(-2001, 12, 31));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 28)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 12, 28)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(-2002, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2000, 2, 29, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2002, 12, 29, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(-2001, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test Both
{
auto sysTime = SysTime(Date(1, 1, 1));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(0, 12, 1)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 1, 1));
sysTime.add!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(0, 1, 1)));
sysTime.add!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.add!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(0, 2, 29)));
sysTime.add!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 29)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.add!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-3, 2, 28)));
sysTime.add!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 28)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17));
sysTime.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
sysTime.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
}
{
auto sysTime = SysTime(DateTime(4, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.add!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 2, 28, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.add!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 3, 28, 12, 11, 10), FracSec.from!"msecs"(9)));
}
{
auto sysTime = SysTime(DateTime(-3, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.add!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 4, 30, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.add!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 3, 30, 12, 11, 10), FracSec.from!"msecs"(9)));
}
}
}
/++
Adds the given number of years or months to this $(D SysTime). A
negative number will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. Rolling a $(D SysTime) 12 months
gets the exact same $(D SysTime). However, the days can still be affected
due to the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D SysTime).
allowOverflow = Whether the days should be allowed to overflow,
causing the month to increment.
Examples:
--------------------
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st1.roll!"months"(1);
assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33)));
auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st2.roll!"months"(-1);
assert(st2 == SysTime(DateTime(2010, 12, 1, 12, 33, 33)));
auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st3.roll!"months"(1);
assert(st3 == SysTime(DateTime(1999, 3, 1, 12, 33, 33)));
auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st4.roll!"months"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(1999, 2, 28, 12, 33, 33)));
auto st5 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st5.roll!"years"(1);
assert(st5 == SysTime(DateTime(2001, 3, 1, 12, 30, 33)));
auto st6 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st6.roll!"years"(1, AllowDayOverflow.no);
assert(st6 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
--------------------
+/
/+ref SysTime+/ void roll(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) nothrow
if(units == "years")
{
add!"years"(value, allowOverflow);
}
unittest
{
version(testStdDateTime)
{
//Verify Examples.
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st1.roll!"months"(1);
assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33)));
auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st2.roll!"months"(-1);
assert(st2 == SysTime(DateTime(2010, 12, 1, 12, 33, 33)));
auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st3.roll!"months"(1);
assert(st3 == SysTime(DateTime(1999, 3, 1, 12, 33, 33)));
auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st4.roll!"months"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(1999, 2, 28, 12, 33, 33)));
auto st5 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st5.roll!"years"(1);
assert(st5 == SysTime(DateTime(2001, 3, 1, 12, 30, 33)));
auto st6 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st6.roll!"years"(1, AllowDayOverflow.no);
assert(st6 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
}
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.roll!"years"(4)));
static assert(!__traits(compiles, cst.roll!"years"(4)));
//static assert(!__traits(compiles, ist.roll!"years"(4)));
}
}
//Shares documentation with "years" version.
/+ref SysTime+/ void roll(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) nothrow
if(units == "months")
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto date = Date(cast(int)days);
date.roll!"months"(value, allowOverflow);
days = date.dayOfGregorianCal - 1;
if(days < 0)
{
hnsecs -= convert!("hours", "hnsecs")(24);
++days;
}
immutable newDaysHNSecs = convert!("days", "hnsecs")(days);
adjTime = newDaysHNSecs + hnsecs;
}
//Test roll!"months"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(3);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.roll!"months"(-4);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(6);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 6)));
sysTime.roll!"months"(-6);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(27);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.roll!"months"(-28);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 1)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 5, 1)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.roll!"months"(12);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.roll!"months"(12);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(1999, 7, 31));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 8, 31)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 1)));
}
{
auto sysTime = SysTime(Date(1998, 8, 31));
sysTime.roll!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(1998, 10, 1)));
sysTime.roll!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(1998, 9, 1)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.roll!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(1997, 1, 31)));
sysTime.roll!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(1997, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(1997, 1, 3)));
}
{
auto sysTime = SysTime(Date(1998, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(1998, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(1998, 1, 3)));
}
{
auto sysTime = SysTime(Date(1999, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(1999, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 3)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.roll!"months"(3);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.roll!"months"(-4);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(1998, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(1998, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(1998, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(1999, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(3);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 6)));
sysTime.roll!"months"(-4);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(6);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 1, 6)));
sysTime.roll!"months"(-6);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(-27);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 4, 6)));
sysTime.roll!"months"(28);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 5, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.roll!"months"(-12);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.roll!"months"(-12);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 31));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 31)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 1)));
}
{
auto sysTime = SysTime(Date(-1998, 8, 31));
sysTime.roll!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 10, 1)));
sysTime.roll!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 9, 1)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.roll!"months"(13);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 1, 31)));
sysTime.roll!"months"(-13);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 1, 3)));
}
{
auto sysTime = SysTime(Date(-2002, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-2002, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-2002, 1, 3)));
}
{
auto sysTime = SysTime(Date(-2001, 12, 31));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 3, 3)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 1, 3)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 2, 7), FracSec.from!"hnsecs"(5007));
sysTime.roll!"months"(3);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 10, 6, 12, 2, 7), FracSec.from!"hnsecs"(5007)));
sysTime.roll!"months"(-4);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 6, 6, 12, 2, 7), FracSec.from!"hnsecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(-2002, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2002, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2002, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(-2001, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 3, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 1, 3, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test Both
{
auto sysTime = SysTime(Date(1, 1, 1));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1, 12, 1)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(1, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 1, 1));
sysTime.roll!"months"(-48);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
sysTime.roll!"months"(48);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.roll!"months"(-49);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 2)));
sysTime.roll!"months"(49);
_assertPred!"=="(sysTime, SysTime(Date(4, 4, 2)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.roll!"months"(-85);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 2)));
sysTime.roll!"months"(85);
_assertPred!"=="(sysTime, SysTime(Date(4, 4, 2)));
}
{
auto sysTime = SysTime(Date(-1, 1, 1));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1, 12, 1)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1, 1, 1)));
}
{
auto sysTime = SysTime(Date(-4, 1, 1));
sysTime.roll!"months"(-48);
_assertPred!"=="(sysTime, SysTime(Date(-4, 1, 1)));
sysTime.roll!"months"(48);
_assertPred!"=="(sysTime, SysTime(Date(-4, 1, 1)));
}
{
auto sysTime = SysTime(Date(-4, 3, 31));
sysTime.roll!"months"(-49);
_assertPred!"=="(sysTime, SysTime(Date(-4, 3, 2)));
sysTime.roll!"months"(49);
_assertPred!"=="(sysTime, SysTime(Date(-4, 4, 2)));
}
{
auto sysTime = SysTime(Date(-4, 3, 31));
sysTime.roll!"months"(-85);
_assertPred!"=="(sysTime, SysTime(Date(-4, 3, 2)));
sysTime.roll!"months"(85);
_assertPred!"=="(sysTime, SysTime(Date(-4, 4, 2)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17));
sysTime.roll!"months"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
sysTime.roll!"months"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
}
{
auto sysTime = SysTime(DateTime(4, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.roll!"months"(-85);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 3, 2, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.roll!"months"(85);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 4, 2, 12, 11, 10), FracSec.from!"msecs"(9)));
}
{
auto sysTime = SysTime(DateTime(-3, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.roll!"months"(85);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 5, 1, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.roll!"months"(-85);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 4, 1, 12, 11, 10), FracSec.from!"msecs"(9)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"months"(4)));
//static assert(!__traits(compiles, ist.roll!"months"(4)));
//Verify Examples.
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st1.roll!"months"(1);
assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33)));
auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st2.roll!"months"(-1);
assert(st2 == SysTime(DateTime(2010, 12, 1, 12, 33, 33)));
auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st3.roll!"months"(1);
assert(st3 == SysTime(DateTime(1999, 3, 1, 12, 33, 33)));
auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st4.roll!"months"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(1999, 2, 28, 12, 33, 33)));
}
}
//Test roll!"months"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 6)));
sysTime.roll!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"months"(27, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 10, 6)));
sysTime.roll!"months"(-28, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(1999, 5, 31));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 4, 30)));
}
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.roll!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 29));
sysTime.roll!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(1999, 7, 31));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 8, 31)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 9, 30)));
}
{
auto sysTime = SysTime(Date(1998, 8, 31));
sysTime.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 9, 30)));
sysTime.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 8, 30)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 1, 31)));
sysTime.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(1997, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1997, 12, 28)));
}
{
auto sysTime = SysTime(Date(1998, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1998, 12, 28)));
}
{
auto sysTime = SysTime(Date(1999, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1999, 12, 28)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(1998, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1998, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1998, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(1999, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 10, 6)));
sysTime.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 1, 6)));
sysTime.roll!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"months"(-27, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 4, 6)));
sysTime.roll!"months"(28, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 6)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(-1999, 5, 31));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 4, 30)));
}
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.roll!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 29));
sysTime.roll!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 31));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 8, 31)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 9, 30)));
}
{
auto sysTime = SysTime(Date(-1998, 8, 31));
sysTime.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 9, 30)));
sysTime.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1998, 8, 30)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 1, 31)));
sysTime.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 31)));
}
{
auto sysTime = SysTime(Date(-1997, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1997, 12, 28)));
}
{
auto sysTime = SysTime(Date(-2002, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2002, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2002, 12, 28)));
}
{
auto sysTime = SysTime(Date(-2001, 12, 31));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 2, 28)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-2001, 12, 28)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 12, 2, 7), FracSec.from!"usecs"(5007));
sysTime.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 10, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
sysTime.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 6, 6, 12, 2, 7), FracSec.from!"usecs"(5007)));
}
{
auto sysTime = SysTime(DateTime(-2002, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2002, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2002, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
{
auto sysTime = SysTime(DateTime(-2001, 12, 31, 7, 7, 7), FracSec.from!"hnsecs"(422202));
sysTime.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 2, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
sysTime.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-2001, 12, 28, 7, 7, 7), FracSec.from!"hnsecs"(422202)));
}
//Test Both
{
auto sysTime = SysTime(Date(1, 1, 1));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1, 12, 1)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(1, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 1, 1));
sysTime.roll!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
sysTime.roll!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 1, 1)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.roll!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 2, 29)));
sysTime.roll!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 29)));
}
{
auto sysTime = SysTime(Date(4, 3, 31));
sysTime.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 2, 29)));
sysTime.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(4, 3, 29)));
}
{
auto sysTime = SysTime(Date(-1, 1, 1));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1, 12, 1)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-1, 1, 1)));
}
{
auto sysTime = SysTime(Date(-4, 1, 1));
sysTime.roll!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 1, 1)));
sysTime.roll!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 1, 1)));
}
{
auto sysTime = SysTime(Date(-4, 3, 31));
sysTime.roll!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 2, 29)));
sysTime.roll!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 3, 29)));
}
{
auto sysTime = SysTime(Date(-4, 3, 31));
sysTime.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 2, 29)));
sysTime.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(Date(-4, 3, 29)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17));
sysTime.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 12, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
sysTime.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 7, 9), FracSec.from!"hnsecs"(17)));
}
{
auto sysTime = SysTime(DateTime(4, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 2, 29, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(4, 3, 29, 12, 11, 10), FracSec.from!"msecs"(9)));
}
{
auto sysTime = SysTime(DateTime(-3, 3, 31, 12, 11, 10), FracSec.from!"msecs"(9));
sysTime.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 4, 30, 12, 11, 10), FracSec.from!"msecs"(9)));
sysTime.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(sysTime, SysTime(DateTime(-3, 3, 30, 12, 11, 10), FracSec.from!"msecs"(9)));
}
}
}
/++
Adds the given number of units to this $(D SysTime). A negative number
will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. For instance, rolling a $(D SysTime) one
year's worth of days gets the exact same $(D SysTime).
Accepted units are $(D "days"), $(D "minutes"), $(D "hours"),
$(D "minutes"), $(D "seconds"), $(D "msecs"), $(D "usecs"), and
$(D "hnsecs").
Note that when rolling msecs, usecs or hnsecs, they all add up to a
second. So, for example, rolling 1000 msecs is exactly the same as
rolling 100,000 usecs.
Params:
units = The units to add.
value = The number of $(D_PARAM units) to add to this $(D SysTime).
Examples:
--------------------
auto st1 = SysTime(DateTime(2010, 1, 1, 11, 23, 12));
st1.roll!"days"(1);
assert(st1 == SysTime(DateTime(2010, 1, 2, 11, 23, 12)));
st1.roll!"days"(365);
assert(st1 == SysTime(DateTime(2010, 1, 26, 11, 23, 12)));
st1.roll!"days"(-32);
assert(st1 == SysTime(DateTime(2010, 1, 25, 11, 23, 12)));
auto st2 = SysTime(DateTime(2010, 7, 4, 12, 0, 0));
st2.roll!"hours"(1);
assert(st2 == SysTime(DateTime(2010, 7, 4, 13, 0, 0)));
auto st3 = SysTime(DateTime(2010, 1, 1, 0, 0, 0));
st3.roll!"seconds"(-1);
assert(st3 == SysTime(DateTime(2010, 1, 1, 0, 0, 59)));
auto st4 = SysTime(DateTime(2010, 1, 1, 0, 0, 0),
FracSec.from!"usecs"(2_400));
st4.roll!"usecs"(-1_200_000);
assert(st4 == SysTime(DateTime(2010, 1, 1, 0, 0, 0),
FracSec.from!"usecs"(802_400)));
--------------------
+/
/+ref SysTime+/ void roll(string units)(long value) nothrow
if(units == "days")
{
auto hnsecs = adjTime;
auto gdays = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--gdays;
}
auto date = Date(cast(int)gdays);
date.roll!"days"(value);
gdays = date.dayOfGregorianCal - 1;
if(gdays < 0)
{
hnsecs -= convert!("hours", "hnsecs")(24);
++gdays;
}
immutable newDaysHNSecs = convert!("days", "hnsecs")(gdays);
adjTime = newDaysHNSecs + hnsecs;
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto st1 = SysTime(DateTime(2010, 1, 1, 11, 23, 12));
st1.roll!"days"(1);
assert(st1 == SysTime(DateTime(2010, 1, 2, 11, 23, 12)));
st1.roll!"days"(365);
assert(st1 == SysTime(DateTime(2010, 1, 26, 11, 23, 12)));
st1.roll!"days"(-32);
assert(st1 == SysTime(DateTime(2010, 1, 25, 11, 23, 12)));
auto st2 = SysTime(DateTime(2010, 7, 4, 12, 0, 0));
st2.roll!"hours"(1);
assert(st2 == SysTime(DateTime(2010, 7, 4, 13, 0, 0)));
auto st3 = SysTime(DateTime(2010, 1, 1, 0, 0, 0));
st3.roll!"seconds"(-1);
assert(st3 == SysTime(DateTime(2010, 1, 1, 0, 0, 59)));
auto st4 = SysTime(DateTime(2010, 1, 1, 0, 0, 0),
FracSec.from!"usecs"(2_400));
st4.roll!"usecs"(-1_200_000);
assert(st4 == SysTime(DateTime(2010, 1, 1, 0, 0, 0),
FracSec.from!"usecs"(802_400)));
}
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto sysTime = SysTime(Date(1999, 2, 28));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(2000, 2, 28));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 29)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(1999, 6, 30));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(1999, 7, 31));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 31)));
}
{
auto sysTime = SysTime(Date(1999, 1, 1));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 31)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(1999, 1, 1)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"days"(9);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 15)));
sysTime.roll!"days"(-11);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 4)));
sysTime.roll!"days"(30);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 3)));
sysTime.roll!"days"(-3);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 31)));
}
{
auto sysTime = SysTime(Date(1999, 7, 6));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 30)));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
sysTime.roll!"days"(366);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 31)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 17)));
sysTime.roll!"days"(-1096);
_assertPred!"=="(sysTime, SysTime(Date(1999, 7, 6)));
}
{
auto sysTime = SysTime(Date(1999, 2, 6));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 7)));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 6)));
sysTime.roll!"days"(366);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 8)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 10)));
sysTime.roll!"days"(-1096);
_assertPred!"=="(sysTime, SysTime(Date(1999, 2, 6)));
}
{
auto sysTime = SysTime(DateTime(1999, 2, 28, 7, 9, 2), FracSec.from!"usecs"(234578));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 2, 1, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 2, 28, 7, 9, 2), FracSec.from!"usecs"(234578)));
}
{
auto sysTime = SysTime(DateTime(1999, 7, 6, 7, 9, 2), FracSec.from!"usecs"(234578));
sysTime.roll!"days"(9);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 7, 15, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-11);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 7, 4, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(30);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 7, 3, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-3);
_assertPred!"=="(sysTime, SysTime(DateTime(1999, 7, 31, 7, 9, 2), FracSec.from!"usecs"(234578)));
}
//Test B.C.
{
auto sysTime = SysTime(Date(-1999, 2, 28));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 2, 28)));
}
{
auto sysTime = SysTime(Date(-2000, 2, 28));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 29)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-2000, 2, 29)));
}
{
auto sysTime = SysTime(Date(-1999, 6, 30));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 6, 30)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 31));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 1)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 31)));
}
{
auto sysTime = SysTime(Date(-1999, 1, 1));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 1, 31)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 1, 1)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"days"(9);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 15)));
sysTime.roll!"days"(-11);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 4)));
sysTime.roll!"days"(30);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 3)));
sysTime.roll!"days"(-3);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 31)));
}
{
auto sysTime = SysTime(Date(-1999, 7, 6));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 30)));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
sysTime.roll!"days"(366);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 31)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 17)));
sysTime.roll!"days"(-1096);
_assertPred!"=="(sysTime, SysTime(Date(-1999, 7, 6)));
}
{
auto sysTime = SysTime(DateTime(-1999, 2, 28, 7, 9, 2), FracSec.from!"usecs"(234578));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 2, 1, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 2, 28, 7, 9, 2), FracSec.from!"usecs"(234578)));
}
{
auto sysTime = SysTime(DateTime(-1999, 7, 6, 7, 9, 2), FracSec.from!"usecs"(234578));
sysTime.roll!"days"(9);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 7, 15, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-11);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 7, 4, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(30);
_assertPred!"=="(sysTime, SysTime(DateTime(-1999, 7, 3, 7, 9, 2), FracSec.from!"usecs"(234578)));
sysTime.roll!"days"(-3);
}
//Test Both
{
auto sysTime = SysTime(Date(1, 7, 6));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 13)));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 6)));
sysTime.roll!"days"(-731);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 19)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(Date(1, 7, 5)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"days"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"days"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(1, 7, 6, 13, 13, 9), FracSec.from!"msecs"(22));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 13, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 6, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(-731);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 19, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 7, 5, 13, 13, 9), FracSec.from!"msecs"(22)));
}
{
auto sysTime = SysTime(DateTime(0, 7, 6, 13, 13, 9), FracSec.from!"msecs"(22));
sysTime.roll!"days"(-365);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 7, 13, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(365);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 7, 6, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(-731);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 7, 19, 13, 13, 9), FracSec.from!"msecs"(22)));
sysTime.roll!"days"(730);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 7, 5, 13, 13, 9), FracSec.from!"msecs"(22)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"days"(4)));
//static assert(!__traits(compiles, ist.roll!"days"(4)));
//Verify Examples.
auto st = SysTime(DateTime(2010, 1, 1, 11, 23, 12));
st.roll!"days"(1);
assert(st == SysTime(DateTime(2010, 1, 2, 11, 23, 12)));
st.roll!"days"(365);
assert(st == SysTime(DateTime(2010, 1, 26, 11, 23, 12)));
st.roll!"days"(-32);
assert(st == SysTime(DateTime(2010, 1, 25, 11, 23, 12)));
}
}
//Shares documentation with "days" version.
/+ref SysTime+/ void roll(string units)(long value) nothrow
if(units == "hours" ||
units == "minutes" ||
units == "seconds")
{
try
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable second = splitUnitsFromHNSecs!"seconds"(hnsecs);
auto dateTime = DateTime(Date(cast(int)days), TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second));
dateTime.roll!units(value);
--days;
hnsecs += convert!("hours", "hnsecs")(dateTime.hour);
hnsecs += convert!("minutes", "hnsecs")(dateTime.minute);
hnsecs += convert!("seconds", "hnsecs")(dateTime.second);
if(days < 0)
{
hnsecs -= convert!("hours", "hnsecs")(24);
++days;
}
immutable newDaysHNSecs = convert!("days", "hnsecs")(days);
adjTime = newDaysHNSecs + hnsecs;
}
catch(Exception e)
assert(0, "Either DateTime's constructor or TimeOfDay's constructor threw.");
}
//Test roll!"hours"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, int hours, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"hours"(hours);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 2, SysTime(DateTime(1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 3, SysTime(DateTime(1999, 7, 6, 15, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 4, SysTime(DateTime(1999, 7, 6, 16, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 5, SysTime(DateTime(1999, 7, 6, 17, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 6, SysTime(DateTime(1999, 7, 6, 18, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 7, SysTime(DateTime(1999, 7, 6, 19, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 8, SysTime(DateTime(1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 9, SysTime(DateTime(1999, 7, 6, 21, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 10, SysTime(DateTime(1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 11, SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 12, SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 13, SysTime(DateTime(1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 14, SysTime(DateTime(1999, 7, 6, 2, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 15, SysTime(DateTime(1999, 7, 6, 3, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 16, SysTime(DateTime(1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 17, SysTime(DateTime(1999, 7, 6, 5, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 18, SysTime(DateTime(1999, 7, 6, 6, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 19, SysTime(DateTime(1999, 7, 6, 7, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 20, SysTime(DateTime(1999, 7, 6, 8, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 21, SysTime(DateTime(1999, 7, 6, 9, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 22, SysTime(DateTime(1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 23, SysTime(DateTime(1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 24, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 50, SysTime(DateTime(1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 10_000, SysTime(DateTime(1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -2, SysTime(DateTime(1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -3, SysTime(DateTime(1999, 7, 6, 9, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -4, SysTime(DateTime(1999, 7, 6, 8, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -5, SysTime(DateTime(1999, 7, 6, 7, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -6, SysTime(DateTime(1999, 7, 6, 6, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -7, SysTime(DateTime(1999, 7, 6, 5, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -8, SysTime(DateTime(1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -9, SysTime(DateTime(1999, 7, 6, 3, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -10, SysTime(DateTime(1999, 7, 6, 2, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -11, SysTime(DateTime(1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -12, SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -13, SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -14, SysTime(DateTime(1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -15, SysTime(DateTime(1999, 7, 6, 21, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -16, SysTime(DateTime(1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -17, SysTime(DateTime(1999, 7, 6, 19, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -18, SysTime(DateTime(1999, 7, 6, 18, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -19, SysTime(DateTime(1999, 7, 6, 17, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -20, SysTime(DateTime(1999, 7, 6, 16, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -21, SysTime(DateTime(1999, 7, 6, 15, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -22, SysTime(DateTime(1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -23, SysTime(DateTime(1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -24, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -50, SysTime(DateTime(1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -10_000, SysTime(DateTime(1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 7, 31, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(1999, 7, 31, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 8, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(1999, 8, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 12, 31, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(1999, 12, 31, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(2000, 1, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(2000, 1, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 2, 28, 23, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(1999, 2, 28, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1999, 3, 2, 0, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(1999, 3, 2, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(2000, 2, 28, 23, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(2000, 2, 28, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(2000, 3, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(2000, 3, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(-1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 2, SysTime(DateTime(-1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 3, SysTime(DateTime(-1999, 7, 6, 15, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 4, SysTime(DateTime(-1999, 7, 6, 16, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 5, SysTime(DateTime(-1999, 7, 6, 17, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 6, SysTime(DateTime(-1999, 7, 6, 18, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 7, SysTime(DateTime(-1999, 7, 6, 19, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 8, SysTime(DateTime(-1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 9, SysTime(DateTime(-1999, 7, 6, 21, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 10, SysTime(DateTime(-1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 11, SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 12, SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 13, SysTime(DateTime(-1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 14, SysTime(DateTime(-1999, 7, 6, 2, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 15, SysTime(DateTime(-1999, 7, 6, 3, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 16, SysTime(DateTime(-1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 17, SysTime(DateTime(-1999, 7, 6, 5, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 18, SysTime(DateTime(-1999, 7, 6, 6, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 19, SysTime(DateTime(-1999, 7, 6, 7, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 20, SysTime(DateTime(-1999, 7, 6, 8, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 21, SysTime(DateTime(-1999, 7, 6, 9, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 22, SysTime(DateTime(-1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 23, SysTime(DateTime(-1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 24, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(-1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 50, SysTime(DateTime(-1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), 10_000, SysTime(DateTime(-1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(-1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -2, SysTime(DateTime(-1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -3, SysTime(DateTime(-1999, 7, 6, 9, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -4, SysTime(DateTime(-1999, 7, 6, 8, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -5, SysTime(DateTime(-1999, 7, 6, 7, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -6, SysTime(DateTime(-1999, 7, 6, 6, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -7, SysTime(DateTime(-1999, 7, 6, 5, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -8, SysTime(DateTime(-1999, 7, 6, 4, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -9, SysTime(DateTime(-1999, 7, 6, 3, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -10, SysTime(DateTime(-1999, 7, 6, 2, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -11, SysTime(DateTime(-1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -12, SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -13, SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -14, SysTime(DateTime(-1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -15, SysTime(DateTime(-1999, 7, 6, 21, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -16, SysTime(DateTime(-1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -17, SysTime(DateTime(-1999, 7, 6, 19, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -18, SysTime(DateTime(-1999, 7, 6, 18, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -19, SysTime(DateTime(-1999, 7, 6, 17, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -20, SysTime(DateTime(-1999, 7, 6, 16, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -21, SysTime(DateTime(-1999, 7, 6, 15, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -22, SysTime(DateTime(-1999, 7, 6, 14, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -23, SysTime(DateTime(-1999, 7, 6, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -24, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(-1999, 7, 6, 11, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -50, SysTime(DateTime(-1999, 7, 6, 10, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(45)), -10_000, SysTime(DateTime(-1999, 7, 6, 20, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(-1999, 7, 6, 1, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(-1999, 7, 6, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), 0, SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 6, 23, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(-1999, 7, 6, 22, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 7, 31, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(-1999, 7, 31, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-1999, 8, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(-1999, 8, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2001, 12, 31, 23, 30, 33), FracSec.from!"msecs"(45)), 1, SysTime(DateTime(-2001, 12, 31, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2000, 1, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -1, SysTime(DateTime(-2000, 1, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2001, 2, 28, 23, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(-2001, 2, 28, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2001, 3, 2, 0, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(-2001, 3, 2, 23, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2000, 2, 28, 23, 30, 33), FracSec.from!"msecs"(45)), 25, SysTime(DateTime(-2000, 2, 28, 0, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(-2000, 3, 1, 0, 30, 33), FracSec.from!"msecs"(45)), -25, SysTime(DateTime(-2000, 3, 1, 23, 30, 33), FracSec.from!"msecs"(45)));
//Test Both
TestST(SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"msecs"(45)), 17_546, SysTime(DateTime(-1, 1, 1, 13, 30, 33), FracSec.from!"msecs"(45)));
TestST(SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"msecs"(45)), -17_546, SysTime(DateTime(1, 1, 1, 11, 30, 33), FracSec.from!"msecs"(45)));
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"hours"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"hours"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"hours"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"hours"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"hours"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"hours"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"hours"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 0, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"hours"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"hours"(4)));
//static assert(!__traits(compiles, ist.roll!"hours"(4)));
//Verify Examples.
auto st1 = SysTime(DateTime(2010, 7, 4, 12, 0, 0));
st1.roll!"hours"(1);
assert(st1 == SysTime(DateTime(2010, 7, 4, 13, 0, 0)));
auto st2 = SysTime(DateTime(2010, 2, 12, 12, 0, 0));
st2.roll!"hours"(-1);
assert(st2 == SysTime(DateTime(2010, 2, 12, 11, 0, 0)));
auto st3 = SysTime(DateTime(2009, 12, 31, 0, 0, 0));
st3.roll!"minutes"(1);
assert(st3 == SysTime(DateTime(2009, 12, 31, 0, 1, 0)));
auto st4 = SysTime(DateTime(2010, 1, 1, 0, 0, 0));
st4.roll!"minutes"(-1);
assert(st4 == SysTime(DateTime(2010, 1, 1, 0, 59, 0)));
auto st5 = SysTime(DateTime(2009, 12, 31, 0, 0, 0));
st5.roll!"seconds"(1);
assert(st5 == SysTime(DateTime(2009, 12, 31, 0, 0, 1)));
auto st6 = SysTime(DateTime(2010, 1, 1, 0, 0, 0));
st6.roll!"seconds"(-1);
assert(st6 == SysTime(DateTime(2010, 1, 1, 0, 0, 59)));
}
}
//Test roll!"minutes"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, int minutes, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"minutes"(minutes);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 2, SysTime(DateTime(1999, 7, 6, 12, 32, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 3, SysTime(DateTime(1999, 7, 6, 12, 33, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 4, SysTime(DateTime(1999, 7, 6, 12, 34, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 5, SysTime(DateTime(1999, 7, 6, 12, 35, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 10, SysTime(DateTime(1999, 7, 6, 12, 40, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 15, SysTime(DateTime(1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 29, SysTime(DateTime(1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 30, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 45, SysTime(DateTime(1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 60, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 75, SysTime(DateTime(1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 90, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 100, SysTime(DateTime(1999, 7, 6, 12, 10, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 689, SysTime(DateTime(1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 690, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 691, SysTime(DateTime(1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 960, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1439, SysTime(DateTime(1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1440, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1441, SysTime(DateTime(1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 2880, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -2, SysTime(DateTime(1999, 7, 6, 12, 28, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -3, SysTime(DateTime(1999, 7, 6, 12, 27, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -4, SysTime(DateTime(1999, 7, 6, 12, 26, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -5, SysTime(DateTime(1999, 7, 6, 12, 25, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -10, SysTime(DateTime(1999, 7, 6, 12, 20, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -15, SysTime(DateTime(1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -29, SysTime(DateTime(1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -30, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -45, SysTime(DateTime(1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -60, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -75, SysTime(DateTime(1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -90, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -100, SysTime(DateTime(1999, 7, 6, 12, 50, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -749, SysTime(DateTime(1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -750, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -751, SysTime(DateTime(1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -960, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1439, SysTime(DateTime(1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1440, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1441, SysTime(DateTime(1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -2880, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1999, 7, 6, 11, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1999, 7, 6, 11, 58, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1999, 7, 6, 0, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1999, 7, 6, 0, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1999, 7, 5, 23, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1999, 7, 5, 23, 58, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(1998, 12, 31, 23, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(1998, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(1998, 12, 31, 23, 58, 33), FracSec.from!"usecs"(7203)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 2, SysTime(DateTime(-1999, 7, 6, 12, 32, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 3, SysTime(DateTime(-1999, 7, 6, 12, 33, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 4, SysTime(DateTime(-1999, 7, 6, 12, 34, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 5, SysTime(DateTime(-1999, 7, 6, 12, 35, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 10, SysTime(DateTime(-1999, 7, 6, 12, 40, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 15, SysTime(DateTime(-1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 29, SysTime(DateTime(-1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 30, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 45, SysTime(DateTime(-1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 60, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 75, SysTime(DateTime(-1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 90, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 100, SysTime(DateTime(-1999, 7, 6, 12, 10, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 689, SysTime(DateTime(-1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 690, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 691, SysTime(DateTime(-1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 960, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1439, SysTime(DateTime(-1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1440, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 1441, SysTime(DateTime(-1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), 2880, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -2, SysTime(DateTime(-1999, 7, 6, 12, 28, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -3, SysTime(DateTime(-1999, 7, 6, 12, 27, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -4, SysTime(DateTime(-1999, 7, 6, 12, 26, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -5, SysTime(DateTime(-1999, 7, 6, 12, 25, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -10, SysTime(DateTime(-1999, 7, 6, 12, 20, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -15, SysTime(DateTime(-1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -29, SysTime(DateTime(-1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -30, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -45, SysTime(DateTime(-1999, 7, 6, 12, 45, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -60, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -75, SysTime(DateTime(-1999, 7, 6, 12, 15, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -90, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -100, SysTime(DateTime(-1999, 7, 6, 12, 50, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -749, SysTime(DateTime(-1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -750, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -751, SysTime(DateTime(-1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -960, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1439, SysTime(DateTime(-1999, 7, 6, 12, 31, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1440, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -1441, SysTime(DateTime(-1999, 7, 6, 12, 29, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)), -2880, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-1999, 7, 6, 12, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-1999, 7, 6, 12, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-1999, 7, 6, 11, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 11, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-1999, 7, 6, 11, 58, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-1999, 7, 6, 0, 1, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-1999, 7, 6, 0, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-1999, 7, 5, 23, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-1999, 7, 5, 23, 58, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), 1, SysTime(DateTime(-2000, 12, 31, 23, 0, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), 0, SysTime(DateTime(-2000, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 33), FracSec.from!"usecs"(7203)), -1, SysTime(DateTime(-2000, 12, 31, 23, 58, 33), FracSec.from!"usecs"(7203)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0)), -1, SysTime(DateTime(1, 1, 1, 0, 59, 0)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 0)), 1, SysTime(DateTime(0, 12, 31, 23, 0, 0)));
TestST(SysTime(DateTime(0, 1, 1, 0, 0, 0)), -1, SysTime(DateTime(0, 1, 1, 0, 59, 0)));
TestST(SysTime(DateTime(-1, 12, 31, 23, 59, 0)), 1, SysTime(DateTime(-1, 12, 31, 23, 0, 0)));
TestST(SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"usecs"(7203)), 1_052_760, SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"usecs"(7203)), -1_052_760, SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"usecs"(7203)), 1_052_782, SysTime(DateTime(-1, 1, 1, 11, 52, 33), FracSec.from!"usecs"(7203)));
TestST(SysTime(DateTime(1, 1, 1, 13, 52, 33), FracSec.from!"usecs"(7203)), -1_052_782, SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"usecs"(7203)));
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"minutes"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 59, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"minutes"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"minutes"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"minutes"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 59), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"minutes"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 0, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"minutes"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"minutes"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 0, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"minutes"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"minutes"(4)));
//static assert(!__traits(compiles, ist.roll!"minutes"(4)));
}
}
//Test roll!"seconds"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, int seconds, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"seconds"(seconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 35), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3, SysTime(DateTime(1999, 7, 6, 12, 30, 36), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 4, SysTime(DateTime(1999, 7, 6, 12, 30, 37), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 5, SysTime(DateTime(1999, 7, 6, 12, 30, 38), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 43), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 15, SysTime(DateTime(1999, 7, 6, 12, 30, 48), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26, SysTime(DateTime(1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 27, SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 30, SysTime(DateTime(1999, 7, 6, 12, 30, 3), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 59, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 60, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 61, SysTime(DateTime(1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1766, SysTime(DateTime(1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1767, SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1768, SysTime(DateTime(1999, 7, 6, 12, 30, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2007, SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3599, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3600, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3601, SysTime(DateTime(1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 7200, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 31), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -3, SysTime(DateTime(1999, 7, 6, 12, 30, 30), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -4, SysTime(DateTime(1999, 7, 6, 12, 30, 29), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -5, SysTime(DateTime(1999, 7, 6, 12, 30, 28), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 23), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -15, SysTime(DateTime(1999, 7, 6, 12, 30, 18), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33, SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -34, SysTime(DateTime(1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -35, SysTime(DateTime(1999, 7, 6, 12, 30, 58), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -59, SysTime(DateTime(1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -60, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -61, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 0, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 0, 0, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 0, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 5, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 5, 23, 59, 58), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1998, 12, 31, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1998, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1998, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1998, 12, 31, 23, 59, 58), FracSec.from!"msecs"(274)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 35), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3, SysTime(DateTime(-1999, 7, 6, 12, 30, 36), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 4, SysTime(DateTime(-1999, 7, 6, 12, 30, 37), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 5, SysTime(DateTime(-1999, 7, 6, 12, 30, 38), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 43), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 15, SysTime(DateTime(-1999, 7, 6, 12, 30, 48), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26, SysTime(DateTime(-1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 27, SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 30, SysTime(DateTime(-1999, 7, 6, 12, 30, 3), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 59, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 60, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 61, SysTime(DateTime(-1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1766, SysTime(DateTime(-1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1767, SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1768, SysTime(DateTime(-1999, 7, 6, 12, 30, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2007, SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3599, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3600, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 3601, SysTime(DateTime(-1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 7200, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 31), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -3, SysTime(DateTime(-1999, 7, 6, 12, 30, 30), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -4, SysTime(DateTime(-1999, 7, 6, 12, 30, 29), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -5, SysTime(DateTime(-1999, 7, 6, 12, 30, 28), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 23), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -15, SysTime(DateTime(-1999, 7, 6, 12, 30, 18), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33, SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -34, SysTime(DateTime(-1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -35, SysTime(DateTime(-1999, 7, 6, 12, 30, 58), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -59, SysTime(DateTime(-1999, 7, 6, 12, 30, 34), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -60, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -61, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 0, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 0, 0, 1), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 0, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 0, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 5, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 5, 23, 59, 59), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 5, 23, 59, 58), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-2000, 12, 31, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-2000, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-2000, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-2000, 12, 31, 23, 59, 58), FracSec.from!"msecs"(274)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1, 1, 1, 0, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(0, 12, 31, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(0, 1, 1, 0, 0, 59), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1, 12, 31, 23, 59, 59), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1, 12, 31, 23, 59, 0), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"msecs"(274)), 63_165_600L, SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"msecs"(274)), -63_165_600L, SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1, 1, 1, 11, 30, 33), FracSec.from!"msecs"(274)), 63_165_617L, SysTime(DateTime(-1, 1, 1, 11, 30, 50), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1, 1, 1, 13, 30, 50), FracSec.from!"msecs"(274)), -63_165_617L, SysTime(DateTime(1, 1, 1, 13, 30, 33), FracSec.from!"msecs"(274)));
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0));
sysTime.roll!"seconds"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 59), FracSec.from!"hnsecs"(0)));
sysTime.roll!"seconds"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"seconds"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 59), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"seconds"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0));
sysTime.roll!"seconds"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 0), FracSec.from!"hnsecs"(0)));
sysTime.roll!"seconds"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
}
{
auto sysTime = SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999));
sysTime.roll!"seconds"(1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 0), FracSec.from!"hnsecs"(9_999_999)));
sysTime.roll!"seconds"(-1);
_assertPred!"=="(sysTime, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"seconds"(4)));
//static assert(!__traits(compiles, ist.roll!"seconds"(4)));
}
}
//Shares documentation with "days" version.
/+ref SysTime+/ void roll(string units)(long value) nothrow
if(units == "msecs" ||
units == "usecs" ||
units == "hnsecs")
{
auto hnsecs = adjTime;
immutable days = splitUnitsFromHNSecs!"days"(hnsecs);
immutable negative = hnsecs < 0;
if(negative)
hnsecs += convert!("hours", "hnsecs")(24);
immutable seconds = splitUnitsFromHNSecs!"seconds"(hnsecs);
hnsecs += convert!(units, "hnsecs")(value);
hnsecs %= convert!("seconds", "hnsecs")(1);
if(hnsecs < 0)
hnsecs += convert!("seconds", "hnsecs")(1);
hnsecs += convert!("seconds", "hnsecs")(seconds);
if(negative)
hnsecs -= convert!("hours", "hnsecs")(24);
immutable newDaysHNSecs = convert!("days", "hnsecs")(days);
adjTime = newDaysHNSecs + hnsecs;
}
//Test roll!"msecs"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, int milliseconds, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"msecs"(milliseconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(276)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(284)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(374)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_727, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(1)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1_766_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1_766_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(272)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(264)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(174)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1_833_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1_833_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(276)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(284)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(374)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 26_727, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(1)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1_766_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), 1_766_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(272)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(264)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(174)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -33_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1_833_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(274)), -1_833_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(999)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(1)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), 0, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), -1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(999)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), -2, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(998)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), -1000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), -2000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(0)), -2555, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"msecs"(445)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_989_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(19_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2555, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(5_549_999)));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.addMSecs(4)));
//static assert(!__traits(compiles, ist.addMSecs(4)));
}
}
//Test roll!"usecs"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, long microseconds, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"usecs"(microseconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(276)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(284)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(374)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(2274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(26_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(27_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_727, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(27_001)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_766_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(766_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_766_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(767_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(272)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(264)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(174)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(998_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -33_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(967_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -33_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(966_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_833_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(167_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_833_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(166_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(276)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(284)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(374)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(1275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(2274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(26_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(27_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 26_727, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(27_001)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_766_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(766_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_766_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(767_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), 3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(272)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(264)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(174)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(999_273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(998_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -33_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(967_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -33_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(966_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_833_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(167_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_833_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(166_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)), -3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(274)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(1)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), 0, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(999_999)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -2, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(999_998)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -1000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(999_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -2000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(998_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -2555, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(997_445)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -1_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -2_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(0)), -2_333_333, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"usecs"(666_667)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_989)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(19)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(19_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2555, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(25_549)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_333_333, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(3_333_329)));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"usecs"(4)));
//static assert(!__traits(compiles, ist.roll!"usecs"(4)));
}
}
//Test roll!"hnsecs"().
unittest
{
version(testStdDateTime)
{
static void TestST(SysTime orig, long hnsecs, in SysTime expected, size_t line = __LINE__)
{
orig.roll!"hnsecs"(hnsecs);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_998_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2555, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_997_445)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(8_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_333_333, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(7_666_667)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -10_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_888_888, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_111_112)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2555, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(2554)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_333_333, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(2_333_332)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 10_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_888_888, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(888_887)));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.roll!"hnsecs"(4)));
//static assert(!__traits(compiles, ist.roll!"hnsecs"(4)));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D SysTime).
The legal types of arithmetic for $(D SysTime) using this operator are
$(BOOKTABLE,
$(TR $(TD SysTime) $(TD +) $(TD duration) $(TD -->) $(TD SysTime))
$(TR $(TD SysTime) $(TD -) $(TD duration) $(TD -->) $(TD SysTime))
)
Params:
duration = The duration to add to or subtract from this
$(D SysTime).
+/
SysTime opBinary(string op, D)(in D duration) const pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
SysTime retval = SysTime(this._stdTime, this._timezone);
static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
immutable hnsecs = duration.hnsecs;
//Ideally, this would just be
//retval._stdTime += unaryFun!(op ~ "a")(hnsecs);
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
retval._stdTime += signedHNSecs;
return retval;
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678));
_assertPred!"=="(st + dur!"weeks"(7), SysTime(DateTime(1999, 8, 24, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"weeks"(-7), SysTime(DateTime(1999, 5, 18, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"days"(7), SysTime(DateTime(1999, 7, 13, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"days"(-7), SysTime(DateTime(1999, 6, 29, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"hours"(7), SysTime(DateTime(1999, 7, 6, 19, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"hours"(-7), SysTime(DateTime(1999, 7, 6, 5, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"minutes"(7), SysTime(DateTime(1999, 7, 6, 12, 37, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"minutes"(-7), SysTime(DateTime(1999, 7, 6, 12, 23, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"seconds"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 40), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"seconds"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 26), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st + dur!"msecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_415_678)));
_assertPred!"=="(st + dur!"msecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_275_678)));
_assertPred!"=="(st + dur!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_748)));
_assertPred!"=="(st + dur!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_608)));
_assertPred!"=="(st + dur!"hnsecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_685)));
_assertPred!"=="(st + dur!"hnsecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_671)));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(st + TickDuration.from!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_748)));
_assertPred!"=="(st + TickDuration.from!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_608)));
}
_assertPred!"=="(st - dur!"weeks"(-7), SysTime(DateTime(1999, 8, 24, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"weeks"(7), SysTime(DateTime(1999, 5, 18, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"days"(-7), SysTime(DateTime(1999, 7, 13, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"days"(7), SysTime(DateTime(1999, 6, 29, 12, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"hours"(-7), SysTime(DateTime(1999, 7, 6, 19, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"hours"(7), SysTime(DateTime(1999, 7, 6, 5, 30, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"minutes"(-7), SysTime(DateTime(1999, 7, 6, 12, 37, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"minutes"(7), SysTime(DateTime(1999, 7, 6, 12, 23, 33), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"seconds"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 40), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"seconds"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 26), FracSec.from!"hnsecs"(2_345_678)));
_assertPred!"=="(st - dur!"msecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_415_678)));
_assertPred!"=="(st - dur!"msecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_275_678)));
_assertPred!"=="(st - dur!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_748)));
_assertPred!"=="(st - dur!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_608)));
_assertPred!"=="(st - dur!"hnsecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_685)));
_assertPred!"=="(st - dur!"hnsecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_671)));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(st - TickDuration.from!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_748)));
_assertPred!"=="(st - TickDuration.from!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2_345_608)));
}
static void TestST(in SysTime orig, long hnsecs, in SysTime expected, size_t line = __LINE__)
{
_assertPred!"=="(orig + dur!"hnsecs"(hnsecs), expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 39), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 36, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 31, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(1999, 7, 6, 13, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 27), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 24, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 29, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(1999, 7, 6, 11, 30, 33), FracSec.from!"hnsecs"(274)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 39), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 36, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 31, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 13, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 27), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 24, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 29, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 11, 30, 33), FracSec.from!"hnsecs"(274)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_998_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2555, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_997_445)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(8_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_333_333, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(7_666_667)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -10_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 58), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_888_888, SysTime(DateTime(0, 12, 31, 23, 59, 57), FracSec.from!"hnsecs"(9_111_112)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2555, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(2554)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_333_333, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(2_333_332)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 10_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 1), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_888_888, SysTime(DateTime(1, 1, 1, 0, 0, 2), FracSec.from!"hnsecs"(888_887)));
auto duration = dur!"seconds"(12);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst + duration));
//static assert(__traits(compiles, ist + duration));
static assert(__traits(compiles, cst - duration));
//static assert(__traits(compiles, ist - duration));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D SysTime), as well as assigning the result to this $(D SysTime).
The legal types of arithmetic for $(D SysTime) using this operator are
$(BOOKTABLE,
$(TR $(TD SysTime) $(TD +) $(TD duration) $(TD -->) $(TD SysTime))
$(TR $(TD SysTime) $(TD -) $(TD duration) $(TD -->) $(TD SysTime))
)
Params:
duration = The duration to add to or subtract from this
$(D SysTime).
+/
/+ref+/ SysTime opOpAssign(string op, D)(in D duration) pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
static if(is(Unqual!D == Duration))
auto hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
auto hnsecs = duration.hnsecs;
//Ideally, this would just be
//_stdTime += unaryFun!(op ~ "a")(hnsecs);
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
_stdTime += signedHNSecs;
return this;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"weeks"(7), SysTime(DateTime(1999, 8, 24, 12, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"weeks"(-7), SysTime(DateTime(1999, 5, 18, 12, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"days"(7), SysTime(DateTime(1999, 7, 13, 12, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"days"(-7), SysTime(DateTime(1999, 6, 29, 12, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hours"(7), SysTime(DateTime(1999, 7, 6, 19, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hours"(-7), SysTime(DateTime(1999, 7, 6, 5, 30, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"minutes"(7), SysTime(DateTime(1999, 7, 6, 12, 37, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"minutes"(-7), SysTime(DateTime(1999, 7, 6, 12, 23, 33)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"seconds"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 40)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"seconds"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 26)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"msecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(7)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"msecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(993)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"usecs"(999_993)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hnsecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(7)));
_assertPred!"+="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hnsecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_993)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"weeks"(-7), SysTime(DateTime(1999, 8, 24, 12, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"weeks"(7), SysTime(DateTime(1999, 5, 18, 12, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"days"(-7), SysTime(DateTime(1999, 7, 13, 12, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"days"(7), SysTime(DateTime(1999, 6, 29, 12, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hours"(-7), SysTime(DateTime(1999, 7, 6, 19, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hours"(7), SysTime(DateTime(1999, 7, 6, 5, 30, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"minutes"(-7), SysTime(DateTime(1999, 7, 6, 12, 37, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"minutes"(7), SysTime(DateTime(1999, 7, 6, 12, 23, 33)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"seconds"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 40)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"seconds"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 26)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"msecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(7)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"msecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"msecs"(993)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"usecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(7)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"usecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"usecs"(999_993)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hnsecs"(-7), SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(7)));
_assertPred!"-="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)), dur!"hnsecs"(7), SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_993)));
static void TestST(SysTime orig, long hnsecs, in SysTime expected, size_t line = __LINE__)
{
orig += dur!"hnsecs"(hnsecs);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 39), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 36, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 31, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(1999, 7, 6, 13, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(1999, 7, 6, 12, 30, 27), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 24, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(1999, 7, 6, 12, 29, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(1999, 7, 6, 11, 30, 33), FracSec.from!"hnsecs"(274)));
//Test B.C.
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 0, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(276)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(284)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(374)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1275)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(2274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(26_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 26_727, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(27_001)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_725, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_766_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_766_726, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_767_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 39), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 36, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 31, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), 36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 13, 30, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(272)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -10, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(264)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -100, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(174)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -274, SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1001, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_999_273)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -2000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_998_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_967_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -33_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_966_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_274, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_167_000)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_833_275, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(8_166_999)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -1_000_000, SysTime(DateTime(-1999, 7, 6, 12, 30, 32), FracSec.from!"hnsecs"(9_000_274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -60_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 30, 27), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -3_600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 24, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -600_000_000L, SysTime(DateTime(-1999, 7, 6, 12, 29, 33), FracSec.from!"hnsecs"(274)));
TestST(SysTime(DateTime(-1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(274)), -36_000_000_000L, SysTime(DateTime(-1999, 7, 6, 11, 30, 33), FracSec.from!"hnsecs"(274)));
//Test Both
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_998_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2555, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_997_445)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -1_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(8_000_000)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -2_333_333, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(7_666_667)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -10_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_000_000, SysTime(DateTime(0, 12, 31, 23, 59, 58), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), -20_888_888, SysTime(DateTime(0, 12, 31, 23, 59, 57), FracSec.from!"hnsecs"(9_111_112)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), -1, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2555, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(2554)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 2_333_333, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(2_333_332)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 10_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_000_000, SysTime(DateTime(1, 1, 1, 0, 0, 1), FracSec.from!"hnsecs"(9_999_999)));
TestST(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 20_888_888, SysTime(DateTime(1, 1, 1, 0, 0, 2), FracSec.from!"hnsecs"(888_887)));
auto duration = dur!"seconds"(12);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst += duration));
//static assert(!__traits(compiles, ist += duration));
static assert(!__traits(compiles, cst -= duration));
//static assert(!__traits(compiles, ist -= duration));
}
}
/++
Gives the difference between two $(D SysTime)s.
The legal types of arithmetic for $(D SysTime) using this operator are
$(BOOKTABLE,
$(TR $(TD SysTime) $(TD -) $(TD SysTime) $(TD -->) $(TD duration))
)
+/
Duration opBinary(string op)(in SysTime rhs) const pure nothrow
if(op == "-")
{
return dur!"hnsecs"(_stdTime - rhs._stdTime);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1998, 7, 6, 12, 30, 33)),
dur!"seconds"(31_536_000));
_assertPred!"=="(SysTime(DateTime(1998, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(-31_536_000));
_assertPred!"=="(SysTime(DateTime(1999, 8, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(26_78_400));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 8, 6, 12, 30, 33)),
dur!"seconds"(-26_78_400));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 5, 12, 30, 33)),
dur!"seconds"(86_400));
_assertPred!"=="(SysTime(DateTime(1999, 7, 5, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(-86_400));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 11, 30, 33)),
dur!"seconds"(3600));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 11, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(-3600));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 31, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(60));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 31, 33)),
dur!"seconds"(-60));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 34)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"seconds"(1));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 34)),
dur!"seconds"(-1));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(532)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"msecs"(532));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"msecs"(532)),
dur!"msecs"(-532));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(333_347)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"usecs"(333_347));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"usecs"(333_347)),
dur!"usecs"(-333_347));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_234_567)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33)),
dur!"hnsecs"(1_234_567));
_assertPred!"=="(SysTime(DateTime(1999, 7, 6, 12, 30, 33)) - SysTime(DateTime(1999, 7, 6, 12, 30, 33), FracSec.from!"hnsecs"(1_234_567)),
dur!"hnsecs"(-1_234_567));
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 12, 30, 33)) - SysTime(DateTime(1, 1, 1, 0, 0, 0)), dur!"seconds"(45033));
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0)) - SysTime(DateTime(1, 1, 1, 12, 30, 33)), dur!"seconds"(-45033));
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 12, 30, 33)) - SysTime(DateTime(1, 1, 1, 0, 0, 0)), dur!"seconds"(-41367));
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0)) - SysTime(DateTime(0, 12, 31, 12, 30, 33)), dur!"seconds"(41367));
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0)) - SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)),
dur!"hnsecs"(1));
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)) - SysTime(DateTime(1, 1, 1, 0, 0, 0)),
dur!"hnsecs"(-1));
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
_assertPred!"=="(SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), tz) -
SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), tz),
dur!"hnsecs"(0));
_assertPred!"=="(SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), tz) -
SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), UTC()),
dur!"hours"(8));
_assertPred!"=="(SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), UTC()) -
SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), tz),
dur!"hours"(-8));
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st - st));
static assert(__traits(compiles, cst - st));
//static assert(__traits(compiles, ist - st));
static assert(__traits(compiles, st - cst));
static assert(__traits(compiles, cst - cst));
//static assert(__traits(compiles, ist - cst));
//static assert(__traits(compiles, st - ist));
//static assert(__traits(compiles, cst - ist));
//static assert(__traits(compiles, ist - ist));
}
}
/++
Returns the difference between the two $(D SysTime)s in months.
To get the difference in years, subtract the year property
of two $(D SysTime)s. To get the difference in days or weeks,
subtract the $(D SysTime)s themselves and use the $(D Duration)
that results. Because converting between months and smaller
units requires a specific date (which $(D Duration)s don't have),
getting the difference in months requires some math using both
the year and month properties, so this is a convenience function for
getting the difference in months.
Note that the number of days in the months or how far into the month
either date is is irrelevant. It is the difference in the month property
combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Params:
rhs = The $(D SysTime) to subtract from this one.
Examples:
--------------------
assert(SysTime(Date(1999, 2, 1)).diffMonths(SysTime(Date(1999, 1, 31))) == 1);
assert(SysTime(Date(1999, 1, 31)).diffMonths(SysTime(Date(1999, 2, 1))) == -1);
assert(SysTime(Date(1999, 3, 1)).diffMonths(SysTime(Date(1999, 1, 1))) == 2);
assert(SysTime(Date(1999, 1, 1)).diffMonths(SysTime(Date(1999, 3, 31))) == -2);
--------------------
+/
int diffMonths(in SysTime rhs) const nothrow
{
return (cast(Date)this).diffMonths(cast(Date)rhs);
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.diffMonths(st)));
static assert(__traits(compiles, cst.diffMonths(st)));
//static assert(__traits(compiles, ist.diffMonths(st)));
static assert(__traits(compiles, st.diffMonths(cst)));
static assert(__traits(compiles, cst.diffMonths(cst)));
//static assert(__traits(compiles, ist.diffMonths(cst)));
//static assert(__traits(compiles, st.diffMonths(ist)));
//static assert(__traits(compiles, cst.diffMonths(ist)));
//static assert(__traits(compiles, ist.diffMonths(ist)));
//Verify Examples.
assert(SysTime(Date(1999, 2, 1)).diffMonths(SysTime(Date(1999, 1, 31))) == 1);
assert(SysTime(Date(1999, 1, 31)).diffMonths(SysTime(Date(1999, 2, 1))) == -1);
assert(SysTime(Date(1999, 3, 1)).diffMonths(SysTime(Date(1999, 1, 1))) == 2);
assert(SysTime(Date(1999, 1, 1)).diffMonths(SysTime(Date(1999, 3, 31))) == -2);
}
}
/++
Whether this $(D SysTime) is in a leap year.
+/
@property bool isLeapYear() const nothrow
{
return (cast(Date)this).isLeapYear;
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.isLeapYear));
static assert(__traits(compiles, cst.isLeapYear));
//static assert(__traits(compiles, ist.isLeapYear));
}
}
/++
Day of the week this $(D SysTime) is on.
+/
@property DayOfWeek dayOfWeek() const nothrow
{
return getDayOfWeek(dayOfGregorianCal);
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.dayOfWeek));
static assert(__traits(compiles, cst.dayOfWeek));
//static assert(__traits(compiles, ist.dayOfWeek));
}
}
/++
Day of the year this $(D SysTime) is on.
Examples:
--------------------
assert(SysTime(DateTime(1999, 1, 1, 12, 22, 7)).dayOfYear == 1);
assert(SysTime(DateTime(1999, 12, 31, 7, 2, 59)).dayOfYear == 365);
assert(SysTime(DateTime(2000, 12, 31, 21, 20, 0)).dayOfYear == 366);
--------------------
+/
@property ushort dayOfYear() const nothrow
{
return (cast(Date)this).dayOfYear;
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.dayOfYear));
static assert(__traits(compiles, cst.dayOfYear));
//static assert(__traits(compiles, ist.dayOfYear));
//Verify Examples.
assert(SysTime(DateTime(1999, 1, 1, 12, 22, 7)).dayOfYear == 1);
assert(SysTime(DateTime(1999, 12, 31, 7, 2, 59)).dayOfYear == 365);
assert(SysTime(DateTime(2000, 12, 31, 21, 20, 0)).dayOfYear == 366);
}
}
/++
Day of the year.
Params:
day = The day of the year to set which day of the year this
$(D SysTime) is on.
+/
@property void dayOfYear(int day)
{
immutable hnsecs = adjTime;
immutable days = convert!("hnsecs", "days")(hnsecs);
immutable theRest = hnsecs - convert!("days", "hnsecs")(days);
auto date = Date(cast(int)days);
date.dayOfYear = day;
immutable newDaysHNSecs = convert!("days", "hnsecs")(date.dayOfGregorianCal - 1);
adjTime = newDaysHNSecs + theRest;
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.dayOfYear = 12));
static assert(!__traits(compiles, cst.dayOfYear = 12));
//static assert(!__traits(compiles, ist.dayOfYear = 12));
}
}
/++
The Xth day of the Gregorian Calendar that this $(D SysTime) is on.
Examples:
--------------------
assert(SysTime(DateTime(1, 1, 1, 0, 0, 0)).dayOfGregorianCal == 1);
assert(SysTime(DateTime(1, 12, 31, 23, 59, 59)).dayOfGregorianCal == 365);
assert(SysTime(DateTime(2, 1, 1, 2, 2, 2)).dayOfGregorianCal == 366);
assert(SysTime(DateTime(0, 12, 31, 7, 7, 7)).dayOfGregorianCal == 0);
assert(SysTime(DateTime(0, 1, 1, 19, 30, 0)).dayOfGregorianCal == -365);
assert(SysTime(DateTime(-1, 12, 31, 4, 7, 0)).dayOfGregorianCal == -366);
assert(SysTime(DateTime(2000, 1, 1, 9, 30, 20)).dayOfGregorianCal == 730_120);
assert(SysTime(DateTime(2010, 12, 31, 15, 45, 50)).dayOfGregorianCal == 734_137);
--------------------
+/
@property int dayOfGregorianCal() const nothrow
{
immutable adjustedTime = adjTime;
//We have to add one because 0 would be midnight, January 1st, 1 A.D.,
//which would be the 1st day of the Gregorian Calendar, not the 0th. So,
//simply casting to days is one day off.
if(adjustedTime > 0)
return cast(int)getUnitsFromHNSecs!"days"(adjustedTime) + 1;
long hnsecs = adjustedTime;
immutable days = cast(int)splitUnitsFromHNSecs!"days"(hnsecs);
return hnsecs == 0 ? days + 1 : days;
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal, 1);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)).dayOfGregorianCal, 1);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal, 1);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 1);
_assertPred!"=="(SysTime(DateTime(1, 1, 2, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 2);
_assertPred!"=="(SysTime(DateTime(1, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 32);
_assertPred!"=="(SysTime(DateTime(2, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 366);
_assertPred!"=="(SysTime(DateTime(3, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 731);
_assertPred!"=="(SysTime(DateTime(4, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 1096);
_assertPred!"=="(SysTime(DateTime(5, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 1462);
_assertPred!"=="(SysTime(DateTime(50, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 17_898);
_assertPred!"=="(SysTime(DateTime(97, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 35_065);
_assertPred!"=="(SysTime(DateTime(100, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 36_160);
_assertPred!"=="(SysTime(DateTime(101, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 36_525);
_assertPred!"=="(SysTime(DateTime(105, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 37_986);
_assertPred!"=="(SysTime(DateTime(200, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 72_684);
_assertPred!"=="(SysTime(DateTime(201, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 73_049);
_assertPred!"=="(SysTime(DateTime(300, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 109_208);
_assertPred!"=="(SysTime(DateTime(301, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 109_573);
_assertPred!"=="(SysTime(DateTime(400, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 145_732);
_assertPred!"=="(SysTime(DateTime(401, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 146_098);
_assertPred!"=="(SysTime(DateTime(500, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 182_257);
_assertPred!"=="(SysTime(DateTime(501, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 182_622);
_assertPred!"=="(SysTime(DateTime(1000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 364_878);
_assertPred!"=="(SysTime(DateTime(1001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 365_243);
_assertPred!"=="(SysTime(DateTime(1600, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 584_023);
_assertPred!"=="(SysTime(DateTime(1601, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 584_389);
_assertPred!"=="(SysTime(DateTime(1900, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 693_596);
_assertPred!"=="(SysTime(DateTime(1901, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 693_961);
_assertPred!"=="(SysTime(DateTime(1945, 11, 12, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 710_347);
_assertPred!"=="(SysTime(DateTime(1999, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 729_755);
_assertPred!"=="(SysTime(DateTime(2000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 730_120);
_assertPred!"=="(SysTime(DateTime(2001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 730_486);
_assertPred!"=="(SysTime(DateTime(2010, 1, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_773);
_assertPred!"=="(SysTime(DateTime(2010, 1, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_803);
_assertPred!"=="(SysTime(DateTime(2010, 2, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_804);
_assertPred!"=="(SysTime(DateTime(2010, 2, 28, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_831);
_assertPred!"=="(SysTime(DateTime(2010, 3, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_832);
_assertPred!"=="(SysTime(DateTime(2010, 3, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_862);
_assertPred!"=="(SysTime(DateTime(2010, 4, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_863);
_assertPred!"=="(SysTime(DateTime(2010, 4, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_892);
_assertPred!"=="(SysTime(DateTime(2010, 5, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_893);
_assertPred!"=="(SysTime(DateTime(2010, 5, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_923);
_assertPred!"=="(SysTime(DateTime(2010, 6, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_924);
_assertPred!"=="(SysTime(DateTime(2010, 6, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_953);
_assertPred!"=="(SysTime(DateTime(2010, 7, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_954);
_assertPred!"=="(SysTime(DateTime(2010, 7, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_984);
_assertPred!"=="(SysTime(DateTime(2010, 8, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 733_985);
_assertPred!"=="(SysTime(DateTime(2010, 8, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_015);
_assertPred!"=="(SysTime(DateTime(2010, 9, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_016);
_assertPred!"=="(SysTime(DateTime(2010, 9, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_045);
_assertPred!"=="(SysTime(DateTime(2010, 10, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_046);
_assertPred!"=="(SysTime(DateTime(2010, 10, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_076);
_assertPred!"=="(SysTime(DateTime(2010, 11, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_077);
_assertPred!"=="(SysTime(DateTime(2010, 11, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_106);
_assertPred!"=="(SysTime(DateTime(2010, 12, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_107);
_assertPred!"=="(SysTime(DateTime(2010, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, 734_137);
_assertPred!"=="(SysTime(DateTime(2012, 2, 1, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, 734_534);
_assertPred!"=="(SysTime(DateTime(2012, 2, 28, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, 734_561);
_assertPred!"=="(SysTime(DateTime(2012, 2, 29, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, 734_562);
_assertPred!"=="(SysTime(DateTime(2012, 3, 1, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, 734_563);
//Test B.C.
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(1)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(-1, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal, -366);
_assertPred!"=="(SysTime(DateTime(-1, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_998)).dayOfGregorianCal, -366);
_assertPred!"=="(SysTime(DateTime(-1, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal, -366);
_assertPred!"=="(SysTime(DateTime(-1, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal, -366);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 30, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1);
_assertPred!"=="(SysTime(DateTime(0, 12, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -30);
_assertPred!"=="(SysTime(DateTime(0, 11, 30, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -31);
_assertPred!"=="(SysTime(DateTime(-1, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -366);
_assertPred!"=="(SysTime(DateTime(-1, 12, 30, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -367);
_assertPred!"=="(SysTime(DateTime(-1, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -730);
_assertPred!"=="(SysTime(DateTime(-2, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -731);
_assertPred!"=="(SysTime(DateTime(-2, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1095);
_assertPred!"=="(SysTime(DateTime(-3, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1096);
_assertPred!"=="(SysTime(DateTime(-3, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1460);
_assertPred!"=="(SysTime(DateTime(-4, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1461);
_assertPred!"=="(SysTime(DateTime(-4, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1826);
_assertPred!"=="(SysTime(DateTime(-5, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -1827);
_assertPred!"=="(SysTime(DateTime(-5, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -2191);
_assertPred!"=="(SysTime(DateTime(-9, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -3652);
_assertPred!"=="(SysTime(DateTime(-49, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -18_262);
_assertPred!"=="(SysTime(DateTime(-50, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -18_627);
_assertPred!"=="(SysTime(DateTime(-97, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -35_794);
_assertPred!"=="(SysTime(DateTime(-99, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -36_160);
_assertPred!"=="(SysTime(DateTime(-99, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -36_524);
_assertPred!"=="(SysTime(DateTime(-100, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -36_889);
_assertPred!"=="(SysTime(DateTime(-101, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -37_254);
_assertPred!"=="(SysTime(DateTime(-105, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -38_715);
_assertPred!"=="(SysTime(DateTime(-200, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -73_413);
_assertPred!"=="(SysTime(DateTime(-201, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -73_778);
_assertPred!"=="(SysTime(DateTime(-300, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -109_937);
_assertPred!"=="(SysTime(DateTime(-301, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -110_302);
_assertPred!"=="(SysTime(DateTime(-400, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -146_097);
_assertPred!"=="(SysTime(DateTime(-400, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -146_462);
_assertPred!"=="(SysTime(DateTime(-401, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -146_827);
_assertPred!"=="(SysTime(DateTime(-499, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -182_621);
_assertPred!"=="(SysTime(DateTime(-500, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -182_986);
_assertPred!"=="(SysTime(DateTime(-501, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -183_351);
_assertPred!"=="(SysTime(DateTime(-1000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -365_607);
_assertPred!"=="(SysTime(DateTime(-1001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -365_972);
_assertPred!"=="(SysTime(DateTime(-1599, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -584_387);
_assertPred!"=="(SysTime(DateTime(-1600, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -584_388);
_assertPred!"=="(SysTime(DateTime(-1600, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -584_753);
_assertPred!"=="(SysTime(DateTime(-1601, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -585_118);
_assertPred!"=="(SysTime(DateTime(-1900, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -694_325);
_assertPred!"=="(SysTime(DateTime(-1901, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -694_690);
_assertPred!"=="(SysTime(DateTime(-1999, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -730_484);
_assertPred!"=="(SysTime(DateTime(-2000, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -730_485);
_assertPred!"=="(SysTime(DateTime(-2000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -730_850);
_assertPred!"=="(SysTime(DateTime(-2001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)).dayOfGregorianCal, -731_215);
_assertPred!"=="(SysTime(DateTime(-2010, 1, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_502);
_assertPred!"=="(SysTime(DateTime(-2010, 1, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_472);
_assertPred!"=="(SysTime(DateTime(-2010, 2, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_471);
_assertPred!"=="(SysTime(DateTime(-2010, 2, 28, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_444);
_assertPred!"=="(SysTime(DateTime(-2010, 3, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_443);
_assertPred!"=="(SysTime(DateTime(-2010, 3, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_413);
_assertPred!"=="(SysTime(DateTime(-2010, 4, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_412);
_assertPred!"=="(SysTime(DateTime(-2010, 4, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_383);
_assertPred!"=="(SysTime(DateTime(-2010, 5, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_382);
_assertPred!"=="(SysTime(DateTime(-2010, 5, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_352);
_assertPred!"=="(SysTime(DateTime(-2010, 6, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_351);
_assertPred!"=="(SysTime(DateTime(-2010, 6, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_322);
_assertPred!"=="(SysTime(DateTime(-2010, 7, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_321);
_assertPred!"=="(SysTime(DateTime(-2010, 7, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_291);
_assertPred!"=="(SysTime(DateTime(-2010, 8, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_290);
_assertPred!"=="(SysTime(DateTime(-2010, 8, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_260);
_assertPred!"=="(SysTime(DateTime(-2010, 9, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_259);
_assertPred!"=="(SysTime(DateTime(-2010, 9, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_230);
_assertPred!"=="(SysTime(DateTime(-2010, 10, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_229);
_assertPred!"=="(SysTime(DateTime(-2010, 10, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_199);
_assertPred!"=="(SysTime(DateTime(-2010, 11, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_198);
_assertPred!"=="(SysTime(DateTime(-2010, 11, 30, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_169);
_assertPred!"=="(SysTime(DateTime(-2010, 12, 1, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_168);
_assertPred!"=="(SysTime(DateTime(-2010, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999)).dayOfGregorianCal, -734_138);
_assertPred!"=="(SysTime(DateTime(-2012, 2, 1, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, -735_202);
_assertPred!"=="(SysTime(DateTime(-2012, 2, 28, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, -735_175);
_assertPred!"=="(SysTime(DateTime(-2012, 2, 29, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, -735_174);
_assertPred!"=="(SysTime(DateTime(-2012, 3, 1, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, -735_173);
_assertPred!"=="(SysTime(DateTime(-3760, 9, 7, 0, 0, 0), FracSec.from!"msecs"(0)).dayOfGregorianCal, -1_373_427); //Start of Hebrew Calendar
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.dayOfGregorianCal));
//static assert(__traits(compiles, ist.dayOfGregorianCal));
//Verify Examples.
assert(SysTime(DateTime(1, 1, 1, 0, 0, 0)).dayOfGregorianCal == 1);
assert(SysTime(DateTime(1, 12, 31, 23, 59, 59)).dayOfGregorianCal == 365);
assert(SysTime(DateTime(2, 1, 1, 2, 2, 2)).dayOfGregorianCal == 366);
assert(SysTime(DateTime(0, 12, 31, 7, 7, 7)).dayOfGregorianCal == 0);
assert(SysTime(DateTime(0, 1, 1, 19, 30, 0)).dayOfGregorianCal == -365);
assert(SysTime(DateTime(-1, 12, 31, 4, 7, 0)).dayOfGregorianCal == -366);
assert(SysTime(DateTime(2000, 1, 1, 9, 30, 20)).dayOfGregorianCal == 730_120);
assert(SysTime(DateTime(2010, 12, 31, 15, 45, 50)).dayOfGregorianCal == 734_137);
}
}
//Test that the logic for the day of the Gregorian Calendar is consistent
//between Date and SysTime.
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(1, 1, 1).dayOfGregorianCal, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(1, 1, 2).dayOfGregorianCal, SysTime(DateTime(1, 1, 2, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(1, 2, 1).dayOfGregorianCal, SysTime(DateTime(1, 2, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2, 1, 1).dayOfGregorianCal, SysTime(DateTime(2, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(3, 1, 1).dayOfGregorianCal, SysTime(DateTime(3, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(4, 1, 1).dayOfGregorianCal, SysTime(DateTime(4, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(5, 1, 1).dayOfGregorianCal, SysTime(DateTime(5, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(50, 1, 1).dayOfGregorianCal, SysTime(DateTime(50, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(97, 1, 1).dayOfGregorianCal, SysTime(DateTime(97, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(100, 1, 1).dayOfGregorianCal, SysTime(DateTime(100, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(101, 1, 1).dayOfGregorianCal, SysTime(DateTime(101, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(105, 1, 1).dayOfGregorianCal, SysTime(DateTime(105, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(200, 1, 1).dayOfGregorianCal, SysTime(DateTime(200, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(201, 1, 1).dayOfGregorianCal, SysTime(DateTime(201, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(300, 1, 1).dayOfGregorianCal, SysTime(DateTime(300, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(301, 1, 1).dayOfGregorianCal, SysTime(DateTime(301, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(400, 1, 1).dayOfGregorianCal, SysTime(DateTime(400, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(401, 1, 1).dayOfGregorianCal, SysTime(DateTime(401, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(500, 1, 1).dayOfGregorianCal, SysTime(DateTime(500, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(501, 1, 1).dayOfGregorianCal, SysTime(DateTime(501, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(1000, 1, 1).dayOfGregorianCal, SysTime(DateTime(1000, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(1001, 1, 1).dayOfGregorianCal, SysTime(DateTime(1001, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(1600, 1, 1).dayOfGregorianCal, SysTime(DateTime(1600, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(1601, 1, 1).dayOfGregorianCal, SysTime(DateTime(1601, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(1900, 1, 1).dayOfGregorianCal, SysTime(DateTime(1900, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(1901, 1, 1).dayOfGregorianCal, SysTime(DateTime(1901, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(1945, 11, 12).dayOfGregorianCal, SysTime(DateTime(1945, 11, 12, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(1999, 1, 1).dayOfGregorianCal, SysTime(DateTime(1999, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(1999, 7, 6).dayOfGregorianCal, SysTime(DateTime(1999, 7, 6, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2000, 1, 1).dayOfGregorianCal, SysTime(DateTime(2000, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2001, 1, 1).dayOfGregorianCal, SysTime(DateTime(2001, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 1, 1).dayOfGregorianCal, SysTime(DateTime(2010, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 1, 31).dayOfGregorianCal, SysTime(DateTime(2010, 1, 31, 23, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 2, 1).dayOfGregorianCal, SysTime(DateTime(2010, 2, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 2, 28).dayOfGregorianCal, SysTime(DateTime(2010, 2, 28, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 3, 1).dayOfGregorianCal, SysTime(DateTime(2010, 3, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 3, 31).dayOfGregorianCal, SysTime(DateTime(2010, 3, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 4, 1).dayOfGregorianCal, SysTime(DateTime(2010, 4, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 4, 30).dayOfGregorianCal, SysTime(DateTime(2010, 4, 30, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 5, 1).dayOfGregorianCal, SysTime(DateTime(2010, 5, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 5, 31).dayOfGregorianCal, SysTime(DateTime(2010, 5, 31, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 6, 1).dayOfGregorianCal, SysTime(DateTime(2010, 6, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 6, 30).dayOfGregorianCal, SysTime(DateTime(2010, 6, 30, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 7, 1).dayOfGregorianCal, SysTime(DateTime(2010, 7, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 7, 31).dayOfGregorianCal, SysTime(DateTime(2010, 7, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 8, 1).dayOfGregorianCal, SysTime(DateTime(2010, 8, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 8, 31).dayOfGregorianCal, SysTime(DateTime(2010, 8, 31, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 9, 1).dayOfGregorianCal, SysTime(DateTime(2010, 9, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 9, 30).dayOfGregorianCal, SysTime(DateTime(2010, 9, 30, 12, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 10, 1).dayOfGregorianCal, SysTime(DateTime(2010, 10, 1, 0, 12, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 10, 31).dayOfGregorianCal, SysTime(DateTime(2010, 10, 31, 0, 0, 12), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 11, 1).dayOfGregorianCal, SysTime(DateTime(2010, 11, 1, 23, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 11, 30).dayOfGregorianCal, SysTime(DateTime(2010, 11, 30, 0, 59, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 12, 1).dayOfGregorianCal, SysTime(DateTime(2010, 12, 1, 0, 0, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(2010, 12, 31).dayOfGregorianCal, SysTime(DateTime(2010, 12, 31, 0, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(2012, 2, 1).dayOfGregorianCal, SysTime(DateTime(2012, 2, 1, 23, 0, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(2012, 2, 28).dayOfGregorianCal, SysTime(DateTime(2012, 2, 28, 23, 59, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(2012, 2, 29).dayOfGregorianCal, SysTime(DateTime(2012, 2, 29, 7, 7, 7), FracSec.from!"hnsecs"(7)).dayOfGregorianCal);
_assertPred!"=="(Date(2012, 3, 1).dayOfGregorianCal, SysTime(DateTime(2012, 3, 1, 7, 7, 7), FracSec.from!"hnsecs"(7)).dayOfGregorianCal);
//Test B.C.
_assertPred!"=="(Date(0, 12, 31).dayOfGregorianCal, SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(0, 12, 30).dayOfGregorianCal, SysTime(DateTime(0, 12, 30, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(0, 12, 1).dayOfGregorianCal, SysTime(DateTime(0, 12, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(0, 11, 30).dayOfGregorianCal, SysTime(DateTime(0, 11, 30, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-1, 12, 31).dayOfGregorianCal, SysTime(DateTime(-1, 12, 31, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-1, 12, 30).dayOfGregorianCal, SysTime(DateTime(-1, 12, 30, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-1, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2, 12, 31).dayOfGregorianCal, SysTime(DateTime(-2, 12, 31, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2, 1, 1).dayOfGregorianCal, SysTime(DateTime(-2, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-3, 12, 31).dayOfGregorianCal, SysTime(DateTime(-3, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-3, 1, 1).dayOfGregorianCal, SysTime(DateTime(-3, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-4, 12, 31).dayOfGregorianCal, SysTime(DateTime(-4, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-4, 1, 1).dayOfGregorianCal, SysTime(DateTime(-4, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-5, 12, 31).dayOfGregorianCal, SysTime(DateTime(-5, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-5, 1, 1).dayOfGregorianCal, SysTime(DateTime(-5, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-9, 1, 1).dayOfGregorianCal, SysTime(DateTime(-9, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-49, 1, 1).dayOfGregorianCal, SysTime(DateTime(-49, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-50, 1, 1).dayOfGregorianCal, SysTime(DateTime(-50, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-97, 1, 1).dayOfGregorianCal, SysTime(DateTime(-97, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-99, 12, 31).dayOfGregorianCal, SysTime(DateTime(-99, 12, 31, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-99, 1, 1).dayOfGregorianCal, SysTime(DateTime(-99, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-100, 1, 1).dayOfGregorianCal, SysTime(DateTime(-100, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-101, 1, 1).dayOfGregorianCal, SysTime(DateTime(-101, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-105, 1, 1).dayOfGregorianCal, SysTime(DateTime(-105, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-200, 1, 1).dayOfGregorianCal, SysTime(DateTime(-200, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-201, 1, 1).dayOfGregorianCal, SysTime(DateTime(-201, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-300, 1, 1).dayOfGregorianCal, SysTime(DateTime(-300, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-301, 1, 1).dayOfGregorianCal, SysTime(DateTime(-301, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-400, 12, 31).dayOfGregorianCal, SysTime(DateTime(-400, 12, 31, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-400, 1, 1).dayOfGregorianCal, SysTime(DateTime(-400, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-401, 1, 1).dayOfGregorianCal, SysTime(DateTime(-401, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-499, 1, 1).dayOfGregorianCal, SysTime(DateTime(-499, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-500, 1, 1).dayOfGregorianCal, SysTime(DateTime(-500, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-501, 1, 1).dayOfGregorianCal, SysTime(DateTime(-501, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-1000, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1000, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-1001, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1001, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-1599, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1599, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-1600, 12, 31).dayOfGregorianCal, SysTime(DateTime(-1600, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-1600, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1600, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-1601, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1601, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-1900, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1900, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-1901, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1901, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-1999, 1, 1).dayOfGregorianCal, SysTime(DateTime(-1999, 1, 1, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-1999, 7, 6).dayOfGregorianCal, SysTime(DateTime(-1999, 7, 6, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2000, 12, 31).dayOfGregorianCal, SysTime(DateTime(-2000, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2000, 1, 1).dayOfGregorianCal, SysTime(DateTime(-2000, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2001, 1, 1).dayOfGregorianCal, SysTime(DateTime(-2001, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 1, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 1, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 1, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 2, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 2, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 2, 28).dayOfGregorianCal, SysTime(DateTime(-2010, 2, 28, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 3, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 3, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 3, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 3, 31, 12, 13, 14), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 4, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 4, 1, 12, 13, 14), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 4, 30).dayOfGregorianCal, SysTime(DateTime(-2010, 4, 30, 12, 13, 14), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 5, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 5, 1, 12, 13, 14), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 5, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 5, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 6, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 6, 1, 23, 59, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 6, 30).dayOfGregorianCal, SysTime(DateTime(-2010, 6, 30, 23, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 7, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 7, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 7, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 7, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 8, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 8, 1, 0, 0, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 8, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 8, 31, 0, 0, 0), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 9, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 9, 1, 0, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 9, 30).dayOfGregorianCal, SysTime(DateTime(-2010, 9, 30, 12, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 10, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 10, 1, 0, 12, 0), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 10, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 10, 31, 0, 0, 12), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 11, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 11, 1, 23, 0, 0), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 11, 30).dayOfGregorianCal, SysTime(DateTime(-2010, 11, 30, 0, 59, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 12, 1).dayOfGregorianCal, SysTime(DateTime(-2010, 12, 1, 0, 0, 59), FracSec.from!"hnsecs"(500)).dayOfGregorianCal);
_assertPred!"=="(Date(-2010, 12, 31).dayOfGregorianCal, SysTime(DateTime(-2010, 12, 31, 0, 59, 59), FracSec.from!"hnsecs"(50_000)).dayOfGregorianCal);
_assertPred!"=="(Date(-2012, 2, 1).dayOfGregorianCal, SysTime(DateTime(-2012, 2, 1, 23, 0, 59), FracSec.from!"hnsecs"(9_999_999)).dayOfGregorianCal);
_assertPred!"=="(Date(-2012, 2, 28).dayOfGregorianCal, SysTime(DateTime(-2012, 2, 28, 23, 59, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
_assertPred!"=="(Date(-2012, 2, 29).dayOfGregorianCal, SysTime(DateTime(-2012, 2, 29, 7, 7, 7), FracSec.from!"hnsecs"(7)).dayOfGregorianCal);
_assertPred!"=="(Date(-2012, 3, 1).dayOfGregorianCal, SysTime(DateTime(-2012, 3, 1, 7, 7, 7), FracSec.from!"hnsecs"(7)).dayOfGregorianCal);
_assertPred!"=="(Date(-3760, 9, 7).dayOfGregorianCal, SysTime(DateTime(-3760, 9, 7, 0, 0, 0), FracSec.from!"hnsecs"(0)).dayOfGregorianCal);
}
}
/++
The Xth day of the Gregorian Calendar that this $(D SysTime) is on.
Setting this property does not affect the time portion of $(D SysTime).
Params:
days = The day of the Gregorian Calendar to set this $(D SysTime)
to.
Examples:
--------------------
auto st = SysTime(DateTime(0, 0, 0, 12, 0, 0));
st.dayOfGregorianCal = 1;
assert(st == SysTime(DateTime(1, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 365;
assert(st == SysTime(DateTime(1, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = 366;
assert(st == SysTime(DateTime(2, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 0;
assert(st == SysTime(DateTime(0, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = -365;
assert(st == SysTime(DateTime(-0, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = -366;
assert(st == SysTime(DateTime(-1, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = 730_120;
assert(st == SysTime(DateTime(2000, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 734_137;
assert(st == SysTime(DateTime(2010, 12, 31, 12, 0, 0)));
--------------------
+/
@property void dayOfGregorianCal(int days) nothrow
{
auto hnsecs = adjTime;
hnsecs = removeUnitsFromHNSecs!"days"(hnsecs);
if(hnsecs < 0)
hnsecs += convert!("hours", "hnsecs")(24);
if(--days < 0)
{
hnsecs -= convert!("hours", "hnsecs")(24);
++days;
}
immutable newDaysHNSecs = convert!("days", "hnsecs")(days);
adjTime = newDaysHNSecs + hnsecs;
}
unittest
{
version(testStdDateTime)
{
void testST(SysTime orig, int day, in SysTime expected, size_t line = __LINE__)
{
orig.dayOfGregorianCal = day;
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
testST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
testST(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
testST(SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
//Test B.C.
testST(SysTime(DateTime(0, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)));
testST(SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
testST(SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(1)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1)));
testST(SysTime(DateTime(0, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
//Test Both.
testST(SysTime(DateTime(-512, 7, 20, 0, 0, 0), FracSec.from!"hnsecs"(0)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(0)));
testST(SysTime(DateTime(-513, 6, 6, 0, 0, 0), FracSec.from!"hnsecs"(1)), 1, SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1)));
testST(SysTime(DateTime(-511, 5, 7, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 1, SysTime(DateTime(1, 1, 1, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
testST(SysTime(DateTime(1607, 4, 8, 0, 0, 0), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(0, 12, 31, 0, 0, 0), FracSec.from!"hnsecs"(0)));
testST(SysTime(DateTime(1500, 3, 9, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
testST(SysTime(DateTime(999, 2, 10, 23, 59, 59), FracSec.from!"hnsecs"(1)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1)));
testST(SysTime(DateTime(2007, 12, 11, 23, 59, 59), FracSec.from!"hnsecs"(0)), 0, SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(0)));
auto sysTime = SysTime(DateTime(1, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212));
void testST2(int day, in SysTime expected, size_t line = __LINE__)
{
sysTime.dayOfGregorianCal = day;
_assertPred!"=="(sysTime, expected, "", __FILE__, line);
}
//Test A.D.
testST2(1, SysTime(DateTime(1, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(2, SysTime(DateTime(1, 1, 2, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(32, SysTime(DateTime(1, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(366, SysTime(DateTime(2, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(731, SysTime(DateTime(3, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(1096, SysTime(DateTime(4, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(1462, SysTime(DateTime(5, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(17_898, SysTime(DateTime(50, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(35_065, SysTime(DateTime(97, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(36_160, SysTime(DateTime(100, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(36_525, SysTime(DateTime(101, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(37_986, SysTime(DateTime(105, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(72_684, SysTime(DateTime(200, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(73_049, SysTime(DateTime(201, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(109_208, SysTime(DateTime(300, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(109_573, SysTime(DateTime(301, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(145_732, SysTime(DateTime(400, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(146_098, SysTime(DateTime(401, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(182_257, SysTime(DateTime(500, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(182_622, SysTime(DateTime(501, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(364_878, SysTime(DateTime(1000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(365_243, SysTime(DateTime(1001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(584_023, SysTime(DateTime(1600, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(584_389, SysTime(DateTime(1601, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(693_596, SysTime(DateTime(1900, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(693_961, SysTime(DateTime(1901, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(729_755, SysTime(DateTime(1999, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(730_120, SysTime(DateTime(2000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(730_486, SysTime(DateTime(2001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_773, SysTime(DateTime(2010, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_803, SysTime(DateTime(2010, 1, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_804, SysTime(DateTime(2010, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_831, SysTime(DateTime(2010, 2, 28, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_832, SysTime(DateTime(2010, 3, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_862, SysTime(DateTime(2010, 3, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_863, SysTime(DateTime(2010, 4, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_892, SysTime(DateTime(2010, 4, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_893, SysTime(DateTime(2010, 5, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_923, SysTime(DateTime(2010, 5, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_924, SysTime(DateTime(2010, 6, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_953, SysTime(DateTime(2010, 6, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_954, SysTime(DateTime(2010, 7, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_984, SysTime(DateTime(2010, 7, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(733_985, SysTime(DateTime(2010, 8, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_015, SysTime(DateTime(2010, 8, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_016, SysTime(DateTime(2010, 9, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_045, SysTime(DateTime(2010, 9, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_046, SysTime(DateTime(2010, 10, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_076, SysTime(DateTime(2010, 10, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_077, SysTime(DateTime(2010, 11, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_106, SysTime(DateTime(2010, 11, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_107, SysTime(DateTime(2010, 12, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_137, SysTime(DateTime(2010, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_534, SysTime(DateTime(2012, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_561, SysTime(DateTime(2012, 2, 28, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_562, SysTime(DateTime(2012, 2, 29, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_563, SysTime(DateTime(2012, 3, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_534, SysTime(DateTime(2012, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_561, SysTime(DateTime(2012, 2, 28, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_562, SysTime(DateTime(2012, 2, 29, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(734_563, SysTime(DateTime(2012, 3, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
//Test B.C.
testST2(0, SysTime(DateTime(0, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1, SysTime(DateTime(0, 12, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-30, SysTime(DateTime(0, 12, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-31, SysTime(DateTime(0, 11, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-366, SysTime(DateTime(-1, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-367, SysTime(DateTime(-1, 12, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-730, SysTime(DateTime(-1, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-731, SysTime(DateTime(-2, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1095, SysTime(DateTime(-2, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1096, SysTime(DateTime(-3, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1460, SysTime(DateTime(-3, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1461, SysTime(DateTime(-4, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1826, SysTime(DateTime(-4, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-1827, SysTime(DateTime(-5, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-2191, SysTime(DateTime(-5, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-3652, SysTime(DateTime(-9, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-18_262, SysTime(DateTime(-49, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-18_627, SysTime(DateTime(-50, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-35_794, SysTime(DateTime(-97, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-36_160, SysTime(DateTime(-99, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-36_524, SysTime(DateTime(-99, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-36_889, SysTime(DateTime(-100, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-37_254, SysTime(DateTime(-101, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-38_715, SysTime(DateTime(-105, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-73_413, SysTime(DateTime(-200, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-73_778, SysTime(DateTime(-201, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-109_937, SysTime(DateTime(-300, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-110_302, SysTime(DateTime(-301, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-146_097, SysTime(DateTime(-400, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-146_462, SysTime(DateTime(-400, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-146_827, SysTime(DateTime(-401, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-182_621, SysTime(DateTime(-499, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-182_986, SysTime(DateTime(-500, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-183_351, SysTime(DateTime(-501, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-365_607, SysTime(DateTime(-1000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-365_972, SysTime(DateTime(-1001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-584_387, SysTime(DateTime(-1599, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-584_388, SysTime(DateTime(-1600, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-584_753, SysTime(DateTime(-1600, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-585_118, SysTime(DateTime(-1601, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-694_325, SysTime(DateTime(-1900, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-694_690, SysTime(DateTime(-1901, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-730_484, SysTime(DateTime(-1999, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-730_485, SysTime(DateTime(-2000, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-730_850, SysTime(DateTime(-2000, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-731_215, SysTime(DateTime(-2001, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_502, SysTime(DateTime(-2010, 1, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_472, SysTime(DateTime(-2010, 1, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_471, SysTime(DateTime(-2010, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_444, SysTime(DateTime(-2010, 2, 28, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_443, SysTime(DateTime(-2010, 3, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_413, SysTime(DateTime(-2010, 3, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_412, SysTime(DateTime(-2010, 4, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_383, SysTime(DateTime(-2010, 4, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_382, SysTime(DateTime(-2010, 5, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_352, SysTime(DateTime(-2010, 5, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_351, SysTime(DateTime(-2010, 6, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_322, SysTime(DateTime(-2010, 6, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_321, SysTime(DateTime(-2010, 7, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_291, SysTime(DateTime(-2010, 7, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_290, SysTime(DateTime(-2010, 8, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_260, SysTime(DateTime(-2010, 8, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_259, SysTime(DateTime(-2010, 9, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_230, SysTime(DateTime(-2010, 9, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_229, SysTime(DateTime(-2010, 10, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_199, SysTime(DateTime(-2010, 10, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_198, SysTime(DateTime(-2010, 11, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_169, SysTime(DateTime(-2010, 11, 30, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_168, SysTime(DateTime(-2010, 12, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-734_138, SysTime(DateTime(-2010, 12, 31, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-735_202, SysTime(DateTime(-2012, 2, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-735_175, SysTime(DateTime(-2012, 2, 28, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-735_174, SysTime(DateTime(-2012, 2, 29, 12, 2, 9), FracSec.from!"msecs"(212)));
testST2(-735_173, SysTime(DateTime(-2012, 3, 1, 12, 2, 9), FracSec.from!"msecs"(212)));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(!__traits(compiles, cst.dayOfGregorianCal = 7));
//static assert(!__traits(compiles, ist.dayOfGregorianCal = 7));
//Verify Examples.
auto st = SysTime(DateTime(0, 1, 1, 12, 0, 0));
st.dayOfGregorianCal = 1;
assert(st == SysTime(DateTime(1, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 365;
assert(st == SysTime(DateTime(1, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = 366;
assert(st == SysTime(DateTime(2, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 0;
assert(st == SysTime(DateTime(0, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = -365;
assert(st == SysTime(DateTime(-0, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = -366;
assert(st == SysTime(DateTime(-1, 12, 31, 12, 0, 0)));
st.dayOfGregorianCal = 730_120;
assert(st == SysTime(DateTime(2000, 1, 1, 12, 0, 0)));
st.dayOfGregorianCal = 734_137;
assert(st == SysTime(DateTime(2010, 12, 31, 12, 0, 0)));
}
}
/++
The ISO 8601 week of the year that this $(D SysTime) is in.
See_Also:
$(WEB en.wikipedia.org/wiki/ISO_week_date, ISO Week Date).
+/
@property ubyte isoWeek() const nothrow
{
return (cast(Date)this).isoWeek;
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.isoWeek));
static assert(__traits(compiles, cst.isoWeek));
//static assert(__traits(compiles, ist.isoWeek));
}
}
/++
$(D SysTime) for the last day in the month that this Date is in.
The time portion of endOfMonth is always 23:59:59.9999999.
Examples:
--------------------
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonth ==
SysTime(DateTime(1999, 1, 31, 23, 59, 59),
FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0),
FracSec.from!"msecs"(24)).endOfMonth ==
SysTime(DateTime(1999, 2, 28, 23, 59, 59),
FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27),
FracSec.from!"usecs"(5203)).endOfMonth ==
SysTime(DateTime(2000, 2, 29, 23, 59, 59),
FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9),
FracSec.from!"hnsecs"(12345)).endOfMonth ==
SysTime(DateTime(2000, 6, 30, 23, 59, 59),
FracSec.from!"hnsecs"(9_999_999)));
--------------------
+/
@property SysTime endOfMonth() const nothrow
{
immutable hnsecs = adjTime;
immutable days = getUnitsFromHNSecs!"days"(hnsecs);
auto date = Date(cast(int)days + 1).endOfMonth;
auto newDays = date.dayOfGregorianCal - 1;
long theTimeHNSecs;
if(newDays < 0)
{
theTimeHNSecs = -1;
++newDays;
}
else
theTimeHNSecs = convert!("days", "hnsecs")(1) - 1;
immutable newDaysHNSecs = convert!("days", "hnsecs")(newDays);
auto retval = SysTime(this._stdTime, this._timezone);
retval.adjTime = newDaysHNSecs + theTimeHNSecs;
return retval;
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(Date(1999, 1, 1)).endOfMonth, SysTime(DateTime(1999, 1, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 2, 1)).endOfMonth, SysTime(DateTime(1999, 2, 28, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(2000, 2, 1)).endOfMonth, SysTime(DateTime(2000, 2, 29, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 3, 1)).endOfMonth, SysTime(DateTime(1999, 3, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 4, 1)).endOfMonth, SysTime(DateTime(1999, 4, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 5, 1)).endOfMonth, SysTime(DateTime(1999, 5, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 6, 1)).endOfMonth, SysTime(DateTime(1999, 6, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 7, 1)).endOfMonth, SysTime(DateTime(1999, 7, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 8, 1)).endOfMonth, SysTime(DateTime(1999, 8, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 9, 1)).endOfMonth, SysTime(DateTime(1999, 9, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 10, 1)).endOfMonth, SysTime(DateTime(1999, 10, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 11, 1)).endOfMonth, SysTime(DateTime(1999, 11, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(1999, 12, 1)).endOfMonth, SysTime(DateTime(1999, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
//Test B.C.
_assertPred!"=="(SysTime(Date(-1999, 1, 1)).endOfMonth, SysTime(DateTime(-1999, 1, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 2, 1)).endOfMonth, SysTime(DateTime(-1999, 2, 28, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-2000, 2, 1)).endOfMonth, SysTime(DateTime(-2000, 2, 29, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 3, 1)).endOfMonth, SysTime(DateTime(-1999, 3, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 4, 1)).endOfMonth, SysTime(DateTime(-1999, 4, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 5, 1)).endOfMonth, SysTime(DateTime(-1999, 5, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 6, 1)).endOfMonth, SysTime(DateTime(-1999, 6, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 7, 1)).endOfMonth, SysTime(DateTime(-1999, 7, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 8, 1)).endOfMonth, SysTime(DateTime(-1999, 8, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 9, 1)).endOfMonth, SysTime(DateTime(-1999, 9, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 10, 1)).endOfMonth, SysTime(DateTime(-1999, 10, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 11, 1)).endOfMonth, SysTime(DateTime(-1999, 11, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
_assertPred!"=="(SysTime(Date(-1999, 12, 1)).endOfMonth, SysTime(DateTime(-1999, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.endOfMonth));
//static assert(__traits(compiles, ist.endOfMonth));
//Verify Examples.
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonth == SysTime(DateTime(1999, 1, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0), FracSec.from!"msecs"(24)).endOfMonth == SysTime(DateTime(1999, 2, 28, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27), FracSec.from!"usecs"(5203)).endOfMonth == SysTime(DateTime(2000, 2, 29, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9), FracSec.from!"hnsecs"(12345)).endOfMonth == SysTime(DateTime(2000, 6, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
}
}
/++
The last day in the month that this $(D SysTime) is in.
Examples:
--------------------
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).daysInMonth == 31);
assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0)).daysInMonth == 28);
assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27)).daysInMonth == 29);
assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9)).daysInMonth == 30);
--------------------
+/
@property ubyte daysInMonth() const nothrow
{
return Date(dayOfGregorianCal).daysInMonth;
}
//Explicitly undocumented. Do not use. To be removed in March 2013.
deprecated("Please use daysInMonth instead.") @property ubyte endOfMonthDay() const nothrow
{
return Date(dayOfGregorianCal).daysInMonth;
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(DateTime(1999, 1, 1, 12, 1, 13)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 2, 1, 17, 13, 12)).daysInMonth, 28);
_assertPred!"=="(SysTime(DateTime(2000, 2, 1, 13, 2, 12)).daysInMonth, 29);
_assertPred!"=="(SysTime(DateTime(1999, 3, 1, 12, 13, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 4, 1, 12, 6, 13)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(1999, 5, 1, 15, 13, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 6, 1, 13, 7, 12)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(1999, 7, 1, 12, 13, 17)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 8, 1, 12, 3, 13)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 9, 1, 12, 13, 12)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(1999, 10, 1, 13, 19, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(1999, 11, 1, 12, 13, 17)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(1999, 12, 1, 12, 52, 13)).daysInMonth, 31);
//Test B.C.
_assertPred!"=="(SysTime(DateTime(-1999, 1, 1, 12, 1, 13)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 2, 1, 7, 13, 12)).daysInMonth, 28);
_assertPred!"=="(SysTime(DateTime(-2000, 2, 1, 13, 2, 12)).daysInMonth, 29);
_assertPred!"=="(SysTime(DateTime(-1999, 3, 1, 12, 13, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 4, 1, 12, 6, 13)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(-1999, 5, 1, 5, 13, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 6, 1, 13, 7, 12)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(-1999, 7, 1, 12, 13, 17)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 8, 1, 12, 3, 13)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 9, 1, 12, 13, 12)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(-1999, 10, 1, 13, 19, 12)).daysInMonth, 31);
_assertPred!"=="(SysTime(DateTime(-1999, 11, 1, 12, 13, 17)).daysInMonth, 30);
_assertPred!"=="(SysTime(DateTime(-1999, 12, 1, 12, 52, 13)).daysInMonth, 31);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.daysInMonth));
//static assert(__traits(compiles, ist.daysInMonth));
//Verify Examples.
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).daysInMonth == 31);
assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0)).daysInMonth == 28);
assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27)).daysInMonth == 29);
assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9)).daysInMonth == 30);
}
}
/++
Whether the current year is a date in A.D.
Examples:
--------------------
assert(SysTime(DateTime(1, 1, 1, 12, 7, 0)).isAD);
assert(SysTime(DateTime(2010, 12, 31, 0, 0, 0)).isAD);
assert(!SysTime(DateTime(0, 12, 31, 23, 59, 59)).isAD);
assert(!SysTime(DateTime(-2010, 1, 1, 2, 2, 2)).isAD);
--------------------
+/
@property bool isAD() const nothrow
{
return adjTime >= 0;
}
unittest
{
version(testStdDateTime)
{
assert(SysTime(DateTime(2010, 7, 4, 12, 0, 9)).isAD);
assert(SysTime(DateTime(1, 1, 1, 0, 0, 0)).isAD);
assert(!SysTime(DateTime(0, 12, 31, 23, 59, 59)).isAD);
assert(!SysTime(DateTime(0, 1, 1, 23, 59, 59)).isAD);
assert(!SysTime(DateTime(-1, 1, 1, 23 ,59 ,59)).isAD);
assert(!SysTime(DateTime(-2010, 7, 4, 12, 2, 2)).isAD);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.isAD));
//static assert(__traits(compiles, ist.isAD));
//Verify Examples.
assert(SysTime(DateTime(1, 1, 1, 12, 7, 0)).isAD);
assert(SysTime(DateTime(2010, 12, 31, 0, 0, 0)).isAD);
assert(!SysTime(DateTime(0, 12, 31, 23, 59, 59)).isAD);
assert(!SysTime(DateTime(-2010, 1, 1, 2, 2, 2)).isAD);
}
}
/++
The julian day for this $(D SysTime) at the given time. For example,
prior to noon, 1996-03-31 would be the julian day number 2_450_173, so
this function returns 2_450_173, while from noon onward, the julian
day number would be 2_450_174, so this function returns 2_450_174.
+/
@property long julianDay() const nothrow
{
immutable jd = dayOfGregorianCal + 1_721_425;
return hour < 12 ? jd - 1 : jd;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(SysTime(DateTime(-4713, 11, 24, 0, 0, 0)).julianDay, -1);
_assertPred!"=="(SysTime(DateTime(-4713, 11, 24, 12, 0, 0)).julianDay, 0);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 0, 0, 0)).julianDay, 1_721_424);
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 12, 0, 0)).julianDay, 1_721_425);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0)).julianDay, 1_721_425);
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 12, 0, 0)).julianDay, 1_721_426);
_assertPred!"=="(SysTime(DateTime(1582, 10, 15, 0, 0, 0)).julianDay, 2_299_160);
_assertPred!"=="(SysTime(DateTime(1582, 10, 15, 12, 0, 0)).julianDay, 2_299_161);
_assertPred!"=="(SysTime(DateTime(1858, 11, 17, 0, 0, 0)).julianDay, 2_400_000);
_assertPred!"=="(SysTime(DateTime(1858, 11, 17, 12, 0, 0)).julianDay, 2_400_001);
_assertPred!"=="(SysTime(DateTime(1982, 1, 4, 0, 0, 0)).julianDay, 2_444_973);
_assertPred!"=="(SysTime(DateTime(1982, 1, 4, 12, 0, 0)).julianDay, 2_444_974);
_assertPred!"=="(SysTime(DateTime(1996, 3, 31, 0, 0, 0)).julianDay, 2_450_173);
_assertPred!"=="(SysTime(DateTime(1996, 3, 31, 12, 0, 0)).julianDay, 2_450_174);
_assertPred!"=="(SysTime(DateTime(2010, 8, 24, 0, 0, 0)).julianDay, 2_455_432);
_assertPred!"=="(SysTime(DateTime(2010, 8, 24, 12, 0, 0)).julianDay, 2_455_433);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.julianDay));
//static assert(__traits(compiles, ist.julianDay));
}
}
/++
The modified julian day for any time on this date (since, the modified
julian day changes at midnight).
+/
@property long modJulianDay() const nothrow
{
return (dayOfGregorianCal + 1_721_425) - 2_400_001;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(SysTime(DateTime(1858, 11, 17, 0, 0, 0)).modJulianDay, 0);
_assertPred!"=="(SysTime(DateTime(1858, 11, 17, 12, 0, 0)).modJulianDay, 0);
_assertPred!"=="(SysTime(DateTime(2010, 8, 24, 0, 0, 0)).modJulianDay, 55_432);
_assertPred!"=="(SysTime(DateTime(2010, 8, 24, 12, 0, 0)).modJulianDay, 55_432);
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cst.modJulianDay));
//static assert(__traits(compiles, ist.modJulianDay));
}
}
/++
Returns a $(D Date) equivalent to this $(D SysTime).
+/
Date opCast(T)() const nothrow
if(is(Unqual!T == Date))
{
return Date(dayOfGregorianCal);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(cast(Date)SysTime(Date(1999, 7, 6)), Date(1999, 7, 6));
_assertPred!"=="(cast(Date)SysTime(Date(2000, 12, 31)), Date(2000, 12, 31));
_assertPred!"=="(cast(Date)SysTime(Date(2001, 1, 1)), Date(2001, 1, 1));
_assertPred!"=="(cast(Date)SysTime(DateTime(1999, 7, 6, 12, 10, 9)), Date(1999, 7, 6));
_assertPred!"=="(cast(Date)SysTime(DateTime(2000, 12, 31, 13, 11, 10)), Date(2000, 12, 31));
_assertPred!"=="(cast(Date)SysTime(DateTime(2001, 1, 1, 14, 12, 11)), Date(2001, 1, 1));
_assertPred!"=="(cast(Date)SysTime(Date(-1999, 7, 6)), Date(-1999, 7, 6));
_assertPred!"=="(cast(Date)SysTime(Date(-2000, 12, 31)), Date(-2000, 12, 31));
_assertPred!"=="(cast(Date)SysTime(Date(-2001, 1, 1)), Date(-2001, 1, 1));
_assertPred!"=="(cast(Date)SysTime(DateTime(-1999, 7, 6, 12, 10, 9)), Date(-1999, 7, 6));
_assertPred!"=="(cast(Date)SysTime(DateTime(-2000, 12, 31, 13, 11, 10)), Date(-2000, 12, 31));
_assertPred!"=="(cast(Date)SysTime(DateTime(-2001, 1, 1, 14, 12, 11)), Date(-2001, 1, 1));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(Date)cst));
//static assert(__traits(compiles, cast(Date)ist));
}
}
/++
Returns a $(D DateTime) equivalent to this $(D SysTime).
+/
DateTime opCast(T)() const nothrow
if(is(Unqual!T == DateTime))
{
try
{
auto hnsecs = adjTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable second = getUnitsFromHNSecs!"seconds"(hnsecs);
return DateTime(Date(cast(int)days), TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second));
}
catch(Exception e)
assert(0, "Either DateTime's constructor or TimeOfDay's constructor threw.");
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(cast(DateTime)SysTime(DateTime(1, 1, 6, 7, 12, 22)), DateTime(1, 1, 6, 7, 12, 22));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(1, 1, 6, 7, 12, 22), FracSec.from!"msecs"(22)), DateTime(1, 1, 6, 7, 12, 22));
_assertPred!"=="(cast(DateTime)SysTime(Date(1999, 7, 6)), DateTime(1999, 7, 6, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(Date(2000, 12, 31)), DateTime(2000, 12, 31, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(Date(2001, 1, 1)), DateTime(2001, 1, 1, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(1999, 7, 6, 12, 10, 9)), DateTime(1999, 7, 6, 12, 10, 9));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(2000, 12, 31, 13, 11, 10)), DateTime(2000, 12, 31, 13, 11, 10));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(2001, 1, 1, 14, 12, 11)), DateTime(2001, 1, 1, 14, 12, 11));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(-1, 1, 6, 7, 12, 22)), DateTime(-1, 1, 6, 7, 12, 22));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(-1, 1, 6, 7, 12, 22), FracSec.from!"msecs"(22)), DateTime(-1, 1, 6, 7, 12, 22));
_assertPred!"=="(cast(DateTime)SysTime(Date(-1999, 7, 6)), DateTime(-1999, 7, 6, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(Date(-2000, 12, 31)), DateTime(-2000, 12, 31, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(Date(-2001, 1, 1)), DateTime(-2001, 1, 1, 0, 0, 0));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(-1999, 7, 6, 12, 10, 9)), DateTime(-1999, 7, 6, 12, 10, 9));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(-2000, 12, 31, 13, 11, 10)), DateTime(-2000, 12, 31, 13, 11, 10));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(-2001, 1, 1, 14, 12, 11)), DateTime(-2001, 1, 1, 14, 12, 11));
_assertPred!"=="(cast(DateTime)SysTime(DateTime(2011, 1, 13, 8, 17, 2), FracSec.from!"msecs"(296), LocalTime()),
DateTime(2011, 1, 13, 8, 17, 2));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(DateTime)cst));
//static assert(__traits(compiles, cast(DateTime)ist));
}
}
/++
Returns a $(D TimeOfDay) equivalent to this $(D SysTime).
+/
TimeOfDay opCast(T)() const nothrow
if(is(Unqual!T == TimeOfDay))
{
try
{
auto hnsecs = adjTime;
hnsecs = removeUnitsFromHNSecs!"days"(hnsecs);
if(hnsecs < 0)
hnsecs += convert!("hours", "hnsecs")(24);
immutable hour = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable second = getUnitsFromHNSecs!"seconds"(hnsecs);
return TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second);
}
catch(Exception e)
assert(0, "TimeOfDay's constructor threw.");
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(1999, 7, 6)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(2000, 12, 31)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(2001, 1, 1)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(1999, 7, 6, 12, 10, 9)), TimeOfDay(12, 10, 9));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(2000, 12, 31, 13, 11, 10)), TimeOfDay(13, 11, 10));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(2001, 1, 1, 14, 12, 11)), TimeOfDay(14, 12, 11));
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(-1999, 7, 6)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(-2000, 12, 31)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(Date(-2001, 1, 1)), TimeOfDay(0, 0, 0));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(-1999, 7, 6, 12, 10, 9)), TimeOfDay(12, 10, 9));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(-2000, 12, 31, 13, 11, 10)), TimeOfDay(13, 11, 10));
_assertPred!"=="(cast(TimeOfDay)SysTime(DateTime(-2001, 1, 1, 14, 12, 11)), TimeOfDay(14, 12, 11));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(TimeOfDay)cst));
//static assert(__traits(compiles, cast(TimeOfDay)ist));
}
}
//Temporary hack until bug http://d.puremagic.com/issues/show_bug.cgi?id=4867 is fixed.
//This allows assignment from const(SysTime) to SysTime.
//It may be a good idea to keep it though, since casting from a type to itself
//should be allowed, and it doesn't work without this opCast() since opCast()
//has already been defined for other types.
SysTime opCast(T)() const pure nothrow
if(is(Unqual!T == SysTime))
{
return SysTime(_stdTime, _timezone);
}
/++
Converts this $(D SysTime) to a string with the format
YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds and TZ is time
zone).
Note that the number of digits in the fractional seconds varies with the
number of fractional seconds. It's a maximum of 7 (which would be
hnsecs), but only has as many as are necessary to hold the correct value
(so no trailing zeroes), and if there are no fractional seconds, then
there is no decimal point.
If this $(D SysTime)'s time zone is $(D LocalTime), then TZ is empty.
If its time zone is $(D UTC), then it is "Z". Otherwise, it is the
offset from UTC (e.g. +1:00 or -7:00). Note that the offset from UTC
is $(I not) enough to uniquely identify the time zone.
Time zone offsets will be in the form +HH:MM or -HH:MM.
Examples:
--------------------
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOString() ==
"20100704T070612");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toISOString() ==
"19981225T021500.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOString() ==
"00000105T230959");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toISOString() ==
"-00040105T000002.052092");
--------------------
+/
string toISOString() const nothrow
{
try
{
immutable adjustedTime = adjTime;
long hnsecs = adjustedTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto hour = splitUnitsFromHNSecs!"hours"(hnsecs);
auto minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
auto second = splitUnitsFromHNSecs!"seconds"(hnsecs);
auto dateTime = DateTime(Date(cast(int)days), TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second));
auto fracSecStr = fracSecToISOString(cast(int)hnsecs);
if(_timezone is LocalTime())
return dateTime.toISOString() ~ fracSecToISOString(cast(int)hnsecs);
if(_timezone is UTC())
return dateTime.toISOString() ~ fracSecToISOString(cast(int)hnsecs) ~ "Z";
immutable utcOffset = dur!"hnsecs"(adjustedTime - stdTime);
return format("%s%s%s",
dateTime.toISOString(),
fracSecToISOString(cast(int)hnsecs),
SimpleTimeZone.toISOString(utcOffset));
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(DateTime.init, UTC()).toISOString(), "00010101T000000Z");
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1), UTC()).toISOString(), "00010101T000000.0000001Z");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0)).toISOString(), "00091204T000000");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12)).toISOString(), "00991204T050612");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59)).toISOString(), "09991204T134459");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59)).toISOString(), "99990704T235959");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1)).toISOString(), "+100001020T010101");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toISOString(), "00091204T000000.042");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toISOString(), "00991204T050612.1");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toISOString(), "09991204T134459.04502");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toISOString(), "99990704T235959.0000012");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toISOString(), "+100001020T010101.050789");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(-360))).toISOString(),
"20121221T121212-06:00");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(420))).toISOString(),
"20121221T121212+07:00");
//Test B.C.
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()).toISOString(), "00001231T235959.9999999Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1), UTC()).toISOString(), "00001231T235959.0000001Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), UTC()).toISOString(), "00001231T235959Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 12, 4)).toISOString(), "00001204T001204");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0)).toISOString(), "-00091204T000000");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12)).toISOString(), "-00991204T050612");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59)).toISOString(), "-09991204T134459");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59)).toISOString(), "-99990704T235959");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1)).toISOString(), "-100001020T010101");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 0, 0), FracSec.from!"msecs"(7)).toISOString(), "00001204T000000.007");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toISOString(), "-00091204T000000.042");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toISOString(), "-00991204T050612.1");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toISOString(), "-09991204T134459.04502");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toISOString(), "-99990704T235959.0000012");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toISOString(), "-100001020T010101.050789");
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(TimeOfDay)cst));
//static assert(__traits(compiles, cast(TimeOfDay)ist));
//Verify Examples.
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOString() ==
"20100704T070612");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toISOString() ==
"19981225T021500.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOString() ==
"00000105T230959");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toISOString() ==
"-00040105T000002.052092");
}
}
/++
Converts this $(D SysTime) to a string with the format
YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ
is the time zone).
Note that the number of digits in the fractional seconds varies with the
number of fractional seconds. It's a maximum of 7 (which would be
hnsecs), but only has as many as are necessary to hold the correct value
(so no trailing zeroes), and if there are no fractional seconds, then
there is no decimal point.
If this $(D SysTime)'s time zone is $(D LocalTime), then TZ is empty. If
its time zone is $(D UTC), then it is "Z". Otherwise, it is the offset
from UTC (e.g. +1:00 or -7:00). Note that the offset from UTC is
$(I not) enough to uniquely identify the time zone.
Time zone offsets will be in the form +HH:MM or -HH:MM.
Examples:
--------------------
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOExtString() ==
"2010-07-04T07:06:12");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toISOExtString() ==
"1998-12-25T02:15:00.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOExtString() ==
"0000-01-05T23:09:59");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toISOExtString() ==
"-0004-01-05T00:00:02.052092");
--------------------
+/
string toISOExtString() const nothrow
{
try
{
immutable adjustedTime = adjTime;
long hnsecs = adjustedTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto hour = splitUnitsFromHNSecs!"hours"(hnsecs);
auto minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
auto second = splitUnitsFromHNSecs!"seconds"(hnsecs);
auto dateTime = DateTime(Date(cast(int)days), TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second));
auto fracSecStr = fracSecToISOString(cast(int)hnsecs);
if(_timezone is LocalTime())
return dateTime.toISOExtString() ~ fracSecToISOString(cast(int)hnsecs);
if(_timezone is UTC())
return dateTime.toISOExtString() ~ fracSecToISOString(cast(int)hnsecs) ~ "Z";
immutable utcOffset = dur!"hnsecs"(adjustedTime - stdTime);
return format("%s%s%s",
dateTime.toISOExtString(),
fracSecToISOString(cast(int)hnsecs),
SimpleTimeZone.toISOString(utcOffset));
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(DateTime.init, UTC()).toISOExtString(), "0001-01-01T00:00:00Z");
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1), UTC()).toISOExtString(), "0001-01-01T00:00:00.0000001Z");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0)).toISOExtString(), "0009-12-04T00:00:00");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12)).toISOExtString(), "0099-12-04T05:06:12");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59)).toISOExtString(), "0999-12-04T13:44:59");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59)).toISOExtString(), "9999-07-04T23:59:59");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1)).toISOExtString(), "+10000-10-20T01:01:01");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toISOExtString(), "0009-12-04T00:00:00.042");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toISOExtString(), "0099-12-04T05:06:12.1");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toISOExtString(), "0999-12-04T13:44:59.04502");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toISOExtString(), "9999-07-04T23:59:59.0000012");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toISOExtString(), "+10000-10-20T01:01:01.050789");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(-360))).toISOExtString(),
"2012-12-21T12:12:12-06:00");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(420))).toISOExtString(),
"2012-12-21T12:12:12+07:00");
//Test B.C.
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()).toISOExtString(), "0000-12-31T23:59:59.9999999Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1), UTC()).toISOExtString(), "0000-12-31T23:59:59.0000001Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), UTC()).toISOExtString(), "0000-12-31T23:59:59Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 12, 4)).toISOExtString(), "0000-12-04T00:12:04");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0)).toISOExtString(), "-0009-12-04T00:00:00");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12)).toISOExtString(), "-0099-12-04T05:06:12");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59)).toISOExtString(), "-0999-12-04T13:44:59");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59)).toISOExtString(), "-9999-07-04T23:59:59");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1)).toISOExtString(), "-10000-10-20T01:01:01");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 0, 0), FracSec.from!"msecs"(7)).toISOExtString(), "0000-12-04T00:00:00.007");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toISOExtString(), "-0009-12-04T00:00:00.042");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toISOExtString(), "-0099-12-04T05:06:12.1");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toISOExtString(), "-0999-12-04T13:44:59.04502");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toISOExtString(), "-9999-07-04T23:59:59.0000012");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toISOExtString(), "-10000-10-20T01:01:01.050789");
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(TimeOfDay)cst));
//static assert(__traits(compiles, cast(TimeOfDay)ist));
//Verify Examples.
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOExtString() ==
"2010-07-04T07:06:12");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toISOExtString() ==
"1998-12-25T02:15:00.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOExtString() ==
"0000-01-05T23:09:59");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toISOExtString() ==
"-0004-01-05T00:00:02.052092");
}
}
/++
Converts this $(D SysTime) to a string with the format
YYYY-Mon-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ
is the time zone).
Note that the number of digits in the fractional seconds varies with the
number of fractional seconds. It's a maximum of 7 (which would be
hnsecs), but only has as many as are necessary to hold the correct value
(so no trailing zeroes), and if there are no fractional seconds, then
there is no decimal point.
If this $(D SysTime)'s time zone is $(D LocalTime), then TZ is empty. If
its time zone is $(D UTC), then it is "Z". Otherwise, it is the offset
from UTC (e.g. +1:00 or -7:00). Note that the offset from UTC is
$(I not) enough to uniquely identify the time zone.
Time zone offsets will be in the form +HH:MM or -HH:MM.
Examples:
--------------------
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toSimpleString() ==
"2010-Jul-04 07:06:12");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toSimpleString() ==
"1998-Dec-25 02:15:00.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toSimpleString() ==
"0000-Jan-05 23:09:59");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toSimpleString() ==
"-0004-Jan-05 00:00:02.052092");
--------------------
+/
string toSimpleString() const nothrow
{
try
{
immutable adjustedTime = adjTime;
long hnsecs = adjustedTime;
auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1;
if(hnsecs < 0)
{
hnsecs += convert!("hours", "hnsecs")(24);
--days;
}
auto hour = splitUnitsFromHNSecs!"hours"(hnsecs);
auto minute = splitUnitsFromHNSecs!"minutes"(hnsecs);
auto second = splitUnitsFromHNSecs!"seconds"(hnsecs);
auto dateTime = DateTime(Date(cast(int)days), TimeOfDay(cast(int)hour, cast(int)minute, cast(int)second));
auto fracSecStr = fracSecToISOString(cast(int)hnsecs);
if(_timezone is LocalTime())
return dateTime.toSimpleString() ~ fracSecToISOString(cast(int)hnsecs);
if(_timezone is UTC())
return dateTime.toSimpleString() ~ fracSecToISOString(cast(int)hnsecs) ~ "Z";
immutable utcOffset = dur!"hnsecs"(adjustedTime - stdTime);
return format("%s%s%s",
dateTime.toSimpleString(),
fracSecToISOString(cast(int)hnsecs),
SimpleTimeZone.toISOString(utcOffset));
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(SysTime(DateTime.init, UTC()).toString(), "0001-Jan-01 00:00:00Z");
_assertPred!"=="(SysTime(DateTime(1, 1, 1, 0, 0, 0), FracSec.from!"hnsecs"(1), UTC()).toString(), "0001-Jan-01 00:00:00.0000001Z");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0)).toSimpleString(), "0009-Dec-04 00:00:00");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12)).toSimpleString(), "0099-Dec-04 05:06:12");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59)).toSimpleString(), "0999-Dec-04 13:44:59");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59)).toSimpleString(), "9999-Jul-04 23:59:59");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1)).toSimpleString(), "+10000-Oct-20 01:01:01");
_assertPred!"=="(SysTime(DateTime(9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toSimpleString(), "0009-Dec-04 00:00:00.042");
_assertPred!"=="(SysTime(DateTime(99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toSimpleString(), "0099-Dec-04 05:06:12.1");
_assertPred!"=="(SysTime(DateTime(999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toSimpleString(), "0999-Dec-04 13:44:59.04502");
_assertPred!"=="(SysTime(DateTime(9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toSimpleString(), "9999-Jul-04 23:59:59.0000012");
_assertPred!"=="(SysTime(DateTime(10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toSimpleString(), "+10000-Oct-20 01:01:01.050789");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(-360))).toSimpleString(),
"2012-Dec-21 12:12:12-06:00");
_assertPred!"=="(SysTime(DateTime(2012, 12, 21, 12, 12, 12),
new SimpleTimeZone(dur!"minutes"(420))).toSimpleString(),
"2012-Dec-21 12:12:12+07:00");
//Test B.C.
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999), UTC()).toSimpleString(), "0000-Dec-31 23:59:59.9999999Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), FracSec.from!"hnsecs"(1), UTC()).toSimpleString(), "0000-Dec-31 23:59:59.0000001Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 31, 23, 59, 59), UTC()).toSimpleString(), "0000-Dec-31 23:59:59Z");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 12, 4)).toSimpleString(), "0000-Dec-04 00:12:04");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0)).toSimpleString(), "-0009-Dec-04 00:00:00");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12)).toSimpleString(), "-0099-Dec-04 05:06:12");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59)).toSimpleString(), "-0999-Dec-04 13:44:59");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59)).toSimpleString(), "-9999-Jul-04 23:59:59");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1)).toSimpleString(), "-10000-Oct-20 01:01:01");
_assertPred!"=="(SysTime(DateTime(0, 12, 4, 0, 0, 0), FracSec.from!"msecs"(7)).toSimpleString(), "0000-Dec-04 00:00:00.007");
_assertPred!"=="(SysTime(DateTime(-9, 12, 4, 0, 0, 0), FracSec.from!"msecs"(42)).toSimpleString(), "-0009-Dec-04 00:00:00.042");
_assertPred!"=="(SysTime(DateTime(-99, 12, 4, 5, 6, 12), FracSec.from!"msecs"(100)).toSimpleString(), "-0099-Dec-04 05:06:12.1");
_assertPred!"=="(SysTime(DateTime(-999, 12, 4, 13, 44, 59), FracSec.from!"usecs"(45020)).toSimpleString(), "-0999-Dec-04 13:44:59.04502");
_assertPred!"=="(SysTime(DateTime(-9999, 7, 4, 23, 59, 59), FracSec.from!"hnsecs"(12)).toSimpleString(), "-9999-Jul-04 23:59:59.0000012");
_assertPred!"=="(SysTime(DateTime(-10000, 10, 20, 1, 1, 1), FracSec.from!"hnsecs"(507890)).toSimpleString(), "-10000-Oct-20 01:01:01.050789");
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, cast(TimeOfDay)cst));
//static assert(__traits(compiles, cast(TimeOfDay)ist));
//Verify Examples.
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toSimpleString() ==
"2010-Jul-04 07:06:12");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0),
FracSec.from!"msecs"(24)).toSimpleString() ==
"1998-Dec-25 02:15:00.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toSimpleString() ==
"0000-Jan-05 23:09:59");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2),
FracSec.from!"hnsecs"(520_920)).toSimpleString() ==
"-0004-Jan-05 00:00:02.052092");
}
}
/+
Converts this $(D SysTime) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return toSimpleString();
}
/++
Converts this $(D SysTime) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return toSimpleString();
}
unittest
{
version(testStdDateTime)
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
//immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33));
static assert(__traits(compiles, st.toString()));
static assert(__traits(compiles, cst.toString()));
//static assert(__traits(compiles, ist.toString()));
}
}
/++
Creates a $(D SysTime) from a string with the format
YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds is the time
zone). Whitespace is stripped from the given string.
The exact format is exactly as described in $(D toISOString) except that
trailing zeroes are permitted - including having fractional seconds with
all zeroes. However, a decimal point with nothing following it is
invalid.
If there is no time zone in the string, then $(D LocalTime) is used. If
the time zone is "Z", then $(D UTC) is used. Otherwise, a
$(LREF SimpleTimeZone) which corresponds to the given offset from UTC is
used. To get the returned $(D SysTime) to be a particular time
zone, pass in that time zone and the $(D SysTime) to be returned
will be converted to that time zone (though it will still be read in as
whatever time zone is in its string).
The accepted formats for time zone offsets
are +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
Params:
isoString = A string formatted in the ISO format for dates and times.
tz = The time zone to convert the given time to (no
conversion occurs if null).
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D SysTime) would not be valid.
Examples:
--------------------
assert(SysTime.fromISOString("20100704T070612") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOString("19981225T021500.007") ==
SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromISOString("00000105T230959.00002") ==
SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromISOString("-00040105T000002") ==
SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromISOString(" 20100704T070612 ") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOString("20100704T070612Z") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromISOString("20100704T070612-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromISOString("20100704T070612+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(8))));
--------------------
+/
static SysTime fromISOString(S)(in S isoString, immutable TimeZone tz = null)
if(isSomeString!S)
{
auto dstr = to!dstring(strip(isoString));
immutable skipFirst = dstr.startsWith("+", "-") != 0;
auto found = (skipFirst ? dstr[1..$] : dstr).find(".", "Z", "+", "-");
auto dateTimeStr = dstr[0 .. $ - found[0].length];
dstring fracSecStr;
dstring zoneStr;
if(found[1] != 0)
{
if(found[1] == 1)
{
auto foundTZ = found[0].find("Z", "+", "-");
if(foundTZ[1] != 0)
{
fracSecStr = found[0][0 .. $ - foundTZ[0].length];
zoneStr = foundTZ[0];
}
else
fracSecStr = found[0];
}
else
zoneStr = found[0];
}
try
{
auto dateTime = DateTime.fromISOString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
Rebindable!(immutable TimeZone) parsedZone;
if(zoneStr.empty)
parsedZone = LocalTime();
else if(zoneStr == "Z")
parsedZone = UTC();
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);
auto retval = SysTime(dateTime, fracSec, parsedZone);
if(tz !is null)
retval.timezone = tz;
return retval;
}
catch(DateTimeException dte)
throw new DateTimeException(format("Invalid ISO String: %s", isoString));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(SysTime.fromISOString(""));
assertThrown!DateTimeException(SysTime.fromISOString("20100704000000"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704 000000"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704t000000"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000."));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000.A"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000.Z"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000.00000000"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000.00000000"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000+"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000-"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000:"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000-:"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000+:"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000-1:"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000+1:"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000+1:0"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000-24.00"));
assertThrown!DateTimeException(SysTime.fromISOString("20100704T000000+24.00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-07-0400:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Jul-04 00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Jul-04T00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(SysTime.fromISOString("2010-12-22T172201"));
assertThrown!DateTimeException(SysTime.fromISOString("2010-Dec-22 17:22:01"));
_assertPred!"=="(SysTime.fromISOString("20101222T172201"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
_assertPred!"=="(SysTime.fromISOString("19990706T123033"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString("-19990706T123033"), SysTime(DateTime(-1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString("+019990706T123033"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString("19990706T123033 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString(" 19990706T123033"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString(" 19990706T123033 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.0"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.0000000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.0000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"hnsecs"(1)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.0000010"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromISOString("19070707T121212.0010000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromISOString("20101222T172201Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), UTC()));
_assertPred!"=="(SysTime.fromISOString("20101222T172201-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(480))));
_assertPred!"=="(SysTime.fromISOString("20101103T065106.57159Z"),
SysTime(DateTime(2010, 11, 3, 6, 51, 6), FracSec.from!"hnsecs"(5715900), UTC()));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.23412Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_341_200), UTC()));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.23112-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_311_200),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.45-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.1-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_000_000),
new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.55-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(5_500_000),
new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.1234567+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_234_567),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.0+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.0000000+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromISOString("20101222T172201.45+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(480))));
//Verify Examples.
assert(SysTime.fromISOString("20100704T070612") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOString("19981225T021500.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromISOString("00000105T230959.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromISOString("-00040105T000002") == SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromISOString(" 20100704T070612 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOString("20100704T070612Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromISOString("20100704T070612-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromISOString("20100704T070612+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
}
}
/++
Creates a $(D SysTime) from a string with the format
YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds is the
time zone). Whitespace is stripped from the given string.
The exact format is exactly as described in $(D toISOExtString)
except that trailing zeroes are permitted - including having fractional
seconds with all zeroes. However, a decimal point with nothing following
it is invalid.
If there is no time zone in the string, then $(D LocalTime) is used. If
the time zone is "Z", then $(D UTC) is used. Otherwise, a
$(LREF SimpleTimeZone) which corresponds to the given offset from UTC is
used. To get the returned $(D SysTime) to be a particular time
zone, pass in that time zone and the $(D SysTime) to be returned
will be converted to that time zone (though it will still be read in as
whatever time zone is in its string).
The accepted formats for time zone offsets
are +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
Params:
isoString = A string formatted in the ISO Extended format for dates
and times.
tz = The time zone to convert the given time to (no
conversion occurs if null).
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D SysTime) would not be valid.
Examples:
--------------------
assert(SysTime.fromISOExtString("2010-07-04T07:06:12") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOExtString("1998-12-25T02:15:00.007") ==
SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromISOExtString("0000-01-05T23:09:59.00002") ==
SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromISOExtString("-0004-01-05T00:00:02") ==
SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromISOExtString(" 2010-07-04T07:06:12 ") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12Z") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(8))));
--------------------
+/
static SysTime fromISOExtString(S)(in S isoExtString, immutable TimeZone tz = null)
if(isSomeString!(S))
{
auto dstr = to!dstring(strip(isoExtString));
auto tIndex = dstr.stds_indexOf("T");
enforce(tIndex != -1, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto found = dstr[tIndex + 1 .. $].find(".", "Z", "+", "-");
auto dateTimeStr = dstr[0 .. $ - found[0].length];
dstring fracSecStr;
dstring zoneStr;
if(found[1] != 0)
{
if(found[1] == 1)
{
auto foundTZ = found[0].find("Z", "+", "-");
if(foundTZ[1] != 0)
{
fracSecStr = found[0][0 .. $ - foundTZ[0].length];
zoneStr = foundTZ[0];
}
else
fracSecStr = found[0];
}
else
zoneStr = found[0];
}
try
{
auto dateTime = DateTime.fromISOExtString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
Rebindable!(immutable TimeZone) parsedZone;
if(zoneStr.empty)
parsedZone = LocalTime();
else if(zoneStr == "Z")
parsedZone = UTC();
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);
auto retval = SysTime(dateTime, fracSec, parsedZone);
if(tz !is null)
retval.timezone = tz;
return retval;
}
catch(DateTimeException dte)
throw new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(SysTime.fromISOExtString(""));
assertThrown!DateTimeException(SysTime.fromISOExtString("20100704000000"));
assertThrown!DateTimeException(SysTime.fromISOExtString("20100704 000000"));
assertThrown!DateTimeException(SysTime.fromISOExtString("20100704t000000"));
assertThrown!DateTimeException(SysTime.fromISOExtString("20100704T000000."));
assertThrown!DateTimeException(SysTime.fromISOExtString("20100704T000000.0"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07:0400:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00.A"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00.Z"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00.00000000"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00.00000000"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00+"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00-"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00:"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00-:"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00+:"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00-1:"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00+1:"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00+1:0"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00-24.00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-07-04T00:00:00+24.00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-Jul-04 00:00:00.0"));
assertThrown!DateTimeException(SysTime.fromISOExtString("20101222T172201"));
assertThrown!DateTimeException(SysTime.fromISOExtString("2010-Dec-22 17:22:01"));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
_assertPred!"=="(SysTime.fromISOExtString("1999-07-06T12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString("-1999-07-06T12:30:33"), SysTime(DateTime(-1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString("+01999-07-06T12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString("1999-07-06T12:30:33 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString(" 1999-07-06T12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString(" 1999-07-06T12:30:33 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.0"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.0000000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.0000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"hnsecs"(1)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.0000010"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromISOExtString("1907-07-07T12:12:12.0010000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), UTC()));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(480))));
_assertPred!"=="(SysTime.fromISOExtString("2010-11-03T06:51:06.57159Z"),
SysTime(DateTime(2010, 11, 3, 6, 51, 6), FracSec.from!"hnsecs"(5715900), UTC()));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.23412Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_341_200), UTC()));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.23112-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_311_200),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.45-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.1-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_000_000),
new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.55-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(5_500_000),
new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.1234567+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_234_567),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.0+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.0000000+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromISOExtString("2010-12-22T17:22:01.45+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(480))));
//Verify Examples.
assert(SysTime.fromISOExtString("2010-07-04T07:06:12") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOExtString("1998-12-25T02:15:00.007") ==
SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromISOExtString("0000-01-05T23:09:59.00002") ==
SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromISOExtString("-0004-01-05T00:00:02") == SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromISOExtString(" 2010-07-04T07:06:12 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
}
}
/++
Creates a $(D SysTime) from a string with the format
YYYY-MM-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds is the
time zone). Whitespace is stripped from the given string.
The exact format is exactly as described in $(D toSimpleString) except
that trailing zeroes are permitted - including having fractional seconds
with all zeroes. However, a decimal point with nothing following it is
invalid.
If there is no time zone in the string, then $(D LocalTime) is used. If
the time zone is "Z", then $(D UTC) is used. Otherwise, a
$(LREF SimpleTimeZone) which corresponds to the given offset from UTC is
used. To get the returned $(D SysTime) to be a particular time
zone, pass in that time zone and the $(D SysTime) to be returned
will be converted to that time zone (though it will still be read in as
whatever time zone is in its string).
The accepted formats for time zone offsets
are +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
Params:
simpleString = A string formatted in the way that
$(D toSimpleString) formats dates and times.
tz = The time zone to convert the given time to (no
conversion occurs if null).
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D SysTime) would not be valid.
Examples:
--------------------
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromSimpleString("1998-Dec-25 02:15:00.007") ==
SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromSimpleString("0000-Jan-05 23:09:59.00002") ==
SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromSimpleString("-0004-Jan-05 00:00:02") ==
SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12Z") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12),
new SimpleTimeZone(dur!"hours"(8))));
--------------------
+/
static SysTime fromSimpleString(S)(in S simpleString, immutable TimeZone tz = null)
if(isSomeString!(S))
{
auto dstr = to!dstring(strip(simpleString));
auto spaceIndex = dstr.stds_indexOf(" ");
enforce(spaceIndex != -1, new DateTimeException(format("Invalid Simple String: %s", simpleString)));
auto found = dstr[spaceIndex + 1 .. $].find(".", "Z", "+", "-");
auto dateTimeStr = dstr[0 .. $ - found[0].length];
dstring fracSecStr;
dstring zoneStr;
if(found[1] != 0)
{
if(found[1] == 1)
{
auto foundTZ = found[0].find("Z", "+", "-");
if(foundTZ[1] != 0)
{
fracSecStr = found[0][0 .. $ - foundTZ[0].length];
zoneStr = foundTZ[0];
}
else
fracSecStr = found[0];
}
else
zoneStr = found[0];
}
try
{
auto dateTime = DateTime.fromSimpleString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
Rebindable!(immutable TimeZone) parsedZone;
if(zoneStr.empty)
parsedZone = LocalTime();
else if(zoneStr == "Z")
parsedZone = UTC();
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);
auto retval = SysTime(dateTime, fracSec, parsedZone);
if(tz !is null)
retval.timezone = tz;
return retval;
}
catch(DateTimeException dte)
throw new DateTimeException(format("Invalid Simple String: %s", simpleString));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(SysTime.fromSimpleString(""));
assertThrown!DateTimeException(SysTime.fromSimpleString("20100704000000"));
assertThrown!DateTimeException(SysTime.fromSimpleString("20100704 000000"));
assertThrown!DateTimeException(SysTime.fromSimpleString("20100704t000000"));
assertThrown!DateTimeException(SysTime.fromSimpleString("20100704T000000."));
assertThrown!DateTimeException(SysTime.fromSimpleString("20100704T000000.0"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-07-0400:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-07-04T00:00:00.0"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04T00:00:00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00.A"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00.Z"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00.00000000"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00.00000000"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00+"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00-"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00:"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00-:"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00+:"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00-1:"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00+1:"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00+1:0"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00-24.00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-Jul-04 00:00:00+24.00"));
assertThrown!DateTimeException(SysTime.fromSimpleString("20101222T172201"));
assertThrown!DateTimeException(SysTime.fromSimpleString("2010-12-22T172201"));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
_assertPred!"=="(SysTime.fromSimpleString("1999-Jul-06 12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString("-1999-Jul-06 12:30:33"), SysTime(DateTime(-1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString("+01999-Jul-06 12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString("1999-Jul-06 12:30:33 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString(" 1999-Jul-06 12:30:33"), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString(" 1999-Jul-06 12:30:33 "), SysTime(DateTime(1999, 7, 6, 12, 30, 33)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.0"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.0000000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.0000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"hnsecs"(1)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.000001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.0000010"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"usecs"(1)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.001"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromSimpleString("1907-Jul-07 12:12:12.0010000"), SysTime(DateTime(1907, 07, 07, 12, 12, 12), FracSec.from!"msecs"(1)));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), UTC()));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), new SimpleTimeZone(dur!"minutes"(480))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Nov-03 06:51:06.57159Z"),
SysTime(DateTime(2010, 11, 3, 6, 51, 6), FracSec.from!"hnsecs"(5715900), UTC()));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.23412Z"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_341_200), UTC()));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.23112-1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(2_311_200),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.45-1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(-60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.1-1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_000_000),
new SimpleTimeZone(dur!"minutes"(-90))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.55-8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(5_500_000),
new SimpleTimeZone(dur!"minutes"(-480))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.1234567+1:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(1_234_567),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.0+1"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(60))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.0000000+1:30"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(0),
new SimpleTimeZone(dur!"minutes"(90))));
_assertPred!"=="(SysTime.fromSimpleString("2010-Dec-22 17:22:01.45+8:00"),
SysTime(DateTime(2010, 12, 22, 17, 22, 01), FracSec.from!"hnsecs"(4_500_000),
new SimpleTimeZone(dur!"minutes"(480))));
//Verify Examples.
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromSimpleString("1998-Dec-25 02:15:00.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7)));
assert(SysTime.fromSimpleString("0000-Jan-05 23:09:59.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20)));
assert(SysTime.fromSimpleString("-0004-Jan-05 00:00:02") == SysTime(DateTime(-4, 1, 5, 0, 0, 2)));
assert(SysTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12)));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12Z") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12-8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8))));
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") ==
SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
}
}
//TODO Add function which takes a user-specified time format and produces a SysTime
//TODO Add function which takes pretty much any time-string and produces a SysTime.
// Obviously, it will be less efficient, and it probably won't manage _every_
// possible date format, but a smart conversion function would be nice.
/++
Returns the $(D SysTime) farthest in the past which is representable
by $(D SysTime).
The $(D SysTime) which is returned is in UTC.
+/
@property static SysTime min() pure nothrow
{
return SysTime(long.min, UTC());
}
unittest
{
version(testStdDateTime)
{
assert(SysTime.min.year < 0);
assert(SysTime.min < SysTime.max);
}
}
/++
Returns the $(D SysTime) farthest in the future which is representable
by $(D SysTime).
The $(D SysTime) which is returned is in UTC.
+/
@property static SysTime max() pure nothrow
{
return SysTime(long.max, UTC());
}
unittest
{
version(testStdDateTime)
{
assert(SysTime.max.year > 0);
assert(SysTime.max > SysTime.min);
}
}
private:
/+
Returns $(D stdTime) converted to $(D SysTime)'s time zone.
+/
@property long adjTime() const nothrow
{
return _timezone.utcToTZ(_stdTime);
}
/+
Converts the given hnsecs from $(D SysTime)'s time zone to std time.
+/
@property void adjTime(long adjTime) nothrow
{
_stdTime = _timezone.tzToUTC(adjTime);
}
//Commented out due to bug http://d.puremagic.com/issues/show_bug.cgi?id=5058
/+
invariant()
{
assert(_timezone !is null, "Invariant Failure: timezone is null. Were you foolish enough to use SysTime.init? (since timezone for SysTime.init can't be set at compile time).");
}
+/
long _stdTime;
Rebindable!(immutable TimeZone) _timezone;
}
/++
Represents a date in the Proleptic Gregorian Calendar ranging from
32,768 B.C. to 32,767 A.D. Positive years are A.D. Non-positive years are
B.C.
Year, month, and day are kept separately internally so that $(D Date) is
optimized for calendar-based operations.
$(D Date) uses the Proleptic Gregorian Calendar, so it assumes the Gregorian
leap year calculations for its entire length. And, as per
$(WEB en.wikipedia.org/wiki/ISO_8601, ISO 8601), it also treats 1 B.C. as
year 0. So, 1 B.C. is 0, 2 B.C. is -1, etc. Use $(D yearBC) if want B.C. as
a positive integer with 1 B.C. being the year prior to 1 A.D.
Year 0 is a leap year.
+/
struct Date
{
public:
/++
Throws:
$(D DateTimeException) if the resulting $(D Date) would not be valid.
Params:
year = Year of the Gregorian Calendar. Positive values are A.D.
Non-positive values are B.C. with year 0 being the year
prior to 1 A.D.
month = Month of the year.
day = Day of the month.
+/
this(int year, int month, int day) pure
{
enforceValid!"months"(cast(Month)month);
enforceValid!"days"(year, cast(Month)month, day);
_year = cast(short)year;
_month = cast(Month)month;
_day = cast(ubyte)day;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date(1, 1, 1), Date.init);
static void testDate(in Date date, int year, int month, int day, size_t line = __LINE__)
{
_assertPred!"=="(date._year, year, "", __FILE__, line);
_assertPred!"=="(date._month, month, "", __FILE__, line);
_assertPred!"=="(date._day, day, "", __FILE__, line);
}
testDate(Date(1999, 1 , 1), 1999, Month.jan, 1);
testDate(Date(1999, 7 , 1), 1999, Month.jul, 1);
testDate(Date(1999, 7 , 6), 1999, Month.jul, 6);
//Test A.D.
assertThrown!DateTimeException(Date(1, 0, 1));
assertThrown!DateTimeException(Date(1, 1, 0));
assertThrown!DateTimeException(Date(1999, 13, 1));
assertThrown!DateTimeException(Date(1999, 1, 32));
assertThrown!DateTimeException(Date(1999, 2, 29));
assertThrown!DateTimeException(Date(2000, 2, 30));
assertThrown!DateTimeException(Date(1999, 3, 32));
assertThrown!DateTimeException(Date(1999, 4, 31));
assertThrown!DateTimeException(Date(1999, 5, 32));
assertThrown!DateTimeException(Date(1999, 6, 31));
assertThrown!DateTimeException(Date(1999, 7, 32));
assertThrown!DateTimeException(Date(1999, 8, 32));
assertThrown!DateTimeException(Date(1999, 9, 31));
assertThrown!DateTimeException(Date(1999, 10, 32));
assertThrown!DateTimeException(Date(1999, 11, 31));
assertThrown!DateTimeException(Date(1999, 12, 32));
assertNotThrown!DateTimeException(Date(1999, 1, 31));
assertNotThrown!DateTimeException(Date(1999, 2, 28));
assertNotThrown!DateTimeException(Date(2000, 2, 29));
assertNotThrown!DateTimeException(Date(1999, 3, 31));
assertNotThrown!DateTimeException(Date(1999, 4, 30));
assertNotThrown!DateTimeException(Date(1999, 5, 31));
assertNotThrown!DateTimeException(Date(1999, 6, 30));
assertNotThrown!DateTimeException(Date(1999, 7, 31));
assertNotThrown!DateTimeException(Date(1999, 8, 31));
assertNotThrown!DateTimeException(Date(1999, 9, 30));
assertNotThrown!DateTimeException(Date(1999, 10, 31));
assertNotThrown!DateTimeException(Date(1999, 11, 30));
assertNotThrown!DateTimeException(Date(1999, 12, 31));
//Test B.C.
assertNotThrown!DateTimeException(Date(0, 1, 1));
assertNotThrown!DateTimeException(Date(-1, 1, 1));
assertNotThrown!DateTimeException(Date(-1, 12, 31));
assertNotThrown!DateTimeException(Date(-1, 2, 28));
assertNotThrown!DateTimeException(Date(-4, 2, 29));
assertThrown!DateTimeException(Date(-1, 2, 29));
assertThrown!DateTimeException(Date(-2, 2, 29));
assertThrown!DateTimeException(Date(-3, 2, 29));
}
}
/++
Params:
day = The Xth day of the Gregorian Calendar that the constructed
$(D Date) will be for.
+/
this(int day) pure nothrow
{
if(day > 0)
{
int years = (day / daysIn400Years) * 400 + 1;
day %= daysIn400Years;
{
immutable tempYears = day / daysIn100Years;
if(tempYears == 4)
{
years += 300;
day -= daysIn100Years * 3;
}
else
{
years += tempYears * 100;
day %= daysIn100Years;
}
}
years += (day / daysIn4Years) * 4;
day %= daysIn4Years;
{
immutable tempYears = day / daysInYear;
if(tempYears == 4)
{
years += 3;
day -= daysInYear * 3;
}
else
{
years += tempYears;
day %= daysInYear;
}
}
if(day == 0)
{
_year = cast(short)(years - 1);
_month = Month.dec;
_day = 31;
}
else
{
_year = cast(short)years;
try
dayOfYear = day;
catch(Exception e)
assert(0, "dayOfYear assignment threw.");
}
}
else if(day <= 0 && -day < daysInLeapYear)
{
_year = 0;
try
dayOfYear = (daysInLeapYear + day);
catch(Exception e)
assert(0, "dayOfYear assignment threw.");
}
else
{
day += daysInLeapYear - 1;
int years = (day / daysIn400Years) * 400 - 1;
day %= daysIn400Years;
{
immutable tempYears = day / daysIn100Years;
if(tempYears == -4)
{
years -= 300;
day += daysIn100Years * 3;
}
else
{
years += tempYears * 100;
day %= daysIn100Years;
}
}
years += (day / daysIn4Years) * 4;
day %= daysIn4Years;
{
immutable tempYears = day / daysInYear;
if(tempYears == -4)
{
years -= 3;
day += daysInYear * 3;
}
else
{
years += tempYears;
day %= daysInYear;
}
}
if(day == 0)
{
_year = cast(short)(years + 1);
_month = Month.jan;
_day = 1;
}
else
{
_year = cast(short)years;
immutable newDoY = (yearIsLeapYear(_year) ? daysInLeapYear : daysInYear) + day + 1;
try
dayOfYear = newDoY;
catch(Exception e)
assert(0, "dayOfYear assignment threw.");
}
}
}
version(testStdDateTime) unittest
{
//Test A.D.
foreach(gd; chain(testGregDaysBC, testGregDaysAD))
_assertPred!"=="(Date(gd.day), gd.date);
}
/++
Compares this $(D Date) with the given $(D Date).
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
+/
int opCmp(in Date rhs) const pure nothrow
{
if(_year < rhs._year)
return -1;
if(_year > rhs._year)
return 1;
if(_month < rhs._month)
return -1;
if(_month > rhs._month)
return 1;
if(_day < rhs._day)
return -1;
if(_day > rhs._day)
return 1;
return 0;
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!("opCmp", "==")(Date(1, 1, 1), Date.init);
_assertPred!("opCmp", "==")(Date(1999, 1, 1), Date(1999, 1, 1));
_assertPred!("opCmp", "==")(Date(1, 7, 1), Date(1, 7, 1));
_assertPred!("opCmp", "==")(Date(1, 1, 6), Date(1, 1, 6));
_assertPred!("opCmp", "==")(Date(1999, 7, 1), Date(1999, 7, 1));
_assertPred!("opCmp", "==")(Date(1999, 7, 6), Date(1999, 7, 6));
_assertPred!("opCmp", "==")(Date(1, 7, 6), Date(1, 7, 6));
_assertPred!("opCmp", "<")(Date(1999, 7, 6), Date(2000, 7, 6));
_assertPred!("opCmp", ">")(Date(2000, 7, 6), Date(1999, 7, 6));
_assertPred!("opCmp", "<")(Date(1999, 7, 6), Date(1999, 8, 6));
_assertPred!("opCmp", ">")(Date(1999, 8, 6), Date(1999, 7, 6));
_assertPred!("opCmp", "<")(Date(1999, 7, 6), Date(1999, 7, 7));
_assertPred!("opCmp", ">")(Date(1999, 7, 7), Date(1999, 7, 6));
_assertPred!("opCmp", "<")(Date(1999, 8, 7), Date(2000, 7, 6));
_assertPred!("opCmp", ">")(Date(2000, 8, 6), Date(1999, 7, 7));
_assertPred!("opCmp", "<")(Date(1999, 7, 7), Date(2000, 7, 6));
_assertPred!("opCmp", ">")(Date(2000, 7, 6), Date(1999, 7, 7));
_assertPred!("opCmp", "<")(Date(1999, 7, 7), Date(1999, 8, 6));
_assertPred!("opCmp", ">")(Date(1999, 8, 6), Date(1999, 7, 7));
//Test B.C.
_assertPred!("opCmp", "==")(Date(0, 1, 1), Date(0, 1, 1));
_assertPred!("opCmp", "==")(Date(-1, 1, 1), Date(-1, 1, 1));
_assertPred!("opCmp", "==")(Date(-1, 7, 1), Date(-1, 7, 1));
_assertPred!("opCmp", "==")(Date(-1, 1, 6), Date(-1, 1, 6));
_assertPred!("opCmp", "==")(Date(-1999, 7, 1), Date(-1999, 7, 1));
_assertPred!("opCmp", "==")(Date(-1999, 7, 6), Date(-1999, 7, 6));
_assertPred!("opCmp", "==")(Date(-1, 7, 6), Date(-1, 7, 6));
_assertPred!("opCmp", "<")(Date(-2000, 7, 6), Date(-1999, 7, 6));
_assertPred!("opCmp", ">")(Date(-1999, 7, 6), Date(-2000, 7, 6));
_assertPred!("opCmp", "<")(Date(-1999, 7, 6), Date(-1999, 8, 6));
_assertPred!("opCmp", ">")(Date(-1999, 8, 6), Date(-1999, 7, 6));
_assertPred!("opCmp", "<")(Date(-1999, 7, 6), Date(-1999, 7, 7));
_assertPred!("opCmp", ">")(Date(-1999, 7, 7), Date(-1999, 7, 6));
_assertPred!("opCmp", "<")(Date(-2000, 8, 6), Date(-1999, 7, 7));
_assertPred!("opCmp", ">")(Date(-1999, 8, 7), Date(-2000, 7, 6));
_assertPred!("opCmp", "<")(Date(-2000, 7, 6), Date(-1999, 7, 7));
_assertPred!("opCmp", ">")(Date(-1999, 7, 7), Date(-2000, 7, 6));
_assertPred!("opCmp", "<")(Date(-1999, 7, 7), Date(-1999, 8, 6));
_assertPred!("opCmp", ">")(Date(-1999, 8, 6), Date(-1999, 7, 7));
//Test Both
_assertPred!("opCmp", "<")(Date(-1999, 7, 6), Date(1999, 7, 6));
_assertPred!("opCmp", ">")(Date(1999, 7, 6), Date(-1999, 7, 6));
_assertPred!("opCmp", "<")(Date(-1999, 8, 6), Date(1999, 7, 6));
_assertPred!("opCmp", ">")(Date(1999, 7, 6), Date(-1999, 8, 6));
_assertPred!("opCmp", "<")(Date(-1999, 7, 7), Date(1999, 7, 6));
_assertPred!("opCmp", ">")(Date(1999, 7, 6), Date(-1999, 7, 7));
_assertPred!("opCmp", "<")(Date(-1999, 8, 7), Date(1999, 7, 6));
_assertPred!("opCmp", ">")(Date(1999, 7, 6), Date(-1999, 8, 7));
_assertPred!("opCmp", "<")(Date(-1999, 8, 6), Date(1999, 6, 6));
_assertPred!("opCmp", ">")(Date(1999, 6, 8), Date(-1999, 7, 6));
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date.opCmp(date)));
static assert(__traits(compiles, date.opCmp(cdate)));
static assert(__traits(compiles, date.opCmp(idate)));
static assert(__traits(compiles, cdate.opCmp(date)));
static assert(__traits(compiles, cdate.opCmp(cdate)));
static assert(__traits(compiles, cdate.opCmp(idate)));
static assert(__traits(compiles, idate.opCmp(date)));
static assert(__traits(compiles, idate.opCmp(cdate)));
static assert(__traits(compiles, idate.opCmp(idate)));
}
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Examples:
--------------------
assert(Date(1999, 7, 6).year == 1999);
assert(Date(2010, 10, 4).year == 2010);
assert(Date(-7, 4, 5).year == -7);
--------------------
+/
@property short year() const pure nothrow
{
return _year;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date.init.year, 1);
_assertPred!"=="(Date(1999, 7, 6).year, 1999);
_assertPred!"=="(Date(-1999, 7, 6).year, -1999);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.year == 1999));
static assert(__traits(compiles, idate.year == 1999));
//Verify Examples.
assert(Date(1999, 7, 6).year == 1999);
assert(Date(2010, 10, 4).year == 2010);
assert(Date(-7, 4, 5).year == -7);
}
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Params:
year = The year to set this Date's year to.
Throws:
$(D DateTimeException) if the new year is not a leap year and the
resulting date would be on February 29th.
+/
@property void year(int year) pure
{
enforceValid!"days"(year, _month, _day);
_year = cast(short)year;
}
unittest
{
version(testStdDateTime)
{
static void testDateInvalid(Date date, int year)
{
date.year = year;
}
static void testDate(Date date, int year, in Date expected, size_t line = __LINE__)
{
date.year = year;
_assertPred!"=="(date, expected, "", __FILE__, line);
}
assertThrown!DateTimeException(testDateInvalid(Date(4, 2, 29), 1));
testDate(Date(1, 1, 1), 1999, Date(1999, 1, 1));
testDate(Date(1, 1, 1), 0, Date(0, 1, 1));
testDate(Date(1, 1, 1), -1999, Date(-1999, 1, 1));
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.year = 1999));
static assert(!__traits(compiles, idate.year = 1999));
//Verify Examples.
assert(Date(1999, 7, 6).year == 1999);
assert(Date(2010, 10, 4).year == 2010);
assert(Date(-7, 4, 5).year == -7);
}
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Throws:
$(D DateTimeException) if $(D isAD) is true.
Examples:
--------------------
assert(Date(0, 1, 1).yearBC == 1);
assert(Date(-1, 1, 1).yearBC == 2);
assert(Date(-100, 1, 1).yearBC == 101);
--------------------
+/
@property ushort yearBC() const pure
{
if(isAD)
throw new DateTimeException("Year " ~ numToString(_year) ~ " is A.D.");
//Once format is pure, this would be a better error message.
//throw new DateTimeException(format("%s is A.D.", this));
return cast(ushort)((_year * -1) + 1);
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((in Date date){date.yearBC;}(Date(1, 1, 1)));
auto date = Date(0, 7, 6);
const cdate = Date(0, 7, 6);
immutable idate = Date(0, 7, 6);
static assert(__traits(compiles, date.yearBC));
static assert(__traits(compiles, cdate.yearBC));
static assert(__traits(compiles, idate.yearBC));
//Verify Examples.
assert(Date(0, 1, 1).yearBC == 1);
assert(Date(-1, 1, 1).yearBC == 2);
assert(Date(-100, 1, 1).yearBC == 101);
}
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Params:
year = The year B.C. to set this $(D Date)'s year to.
Throws:
$(D DateTimeException) if a non-positive value is given.
Examples:
--------------------
auto date = Date(2010, 1, 1);
date.yearBC = 1;
assert(date == Date(0, 1, 1));
date.yearBC = 10;
assert(date == Date(-9, 1, 1));
--------------------
+/
@property void yearBC(int year) pure
{
if(year <= 0)
throw new DateTimeException("The given year is not a year B.C.");
_year = cast(short)((year - 1) * -1);
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((Date date){date.yearBC = -1;}(Date(1, 1, 1)));
{
auto date = Date(0, 7, 6);
const cdate = Date(0, 7, 6);
immutable idate = Date(0, 7, 6);
static assert(__traits(compiles, date.yearBC = 7));
static assert(!__traits(compiles, cdate.yearBC = 7));
static assert(!__traits(compiles, idate.yearBC = 7));
}
//Verify Examples.
{
auto date = Date(2010, 1, 1);
date.yearBC = 1;
assert(date == Date(0, 1, 1));
date.yearBC = 10;
assert(date == Date(-9, 1, 1));
}
}
}
/++
Month of a Gregorian Year.
Examples:
--------------------
assert(Date(1999, 7, 6).month == 7);
assert(Date(2010, 10, 4).month == 10);
assert(Date(-7, 4, 5).month == 4);
--------------------
+/
@property Month month() const pure nothrow
{
return _month;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date.init.month, 1);
_assertPred!"=="(Date(1999, 7, 6).month, 7);
_assertPred!"=="(Date(-1999, 7, 6).month, 7);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.month == 7));
static assert(__traits(compiles, idate.month == 7));
//Verify Examples.
assert(Date(1999, 7, 6).month == 7);
assert(Date(2010, 10, 4).month == 10);
assert(Date(-7, 4, 5).month == 4);
}
}
/++
Month of a Gregorian Year.
Params:
month = The month to set this $(D Date)'s month to.
Throws:
$(D DateTimeException) if the given month is not a valid month or if
the current day would not be valid in the given month.
+/
@property void month(Month month) pure
{
enforceValid!"months"(month);
enforceValid!"days"(_year, month, _day);
_month = cast(Month)month;
}
unittest
{
version(testStdDateTime)
{
static void testDate(Date date, Month month, in Date expected = Date.init, size_t line = __LINE__)
{
date.month = month;
assert(expected != Date.init);
_assertPred!"=="(date, expected, "", __FILE__, line);
}
assertThrown!DateTimeException(testDate(Date(1, 1, 1), cast(Month)0));
assertThrown!DateTimeException(testDate(Date(1, 1, 1), cast(Month)13));
assertThrown!DateTimeException(testDate(Date(1, 1, 29), cast(Month)2));
assertThrown!DateTimeException(testDate(Date(0, 1, 30), cast(Month)2));
testDate(Date(1, 1, 1), cast(Month)7, Date(1, 7, 1));
testDate(Date(-1, 1, 1), cast(Month)7, Date(-1, 7, 1));
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.month = 7));
static assert(!__traits(compiles, idate.month = 7));
}
}
/++
Day of a Gregorian Month.
Examples:
--------------------
assert(Date(1999, 7, 6).day == 6);
assert(Date(2010, 10, 4).day == 4);
assert(Date(-7, 4, 5).day == 5);
--------------------
+/
@property ubyte day() const pure nothrow
{
return _day;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(Date(1999, 7, 6).day == 6);
assert(Date(2010, 10, 4).day == 4);
assert(Date(-7, 4, 5).day == 5);
}
version(testStdDateTime) unittest
{
static void test(Date date, int expected, size_t line = __LINE__)
{
_assertPred!"=="(date.day, expected,
format("Value given: %s", date), __FILE__, line);
}
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
test(Date(year, md.month, md.day), md.day);
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.day == 6));
static assert(__traits(compiles, idate.day == 6));
}
/++
Day of a Gregorian Month.
Params:
day = The day of the month to set this $(D Date)'s day to.
Throws:
$(D DateTimeException) if the given day is not a valid day of the
current month.
+/
@property void day(int day) pure
{
enforceValid!"days"(_year, _month, day);
_day = cast(ubyte)day;
}
unittest
{
version(testStdDateTime)
{
static void testDate(Date date, int day)
{
date.day = day;
}
//Test A.D.
assertThrown!DateTimeException(testDate(Date(1, 1, 1), 0));
assertThrown!DateTimeException(testDate(Date(1, 1, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 2, 1), 29));
assertThrown!DateTimeException(testDate(Date(4, 2, 1), 30));
assertThrown!DateTimeException(testDate(Date(1, 3, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 4, 1), 31));
assertThrown!DateTimeException(testDate(Date(1, 5, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 6, 1), 31));
assertThrown!DateTimeException(testDate(Date(1, 7, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 8, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 9, 1), 31));
assertThrown!DateTimeException(testDate(Date(1, 10, 1), 32));
assertThrown!DateTimeException(testDate(Date(1, 11, 1), 31));
assertThrown!DateTimeException(testDate(Date(1, 12, 1), 32));
assertNotThrown!DateTimeException(testDate(Date(1, 1, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 2, 1), 28));
assertNotThrown!DateTimeException(testDate(Date(4, 2, 1), 29));
assertNotThrown!DateTimeException(testDate(Date(1, 3, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 4, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(1, 5, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 6, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(1, 7, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 8, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 9, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(1, 10, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(1, 11, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(1, 12, 1), 31));
{
auto date = Date(1, 1, 1);
date.day = 6;
_assertPred!"=="(date, Date(1, 1, 6));
}
//Test B.C.
assertThrown!DateTimeException(testDate(Date(-1, 1, 1), 0));
assertThrown!DateTimeException(testDate(Date(-1, 1, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 2, 1), 29));
assertThrown!DateTimeException(testDate(Date(0, 2, 1), 30));
assertThrown!DateTimeException(testDate(Date(-1, 3, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 4, 1), 31));
assertThrown!DateTimeException(testDate(Date(-1, 5, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 6, 1), 31));
assertThrown!DateTimeException(testDate(Date(-1, 7, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 8, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 9, 1), 31));
assertThrown!DateTimeException(testDate(Date(-1, 10, 1), 32));
assertThrown!DateTimeException(testDate(Date(-1, 11, 1), 31));
assertThrown!DateTimeException(testDate(Date(-1, 12, 1), 32));
assertNotThrown!DateTimeException(testDate(Date(-1, 1, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 2, 1), 28));
assertNotThrown!DateTimeException(testDate(Date(0, 2, 1), 29));
assertNotThrown!DateTimeException(testDate(Date(-1, 3, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 4, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(-1, 5, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 6, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(-1, 7, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 8, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 9, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(-1, 10, 1), 31));
assertNotThrown!DateTimeException(testDate(Date(-1, 11, 1), 30));
assertNotThrown!DateTimeException(testDate(Date(-1, 12, 1), 31));
{
auto date = Date(-1, 1, 1);
date.day = 6;
_assertPred!"=="(date, Date(-1, 1, 6));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.day = 6));
static assert(!__traits(compiles, idate.day = 6));
}
}
/++
Adds the given number of years or months to this $(D Date). A negative
number will subtract.
Note that if day overflow is allowed, and the date with the adjusted
year/month overflows the number of days in the new month, then the month
will be incremented by one, and the day set to the number of days
overflowed. (e.g. if the day were 31 and the new month were June, then
the month would be incremented to July, and the new day would be 1). If
day overflow is not allowed, then the day will be set to the last valid
day in the month (e.g. June 31st would become June 30th).
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D Date).
allowOverflow = Whether the day should be allowed to overflow,
causing the month to increment.
Examples:
--------------------
auto d1 = Date(2010, 1, 1);
d1.add!"months"(11);
assert(d1 == Date(2010, 12, 1));
auto d2 = Date(2010, 1, 1);
d2.add!"months"(-11);
assert(d2 == Date(2009, 2, 1));
auto d3 = Date(2000, 2, 29);
d3.add!"years"(1);
assert(d3 == Date(2001, 3, 1));
auto d4 = Date(2000, 2, 29);
d4.add!"years"(1, AllowDayOverflow.no);
assert(d4 == Date(2001, 2, 28));
--------------------
+/
/+ref Date+/ void add(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "years")
{
immutable newYear = _year + value;
_year += value;
if(_month == Month.feb && _day == 29 && !yearIsLeapYear(_year))
{
if(allowOverflow == AllowDayOverflow.yes)
{
_month = Month.mar;
_day = 1;
}
else
_day = 28;
}
}
//Verify Examples.
unittest
{
version(stdStdDateTime)
{
auto d1 = Date(2010, 1, 1);
d1.add!"months"(11);
assert(d1 == Date(2010, 12, 1));
auto d2 = Date(2010, 1, 1);
d2.add!"months"(-11);
assert(d2 == Date(2009, 2, 1));
auto d3 = Date(2000, 2, 29);
d3.add!"years"(1);
assert(d3 == Date(2001, 3, 1));
auto d4 = Date(2000, 2, 29);
d4.add!"years"(1, AllowDayOverflow.no);
assert(d4 == Date(2001, 2, 28));
}
}
//Test add!"years"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.add!"years"(7);
_assertPred!"=="(date, Date(2006, 7, 6));
date.add!"years"(-9);
_assertPred!"=="(date, Date(1997, 7, 6));
}
{
auto date = Date(1999, 2, 28);
date.add!"years"(1);
_assertPred!"=="(date, Date(2000, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.add!"years"(-1);
_assertPred!"=="(date, Date(1999, 3, 1));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.add!"years"(-7);
_assertPred!"=="(date, Date(-2006, 7, 6));
date.add!"years"(9);
_assertPred!"=="(date, Date(-1997, 7, 6));
}
{
auto date = Date(-1999, 2, 28);
date.add!"years"(-1);
_assertPred!"=="(date, Date(-2000, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.add!"years"(1);
_assertPred!"=="(date, Date(-1999, 3, 1));
}
//Test Both
{
auto date = Date(4, 7, 6);
date.add!"years"(-5);
_assertPred!"=="(date, Date(-1, 7, 6));
date.add!"years"(5);
_assertPred!"=="(date, Date(4, 7, 6));
}
{
auto date = Date(-4, 7, 6);
date.add!"years"(5);
_assertPred!"=="(date, Date(1, 7, 6));
date.add!"years"(-5);
_assertPred!"=="(date, Date(-4, 7, 6));
}
{
auto date = Date(4, 7, 6);
date.add!"years"(-8);
_assertPred!"=="(date, Date(-4, 7, 6));
date.add!"years"(8);
_assertPred!"=="(date, Date(4, 7, 6));
}
{
auto date = Date(-4, 7, 6);
date.add!"years"(8);
_assertPred!"=="(date, Date(4, 7, 6));
date.add!"years"(-8);
_assertPred!"=="(date, Date(-4, 7, 6));
}
{
auto date = Date(-4, 2, 29);
date.add!"years"(5);
_assertPred!"=="(date, Date(1, 3, 1));
}
{
auto date = Date(4, 2, 29);
date.add!"years"(-5);
_assertPred!"=="(date, Date(-1, 3, 1));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.add!"years"(7)));
static assert(!__traits(compiles, idate.add!"years"(7)));
}
}
//Test add!"years"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.add!"years"(7, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2006, 7, 6));
date.add!"years"(-9, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 7, 6));
}
{
auto date = Date(1999, 2, 28);
date.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2000, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 2, 28));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.add!"years"(-7, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2006, 7, 6));
date.add!"years"(9, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 7, 6));
}
{
auto date = Date(-1999, 2, 28);
date.add!"years"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2000, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.add!"years"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 2, 28));
}
//Test Both
{
auto date = Date(4, 7, 6);
date.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1, 7, 6));
date.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 7, 6));
}
{
auto date = Date(-4, 7, 6);
date.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1, 7, 6));
date.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 7, 6));
}
{
auto date = Date(4, 7, 6);
date.add!"years"(-8, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 7, 6));
date.add!"years"(8, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 7, 6));
}
{
auto date = Date(-4, 7, 6);
date.add!"years"(8, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 7, 6));
date.add!"years"(-8, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 7, 6));
}
{
auto date = Date(-4, 2, 29);
date.add!"years"(5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1, 2, 28));
}
{
auto date = Date(4, 2, 29);
date.add!"years"(-5, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1, 2, 28));
}
}
}
//Shares documentation with "years" version.
/+ref Date+/ void add(string units)(long months, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "months")
{
auto years = months / 12;
months %= 12;
auto newMonth = _month + months;
if(months < 0)
{
if(newMonth < 1)
{
newMonth += 12;
--years;
}
}
else if(newMonth > 12)
{
newMonth -= 12;
++years;
}
_year += years;
_month = cast(Month)newMonth;
immutable currMaxDay = maxDay(_year, _month);
immutable overflow = _day - currMaxDay;
if(overflow > 0)
{
if(allowOverflow == AllowDayOverflow.yes)
{
++_month;
_day = cast(ubyte)overflow;
}
else
_day = cast(ubyte)currMaxDay;
}
}
//Test add!"months"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.add!"months"(3);
_assertPred!"=="(date, Date(1999, 10, 6));
date.add!"months"(-4);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 7, 6);
date.add!"months"(6);
_assertPred!"=="(date, Date(2000, 1, 6));
date.add!"months"(-6);
_assertPred!"=="(date, Date(1999, 7, 6));
}
{
auto date = Date(1999, 7, 6);
date.add!"months"(27);
_assertPred!"=="(date, Date(2001, 10, 6));
date.add!"months"(-28);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 5, 31);
date.add!"months"(1);
_assertPred!"=="(date, Date(1999, 7, 1));
}
{
auto date = Date(1999, 5, 31);
date.add!"months"(-1);
_assertPred!"=="(date, Date(1999, 5, 1));
}
{
auto date = Date(1999, 2, 28);
date.add!"months"(12);
_assertPred!"=="(date, Date(2000, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.add!"months"(12);
_assertPred!"=="(date, Date(2001, 3, 1));
}
{
auto date = Date(1999, 7, 31);
date.add!"months"(1);
_assertPred!"=="(date, Date(1999, 8, 31));
date.add!"months"(1);
_assertPred!"=="(date, Date(1999, 10, 1));
}
{
auto date = Date(1998, 8, 31);
date.add!"months"(13);
_assertPred!"=="(date, Date(1999, 10, 1));
date.add!"months"(-13);
_assertPred!"=="(date, Date(1998, 9, 1));
}
{
auto date = Date(1997, 12, 31);
date.add!"months"(13);
_assertPred!"=="(date, Date(1999, 1, 31));
date.add!"months"(-13);
_assertPred!"=="(date, Date(1997, 12, 31));
}
{
auto date = Date(1997, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(1999, 3, 3));
date.add!"months"(-14);
_assertPred!"=="(date, Date(1998, 1, 3));
}
{
auto date = Date(1998, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(2000, 3, 2));
date.add!"months"(-14);
_assertPred!"=="(date, Date(1999, 1, 2));
}
{
auto date = Date(1999, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(2001, 3, 3));
date.add!"months"(-14);
_assertPred!"=="(date, Date(2000, 1, 3));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.add!"months"(3);
_assertPred!"=="(date, Date(-1999, 10, 6));
date.add!"months"(-4);
_assertPred!"=="(date, Date(-1999, 6, 6));
}
{
auto date = Date(-1999, 7, 6);
date.add!"months"(6);
_assertPred!"=="(date, Date(-1998, 1, 6));
date.add!"months"(-6);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
{
auto date = Date(-1999, 7, 6);
date.add!"months"(-27);
_assertPred!"=="(date, Date(-2001, 4, 6));
date.add!"months"(28);
_assertPred!"=="(date, Date(-1999, 8, 6));
}
{
auto date = Date(-1999, 5, 31);
date.add!"months"(1);
_assertPred!"=="(date, Date(-1999, 7, 1));
}
{
auto date = Date(-1999, 5, 31);
date.add!"months"(-1);
_assertPred!"=="(date, Date(-1999, 5, 1));
}
{
auto date = Date(-1999, 2, 28);
date.add!"months"(-12);
_assertPred!"=="(date, Date(-2000, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.add!"months"(-12);
_assertPred!"=="(date, Date(-2001, 3, 1));
}
{
auto date = Date(-1999, 7, 31);
date.add!"months"(1);
_assertPred!"=="(date, Date(-1999, 8, 31));
date.add!"months"(1);
_assertPred!"=="(date, Date(-1999, 10, 1));
}
{
auto date = Date(-1998, 8, 31);
date.add!"months"(13);
_assertPred!"=="(date, Date(-1997, 10, 1));
date.add!"months"(-13);
_assertPred!"=="(date, Date(-1998, 9, 1));
}
{
auto date = Date(-1997, 12, 31);
date.add!"months"(13);
_assertPred!"=="(date, Date(-1995, 1, 31));
date.add!"months"(-13);
_assertPred!"=="(date, Date(-1997, 12, 31));
}
{
auto date = Date(-1997, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(-1995, 3, 3));
date.add!"months"(-14);
_assertPred!"=="(date, Date(-1996, 1, 3));
}
{
auto date = Date(-2002, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(-2000, 3, 2));
date.add!"months"(-14);
_assertPred!"=="(date, Date(-2001, 1, 2));
}
{
auto date = Date(-2001, 12, 31);
date.add!"months"(14);
_assertPred!"=="(date, Date(-1999, 3, 3));
date.add!"months"(-14);
_assertPred!"=="(date, Date(-2000, 1, 3));
}
//Test Both
{
auto date = Date(1, 1, 1);
date.add!"months"(-1);
_assertPred!"=="(date, Date(0, 12, 1));
date.add!"months"(1);
_assertPred!"=="(date, Date(1, 1, 1));
}
{
auto date = Date(4, 1, 1);
date.add!"months"(-48);
_assertPred!"=="(date, Date(0, 1, 1));
date.add!"months"(48);
_assertPred!"=="(date, Date(4, 1, 1));
}
{
auto date = Date(4, 3, 31);
date.add!"months"(-49);
_assertPred!"=="(date, Date(0, 3, 2));
date.add!"months"(49);
_assertPred!"=="(date, Date(4, 4, 2));
}
{
auto date = Date(4, 3, 31);
date.add!"months"(-85);
_assertPred!"=="(date, Date(-3, 3, 3));
date.add!"months"(85);
_assertPred!"=="(date, Date(4, 4, 3));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.add!"months"(3)));
static assert(!__traits(compiles, idate.add!"months"(3)));
}
}
//Test add!"months"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 10, 6));
date.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 7, 6);
date.add!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2000, 1, 6));
date.add!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 7, 6));
}
{
auto date = Date(1999, 7, 6);
date.add!"months"(27, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2001, 10, 6));
date.add!"months"(-28, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 5, 31);
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 30));
}
{
auto date = Date(1999, 5, 31);
date.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 4, 30));
}
{
auto date = Date(1999, 2, 28);
date.add!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2000, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.add!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2001, 2, 28));
}
{
auto date = Date(1999, 7, 31);
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 8, 31));
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 9, 30));
}
{
auto date = Date(1998, 8, 31);
date.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 9, 30));
date.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 8, 30));
}
{
auto date = Date(1997, 12, 31);
date.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 1, 31));
date.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 12, 31));
}
{
auto date = Date(1997, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 2, 28));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 12, 28));
}
{
auto date = Date(1998, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2000, 2, 29));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 12, 29));
}
{
auto date = Date(1999, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2001, 2, 28));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 12, 28));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.add!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 10, 6));
date.add!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 6, 6));
}
{
auto date = Date(-1999, 7, 6);
date.add!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1998, 1, 6));
date.add!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
{
auto date = Date(-1999, 7, 6);
date.add!"months"(-27, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2001, 4, 6));
date.add!"months"(28, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 8, 6));
}
{
auto date = Date(-1999, 5, 31);
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 6, 30));
}
{
auto date = Date(-1999, 5, 31);
date.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 4, 30));
}
{
auto date = Date(-1999, 2, 28);
date.add!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2000, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.add!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2001, 2, 28));
}
{
auto date = Date(-1999, 7, 31);
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 8, 31));
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 9, 30));
}
{
auto date = Date(-1998, 8, 31);
date.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 9, 30));
date.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1998, 8, 30));
}
{
auto date = Date(-1997, 12, 31);
date.add!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1995, 1, 31));
date.add!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 12, 31));
}
{
auto date = Date(-1997, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1995, 2, 28));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 12, 28));
}
{
auto date = Date(-2002, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2000, 2, 29));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2002, 12, 29));
}
{
auto date = Date(-2001, 12, 31);
date.add!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 2, 28));
date.add!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2001, 12, 28));
}
//Test Both
{
auto date = Date(1, 1, 1);
date.add!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(0, 12, 1));
date.add!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1, 1, 1));
}
{
auto date = Date(4, 1, 1);
date.add!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(0, 1, 1));
date.add!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 1, 1));
}
{
auto date = Date(4, 3, 31);
date.add!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(0, 2, 29));
date.add!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 3, 29));
}
{
auto date = Date(4, 3, 31);
date.add!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-3, 2, 28));
date.add!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 3, 28));
}
}
}
/++
Adds the given number of years or months to this $(D Date). A negative
number will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. Rolling a $(D Date) 12 months gets
the exact same $(D Date). However, the days can still be affected due to
the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D Date).
Examples:
--------------------
auto d1 = Date(2010, 1, 1);
d1.roll!"months"(1);
assert(d1 == Date(2010, 2, 1));
auto d2 = Date(2010, 1, 1);
d2.roll!"months"(-1);
assert(d2 == Date(2010, 12, 1));
auto d3 = Date(1999, 1, 29);
d3.roll!"months"(1);
assert(d3 == Date(1999, 3, 1));
auto d4 = Date(1999, 1, 29);
d4.roll!"months"(1, AllowDayOverflow.no);
assert(d4 == Date(1999, 2, 28));
auto d5 = Date(2000, 2, 29);
d5.roll!"years"(1);
assert(d5 == Date(2001, 3, 1));
auto d6 = Date(2000, 2, 29);
d6.roll!"years"(1, AllowDayOverflow.no);
assert(d6 == Date(2001, 2, 28));
--------------------
+/
/+ref Date+/ void roll(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "years")
{
add!"years"(value, allowOverflow);
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto d1 = Date(2010, 1, 1);
d1.roll!"months"(1);
assert(d1 == Date(2010, 2, 1));
auto d2 = Date(2010, 1, 1);
d2.roll!"months"(-1);
assert(d2 == Date(2010, 12, 1));
auto d3 = Date(1999, 1, 29);
d3.roll!"months"(1);
assert(d3 == Date(1999, 3, 1));
auto d4 = Date(1999, 1, 29);
d4.roll!"months"(1, AllowDayOverflow.no);
assert(d4 == Date(1999, 2, 28));
auto d5 = Date(2000, 2, 29);
d5.roll!"years"(1);
assert(d5 == Date(2001, 3, 1));
auto d6 = Date(2000, 2, 29);
d6.roll!"years"(1, AllowDayOverflow.no);
assert(d6 == Date(2001, 2, 28));
}
}
unittest
{
version(testStdDateTime)
{
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.roll!"years"(3)));
static assert(!__traits(compiles, idate.rolYears(3)));
}
}
//Shares documentation with "years" version.
/+ref Date+/ void roll(string units)(long months, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "months")
{
months %= 12;
auto newMonth = _month + months;
if(months < 0)
{
if(newMonth < 1)
newMonth += 12;
}
else
{
if(newMonth > 12)
newMonth -= 12;
}
_month = cast(Month)newMonth;
immutable currMaxDay = maxDay(_year, _month);
immutable overflow = _day - currMaxDay;
if(overflow > 0)
{
if(allowOverflow == AllowDayOverflow.yes)
{
++_month;
_day = cast(ubyte)overflow;
}
else
_day = cast(ubyte)currMaxDay;
}
}
//Test roll!"months"() with AllowDayOverlow.yes
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.roll!"months"(3);
_assertPred!"=="(date, Date(1999, 10, 6));
date.roll!"months"(-4);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 7, 6);
date.roll!"months"(6);
_assertPred!"=="(date, Date(1999, 1, 6));
date.roll!"months"(-6);
_assertPred!"=="(date, Date(1999, 7, 6));
}
{
auto date = Date(1999, 7, 6);
date.roll!"months"(27);
_assertPred!"=="(date, Date(1999, 10, 6));
date.roll!"months"(-28);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 5, 31);
date.roll!"months"(1);
_assertPred!"=="(date, Date(1999, 7, 1));
}
{
auto date = Date(1999, 5, 31);
date.roll!"months"(-1);
_assertPred!"=="(date, Date(1999, 5, 1));
}
{
auto date = Date(1999, 2, 28);
date.roll!"months"(12);
_assertPred!"=="(date, Date(1999, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.roll!"months"(12);
_assertPred!"=="(date, Date(2000, 2, 29));
}
{
auto date = Date(1999, 7, 31);
date.roll!"months"(1);
_assertPred!"=="(date, Date(1999, 8, 31));
date.roll!"months"(1);
_assertPred!"=="(date, Date(1999, 10, 1));
}
{
auto date = Date(1998, 8, 31);
date.roll!"months"(13);
_assertPred!"=="(date, Date(1998, 10, 1));
date.roll!"months"(-13);
_assertPred!"=="(date, Date(1998, 9, 1));
}
{
auto date = Date(1997, 12, 31);
date.roll!"months"(13);
_assertPred!"=="(date, Date(1997, 1, 31));
date.roll!"months"(-13);
_assertPred!"=="(date, Date(1997, 12, 31));
}
{
auto date = Date(1997, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(1997, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(1997, 1, 3));
}
{
auto date = Date(1998, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(1998, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(1998, 1, 3));
}
{
auto date = Date(1999, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(1999, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(1999, 1, 3));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(3);
_assertPred!"=="(date, Date(-1999, 10, 6));
date.roll!"months"(-4);
_assertPred!"=="(date, Date(-1999, 6, 6));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(6);
_assertPred!"=="(date, Date(-1999, 1, 6));
date.roll!"months"(-6);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(-27);
_assertPred!"=="(date, Date(-1999, 4, 6));
date.roll!"months"(28);
_assertPred!"=="(date, Date(-1999, 8, 6));
}
{
auto date = Date(-1999, 5, 31);
date.roll!"months"(1);
_assertPred!"=="(date, Date(-1999, 7, 1));
}
{
auto date = Date(-1999, 5, 31);
date.roll!"months"(-1);
_assertPred!"=="(date, Date(-1999, 5, 1));
}
{
auto date = Date(-1999, 2, 28);
date.roll!"months"(-12);
_assertPred!"=="(date, Date(-1999, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.roll!"months"(-12);
_assertPred!"=="(date, Date(-2000, 2, 29));
}
{
auto date = Date(-1999, 7, 31);
date.roll!"months"(1);
_assertPred!"=="(date, Date(-1999, 8, 31));
date.roll!"months"(1);
_assertPred!"=="(date, Date(-1999, 10, 1));
}
{
auto date = Date(-1998, 8, 31);
date.roll!"months"(13);
_assertPred!"=="(date, Date(-1998, 10, 1));
date.roll!"months"(-13);
_assertPred!"=="(date, Date(-1998, 9, 1));
}
{
auto date = Date(-1997, 12, 31);
date.roll!"months"(13);
_assertPred!"=="(date, Date(-1997, 1, 31));
date.roll!"months"(-13);
_assertPred!"=="(date, Date(-1997, 12, 31));
}
{
auto date = Date(-1997, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(-1997, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(-1997, 1, 3));
}
{
auto date = Date(-2002, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(-2002, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(-2002, 1, 3));
}
{
auto date = Date(-2001, 12, 31);
date.roll!"months"(14);
_assertPred!"=="(date, Date(-2001, 3, 3));
date.roll!"months"(-14);
_assertPred!"=="(date, Date(-2001, 1, 3));
}
//Test Both
{
auto date = Date(1, 1, 1);
date.roll!"months"(-1);
_assertPred!"=="(date, Date(1, 12, 1));
date.roll!"months"(1);
_assertPred!"=="(date, Date(1, 1, 1));
}
{
auto date = Date(4, 1, 1);
date.roll!"months"(-48);
_assertPred!"=="(date, Date(4, 1, 1));
date.roll!"months"(48);
_assertPred!"=="(date, Date(4, 1, 1));
}
{
auto date = Date(4, 3, 31);
date.roll!"months"(-49);
_assertPred!"=="(date, Date(4, 3, 2));
date.roll!"months"(49);
_assertPred!"=="(date, Date(4, 4, 2));
}
{
auto date = Date(4, 3, 31);
date.roll!"months"(-85);
_assertPred!"=="(date, Date(4, 3, 2));
date.roll!"months"(85);
_assertPred!"=="(date, Date(4, 4, 2));
}
{
auto date = Date(-1, 1, 1);
date.roll!"months"(-1);
_assertPred!"=="(date, Date(-1, 12, 1));
date.roll!"months"(1);
_assertPred!"=="(date, Date(-1, 1, 1));
}
{
auto date = Date(-4, 1, 1);
date.roll!"months"(-48);
_assertPred!"=="(date, Date(-4, 1, 1));
date.roll!"months"(48);
_assertPred!"=="(date, Date(-4, 1, 1));
}
{
auto date = Date(-4, 3, 31);
date.roll!"months"(-49);
_assertPred!"=="(date, Date(-4, 3, 2));
date.roll!"months"(49);
_assertPred!"=="(date, Date(-4, 4, 2));
}
{
auto date = Date(-4, 3, 31);
date.roll!"months"(-85);
_assertPred!"=="(date, Date(-4, 3, 2));
date.roll!"months"(85);
_assertPred!"=="(date, Date(-4, 4, 2));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.roll!"months"(3)));
static assert(!__traits(compiles, idate.roll!"months"(3)));
//Verify Examples.
auto date1 = Date(2010, 1, 1);
date1.roll!"months"(1);
assert(date1 == Date(2010, 2, 1));
auto date2 = Date(2010, 1, 1);
date2.roll!"months"(-1);
assert(date2 == Date(2010, 12, 1));
auto date3 = Date(1999, 1, 29);
date3.roll!"months"(1);
assert(date3 == Date(1999, 3, 1));
auto date4 = Date(1999, 1, 29);
date4.roll!"months"(1, AllowDayOverflow.no);
assert(date4 == Date(1999, 2, 28));
}
}
//Test roll!"months"() with AllowDayOverlow.no
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 7, 6);
date.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 10, 6));
date.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 7, 6);
date.roll!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 1, 6));
date.roll!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 7, 6));
}
{
auto date = Date(1999, 7, 6);
date.roll!"months"(27, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 10, 6));
date.roll!"months"(-28, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 6));
}
{
auto date = Date(1999, 5, 31);
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 6, 30));
}
{
auto date = Date(1999, 5, 31);
date.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 4, 30));
}
{
auto date = Date(1999, 2, 28);
date.roll!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 2, 28));
}
{
auto date = Date(2000, 2, 29);
date.roll!"months"(12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(2000, 2, 29));
}
{
auto date = Date(1999, 7, 31);
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 8, 31));
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 9, 30));
}
{
auto date = Date(1998, 8, 31);
date.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 9, 30));
date.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 8, 30));
}
{
auto date = Date(1997, 12, 31);
date.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 1, 31));
date.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 12, 31));
}
{
auto date = Date(1997, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1997, 12, 28));
}
{
auto date = Date(1998, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1998, 12, 28));
}
{
auto date = Date(1999, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1999, 12, 28));
}
//Test B.C.
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(3, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 10, 6));
date.roll!"months"(-4, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 6, 6));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 1, 6));
date.roll!"months"(-6, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"months"(-27, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 4, 6));
date.roll!"months"(28, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 8, 6));
}
{
auto date = Date(-1999, 5, 31);
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 6, 30));
}
{
auto date = Date(-1999, 5, 31);
date.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 4, 30));
}
{
auto date = Date(-1999, 2, 28);
date.roll!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 2, 28));
}
{
auto date = Date(-2000, 2, 29);
date.roll!"months"(-12, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2000, 2, 29));
}
{
auto date = Date(-1999, 7, 31);
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 8, 31));
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1999, 9, 30));
}
{
auto date = Date(-1998, 8, 31);
date.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1998, 9, 30));
date.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1998, 8, 30));
}
{
auto date = Date(-1997, 12, 31);
date.roll!"months"(13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 1, 31));
date.roll!"months"(-13, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 12, 31));
}
{
auto date = Date(-1997, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1997, 12, 28));
}
{
auto date = Date(-2002, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2002, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2002, 12, 28));
}
{
auto date = Date(-2001, 12, 31);
date.roll!"months"(14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2001, 2, 28));
date.roll!"months"(-14, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-2001, 12, 28));
}
//Test Both
{
auto date = Date(1, 1, 1);
date.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1, 12, 1));
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(1, 1, 1));
}
{
auto date = Date(4, 1, 1);
date.roll!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 1, 1));
date.roll!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 1, 1));
}
{
auto date = Date(4, 3, 31);
date.roll!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 2, 29));
date.roll!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 3, 29));
}
{
auto date = Date(4, 3, 31);
date.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 2, 29));
date.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(4, 3, 29));
}
{
auto date = Date(-1, 1, 1);
date.roll!"months"(-1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1, 12, 1));
date.roll!"months"(1, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-1, 1, 1));
}
{
auto date = Date(-4, 1, 1);
date.roll!"months"(-48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 1, 1));
date.roll!"months"(48, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 1, 1));
}
{
auto date = Date(-4, 3, 31);
date.roll!"months"(-49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 2, 29));
date.roll!"months"(49, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 3, 29));
}
{
auto date = Date(-4, 3, 31);
date.roll!"months"(-85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 2, 29));
date.roll!"months"(85, AllowDayOverflow.no);
_assertPred!"=="(date, Date(-4, 3, 29));
}
}
}
/++
Adds the given number of units to this $(D Date). A negative number will
subtract.
The difference between rolling and adding is that rolling does not
affect larger units. For instance, rolling a $(D Date) one
year's worth of days gets the exact same $(D Date).
The only accepted units are $(D "days").
Params:
units = The units to add. Must be $(D "days").
value = The number of days to add to this $(D Date).
Examples:
--------------------
auto d = Date(2010, 1, 1);
d.roll!"days"(1);
assert(d == Date(2010, 1, 2));
d.roll!"days"(365);
assert(d == Date(2010, 1, 26));
d.roll!"days"(-32);
assert(d == Date(2010, 1, 25));
--------------------
+/
/+ref Date+/ void roll(string units)(long days) pure nothrow
if(units == "days")
{
immutable limit = maxDay(_year, _month);
days %= limit;
auto newDay = _day + days;
if(days < 0)
{
if(newDay < 1)
newDay += limit;
}
else if(newDay > limit)
newDay -= limit;
_day = cast(ubyte)newDay;
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto d = Date(2010, 1, 1);
d.roll!"days"(1);
assert(d == Date(2010, 1, 2));
d.roll!"days"(365);
assert(d == Date(2010, 1, 26));
d.roll!"days"(-32);
assert(d == Date(2010, 1, 25));
}
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 2, 28);
date.roll!"days"(1);
_assertPred!"=="(date, Date(1999, 2, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(1999, 2, 28));
}
{
auto date = Date(2000, 2, 28);
date.roll!"days"(1);
_assertPred!"=="(date, Date(2000, 2, 29));
date.roll!"days"(1);
_assertPred!"=="(date, Date(2000, 2, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(2000, 2, 29));
}
{
auto date = Date(1999, 6, 30);
date.roll!"days"(1);
_assertPred!"=="(date, Date(1999, 6, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(1999, 6, 30));
}
{
auto date = Date(1999, 7, 31);
date.roll!"days"(1);
_assertPred!"=="(date, Date(1999, 7, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(1999, 7, 31));
}
{
auto date = Date(1999, 1, 1);
date.roll!"days"(-1);
_assertPred!"=="(date, Date(1999, 1, 31));
date.roll!"days"(1);
_assertPred!"=="(date, Date(1999, 1, 1));
}
{
auto date = Date(1999, 7, 6);
date.roll!"days"(9);
_assertPred!"=="(date, Date(1999, 7, 15));
date.roll!"days"(-11);
_assertPred!"=="(date, Date(1999, 7, 4));
date.roll!"days"(30);
_assertPred!"=="(date, Date(1999, 7, 3));
date.roll!"days"(-3);
_assertPred!"=="(date, Date(1999, 7, 31));
}
{
auto date = Date(1999, 7, 6);
date.roll!"days"(365);
_assertPred!"=="(date, Date(1999, 7, 30));
date.roll!"days"(-365);
_assertPred!"=="(date, Date(1999, 7, 6));
date.roll!"days"(366);
_assertPred!"=="(date, Date(1999, 7, 31));
date.roll!"days"(730);
_assertPred!"=="(date, Date(1999, 7, 17));
date.roll!"days"(-1096);
_assertPred!"=="(date, Date(1999, 7, 6));
}
{
auto date = Date(1999, 2, 6);
date.roll!"days"(365);
_assertPred!"=="(date, Date(1999, 2, 7));
date.roll!"days"(-365);
_assertPred!"=="(date, Date(1999, 2, 6));
date.roll!"days"(366);
_assertPred!"=="(date, Date(1999, 2, 8));
date.roll!"days"(730);
_assertPred!"=="(date, Date(1999, 2, 10));
date.roll!"days"(-1096);
_assertPred!"=="(date, Date(1999, 2, 6));
}
//Test B.C.
{
auto date = Date(-1999, 2, 28);
date.roll!"days"(1);
_assertPred!"=="(date, Date(-1999, 2, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(-1999, 2, 28));
}
{
auto date = Date(-2000, 2, 28);
date.roll!"days"(1);
_assertPred!"=="(date, Date(-2000, 2, 29));
date.roll!"days"(1);
_assertPred!"=="(date, Date(-2000, 2, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(-2000, 2, 29));
}
{
auto date = Date(-1999, 6, 30);
date.roll!"days"(1);
_assertPred!"=="(date, Date(-1999, 6, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(-1999, 6, 30));
}
{
auto date = Date(-1999, 7, 31);
date.roll!"days"(1);
_assertPred!"=="(date, Date(-1999, 7, 1));
date.roll!"days"(-1);
_assertPred!"=="(date, Date(-1999, 7, 31));
}
{
auto date = Date(-1999, 1, 1);
date.roll!"days"(-1);
_assertPred!"=="(date, Date(-1999, 1, 31));
date.roll!"days"(1);
_assertPred!"=="(date, Date(-1999, 1, 1));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"days"(9);
_assertPred!"=="(date, Date(-1999, 7, 15));
date.roll!"days"(-11);
_assertPred!"=="(date, Date(-1999, 7, 4));
date.roll!"days"(30);
_assertPred!"=="(date, Date(-1999, 7, 3));
date.roll!"days"(-3);
_assertPred!"=="(date, Date(-1999, 7, 31));
}
{
auto date = Date(-1999, 7, 6);
date.roll!"days"(365);
_assertPred!"=="(date, Date(-1999, 7, 30));
date.roll!"days"(-365);
_assertPred!"=="(date, Date(-1999, 7, 6));
date.roll!"days"(366);
_assertPred!"=="(date, Date(-1999, 7, 31));
date.roll!"days"(730);
_assertPred!"=="(date, Date(-1999, 7, 17));
date.roll!"days"(-1096);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
//Test Both
{
auto date = Date(1, 7, 6);
date.roll!"days"(-365);
_assertPred!"=="(date, Date(1, 7, 13));
date.roll!"days"(365);
_assertPred!"=="(date, Date(1, 7, 6));
date.roll!"days"(-731);
_assertPred!"=="(date, Date(1, 7, 19));
date.roll!"days"(730);
_assertPred!"=="(date, Date(1, 7, 5));
}
{
auto date = Date(0, 7, 6);
date.roll!"days"(-365);
_assertPred!"=="(date, Date(0, 7, 13));
date.roll!"days"(365);
_assertPred!"=="(date, Date(0, 7, 6));
date.roll!"days"(-731);
_assertPred!"=="(date, Date(0, 7, 19));
date.roll!"days"(730);
_assertPred!"=="(date, Date(0, 7, 5));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.roll!"days"(12)));
static assert(!__traits(compiles, idate.roll!"days"(12)));
//Verify Examples.
auto date = Date(2010, 1, 1);
date.roll!"days"(1);
assert(date == Date(2010, 1, 2));
date.roll!"days"(365);
assert(date == Date(2010, 1, 26));
date.roll!"days"(-32);
assert(date == Date(2010, 1, 25));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D Date).
The legal types of arithmetic for Date using this operator are
$(BOOKTABLE,
$(TR $(TD Date) $(TD +) $(TD duration) $(TD -->) $(TD Date))
$(TR $(TD Date) $(TD -) $(TD duration) $(TD -->) $(TD Date))
)
Params:
duration = The duration to add to or subtract from this $(D Date).
+/
Date opBinary(string op, D)(in D duration) const pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
Date retval = this;
static if(is(Unqual!D == Duration))
immutable days = duration.total!"days";
else static if(is(Unqual!D == TickDuration))
immutable days = convert!("hnsecs", "days")(duration.hnsecs);
//Ideally, this would just be
//return retval.addDays(unaryFun!(op ~ "a")(days));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedDays = days;
else static if(op == "-")
immutable signedDays = -days;
else
static assert(0);
return retval.addDays(signedDays);
}
unittest
{
version(testStdDateTime)
{
auto date = Date(1999, 7, 6);
_assertPred!"=="(date + dur!"weeks"(7), Date(1999, 8, 24));
_assertPred!"=="(date + dur!"weeks"(-7), Date(1999, 5, 18));
_assertPred!"=="(date + dur!"days"(7), Date(1999, 7, 13));
_assertPred!"=="(date + dur!"days"(-7), Date(1999, 6, 29));
_assertPred!"=="(date + dur!"hours"(24), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"hours"(-24), Date(1999, 7, 5));
_assertPred!"=="(date + dur!"minutes"(1440), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"minutes"(-1440), Date(1999, 7, 5));
_assertPred!"=="(date + dur!"seconds"(86_400), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"seconds"(-86_400), Date(1999, 7, 5));
_assertPred!"=="(date + dur!"msecs"(86_400_000), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"msecs"(-86_400_000), Date(1999, 7, 5));
_assertPred!"=="(date + dur!"usecs"(86_400_000_000), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"usecs"(-86_400_000_000), Date(1999, 7, 5));
_assertPred!"=="(date + dur!"hnsecs"(864_000_000_000), Date(1999, 7, 7));
_assertPred!"=="(date + dur!"hnsecs"(-864_000_000_000), Date(1999, 7, 5));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(date + TickDuration.from!"usecs"(86_400_000_000), Date(1999, 7, 7));
_assertPred!"=="(date + TickDuration.from!"usecs"(-86_400_000_000), Date(1999, 7, 5));
}
_assertPred!"=="(date - dur!"weeks"(-7), Date(1999, 8, 24));
_assertPred!"=="(date - dur!"weeks"(7), Date(1999, 5, 18));
_assertPred!"=="(date - dur!"days"(-7), Date(1999, 7, 13));
_assertPred!"=="(date - dur!"days"(7), Date(1999, 6, 29));
_assertPred!"=="(date - dur!"hours"(-24), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"hours"(24), Date(1999, 7, 5));
_assertPred!"=="(date - dur!"minutes"(-1440), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"minutes"(1440), Date(1999, 7, 5));
_assertPred!"=="(date - dur!"seconds"(-86_400), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"seconds"(86_400), Date(1999, 7, 5));
_assertPred!"=="(date - dur!"msecs"(-86_400_000), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"msecs"(86_400_000), Date(1999, 7, 5));
_assertPred!"=="(date - dur!"usecs"(-86_400_000_000), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"usecs"(86_400_000_000), Date(1999, 7, 5));
_assertPred!"=="(date - dur!"hnsecs"(-864_000_000_000), Date(1999, 7, 7));
_assertPred!"=="(date - dur!"hnsecs"(864_000_000_000), Date(1999, 7, 5));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(date - TickDuration.from!"usecs"(-86_400_000_000), Date(1999, 7, 7));
_assertPred!"=="(date - TickDuration.from!"usecs"(86_400_000_000), Date(1999, 7, 5));
}
auto duration = dur!"days"(12);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date + duration));
static assert(__traits(compiles, cdate + duration));
static assert(__traits(compiles, idate + duration));
static assert(__traits(compiles, date - duration));
static assert(__traits(compiles, cdate - duration));
static assert(__traits(compiles, idate - duration));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D Date), as well as assigning the result to this $(D Date).
The legal types of arithmetic for $(D Date) using this operator are
$(BOOKTABLE,
$(TR $(TD Date) $(TD +) $(TD duration) $(TD -->) $(TD Date))
$(TR $(TD Date) $(TD -) $(TD duration) $(TD -->) $(TD Date))
)
Params:
duration = The duration to add to or subtract from this $(D Date).
+/
/+ref+/ Date opOpAssign(string op, D)(in D duration) pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
static if(is(Unqual!D == Duration))
immutable days = duration.total!"days";
else static if(is(Unqual!D == TickDuration))
immutable days = convert!("hnsecs", "days")(duration.hnsecs);
//Ideally, this would just be
//return addDays(unaryFun!(op ~ "a")(days));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedDays = days;
else static if(op == "-")
immutable signedDays = -days;
else
static assert(0);
return addDays(signedDays);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"+="(Date(1999, 7, 6), dur!"weeks"(7), Date(1999, 8, 24));
_assertPred!"+="(Date(1999, 7, 6), dur!"weeks"(-7), Date(1999, 5, 18));
_assertPred!"+="(Date(1999, 7, 6), dur!"days"(7), Date(1999, 7, 13));
_assertPred!"+="(Date(1999, 7, 6), dur!"days"(-7), Date(1999, 6, 29));
_assertPred!"+="(Date(1999, 7, 6), dur!"hours"(24), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"hours"(-24), Date(1999, 7, 5));
_assertPred!"+="(Date(1999, 7, 6), dur!"minutes"(1440), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"minutes"(-1440), Date(1999, 7, 5));
_assertPred!"+="(Date(1999, 7, 6), dur!"seconds"(86_400), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"seconds"(-86_400), Date(1999, 7, 5));
_assertPred!"+="(Date(1999, 7, 6), dur!"msecs"(86_400_000), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"msecs"(-86_400_000), Date(1999, 7, 5));
_assertPred!"+="(Date(1999, 7, 6), dur!"usecs"(86_400_000_000), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"usecs"(-86_400_000_000), Date(1999, 7, 5));
_assertPred!"+="(Date(1999, 7, 6), dur!"hnsecs"(864_000_000_000), Date(1999, 7, 7));
_assertPred!"+="(Date(1999, 7, 6), dur!"hnsecs"(-864_000_000_000), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"weeks"(-7), Date(1999, 8, 24));
_assertPred!"-="(Date(1999, 7, 6), dur!"weeks"(7), Date(1999, 5, 18));
_assertPred!"-="(Date(1999, 7, 6), dur!"days"(-7), Date(1999, 7, 13));
_assertPred!"-="(Date(1999, 7, 6), dur!"days"(7), Date(1999, 6, 29));
_assertPred!"-="(Date(1999, 7, 6), dur!"hours"(-24), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"hours"(24), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"minutes"(-1440), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"minutes"(1440), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"seconds"(-86_400), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"seconds"(86_400), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"msecs"(-86_400_000), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"msecs"(86_400_000), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"usecs"(-86_400_000_000), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"usecs"(86_400_000_000), Date(1999, 7, 5));
_assertPred!"-="(Date(1999, 7, 6), dur!"hnsecs"(-864_000_000_000), Date(1999, 7, 7));
_assertPred!"-="(Date(1999, 7, 6), dur!"hnsecs"(864_000_000_000), Date(1999, 7, 5));
auto duration = dur!"days"(12);
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date += duration));
static assert(!__traits(compiles, cdate += duration));
static assert(!__traits(compiles, idate += duration));
static assert(__traits(compiles, date -= duration));
static assert(!__traits(compiles, cdate -= duration));
static assert(!__traits(compiles, idate -= duration));
}
}
/++
Gives the difference between two $(D Date)s.
The legal types of arithmetic for Date using this operator are
$(BOOKTABLE,
$(TR $(TD Date) $(TD -) $(TD Date) $(TD -->) $(TD duration))
)
+/
Duration opBinary(string op)(in Date rhs) const pure nothrow
if(op == "-")
{
return dur!"days"(this.dayOfGregorianCal - rhs.dayOfGregorianCal);
}
unittest
{
version(testStdDateTime)
{
auto date = Date(1999, 7, 6);
_assertPred!"=="(Date(1999, 7, 6) - Date(1998, 7, 6), dur!"days"(365));
_assertPred!"=="(Date(1998, 7, 6) - Date(1999, 7, 6), dur!"days"(-365));
_assertPred!"=="(Date(1999, 6, 6) - Date(1999, 5, 6), dur!"days"(31));
_assertPred!"=="(Date(1999, 5, 6) - Date(1999, 6, 6), dur!"days"(-31));
_assertPred!"=="(Date(1999, 1, 1) - Date(1998, 12, 31), dur!"days"(1));
_assertPred!"=="(Date(1998, 12, 31) - Date(1999, 1, 1), dur!"days"(-1));
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date - date));
static assert(__traits(compiles, cdate - date));
static assert(__traits(compiles, idate - date));
static assert(__traits(compiles, date - cdate));
static assert(__traits(compiles, cdate - cdate));
static assert(__traits(compiles, idate - cdate));
static assert(__traits(compiles, date - idate));
static assert(__traits(compiles, cdate - idate));
static assert(__traits(compiles, idate - idate));
}
}
/++
Returns the difference between the two $(D Date)s in months.
To get the difference in years, subtract the year property
of two $(D SysTime)s. To get the difference in days or weeks,
subtract the $(D SysTime)s themselves and use the $(D Duration)
that results. Because converting between months and smaller
units requires a specific date (which $(D Duration)s don't have),
getting the difference in months requires some math using both
the year and month properties, so this is a convenience function for
getting the difference in months.
Note that the number of days in the months or how far into the month
either $(D Date) is is irrelevant. It is the difference in the month
property combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Params:
rhs = The $(D Date) to subtract from this one.
Examples:
--------------------
assert(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31)) == 1);
assert(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1)) == -1);
assert(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1)) == 2);
assert(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31)) == -2);
--------------------
+/
int diffMonths(in Date rhs) const pure nothrow
{
immutable yearDiff = _year - rhs._year;
immutable monthDiff = _month - rhs._month;
return yearDiff * 12 + monthDiff;
}
unittest
{
version(testStdDateTime)
{
auto date = Date(1999, 7, 6);
//Test A.D.
_assertPred!"=="(date.diffMonths(Date(1998, 6, 5)), 13);
_assertPred!"=="(date.diffMonths(Date(1998, 7, 5)), 12);
_assertPred!"=="(date.diffMonths(Date(1998, 8, 5)), 11);
_assertPred!"=="(date.diffMonths(Date(1998, 9, 5)), 10);
_assertPred!"=="(date.diffMonths(Date(1998, 10, 5)), 9);
_assertPred!"=="(date.diffMonths(Date(1998, 11, 5)), 8);
_assertPred!"=="(date.diffMonths(Date(1998, 12, 5)), 7);
_assertPred!"=="(date.diffMonths(Date(1999, 1, 5)), 6);
_assertPred!"=="(date.diffMonths(Date(1999, 2, 6)), 5);
_assertPred!"=="(date.diffMonths(Date(1999, 3, 6)), 4);
_assertPred!"=="(date.diffMonths(Date(1999, 4, 6)), 3);
_assertPred!"=="(date.diffMonths(Date(1999, 5, 6)), 2);
_assertPred!"=="(date.diffMonths(Date(1999, 6, 6)), 1);
_assertPred!"=="(date.diffMonths(date), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 8, 6)), -1);
_assertPred!"=="(date.diffMonths(Date(1999, 9, 6)), -2);
_assertPred!"=="(date.diffMonths(Date(1999, 10, 6)), -3);
_assertPred!"=="(date.diffMonths(Date(1999, 11, 6)), -4);
_assertPred!"=="(date.diffMonths(Date(1999, 12, 6)), -5);
_assertPred!"=="(date.diffMonths(Date(2000, 1, 6)), -6);
_assertPred!"=="(date.diffMonths(Date(2000, 2, 6)), -7);
_assertPred!"=="(date.diffMonths(Date(2000, 3, 6)), -8);
_assertPred!"=="(date.diffMonths(Date(2000, 4, 6)), -9);
_assertPred!"=="(date.diffMonths(Date(2000, 5, 6)), -10);
_assertPred!"=="(date.diffMonths(Date(2000, 6, 6)), -11);
_assertPred!"=="(date.diffMonths(Date(2000, 7, 6)), -12);
_assertPred!"=="(date.diffMonths(Date(2000, 8, 6)), -13);
_assertPred!"=="(Date(1998, 6, 5).diffMonths(date), -13);
_assertPred!"=="(Date(1998, 7, 5).diffMonths(date), -12);
_assertPred!"=="(Date(1998, 8, 5).diffMonths(date), -11);
_assertPred!"=="(Date(1998, 9, 5).diffMonths(date), -10);
_assertPred!"=="(Date(1998, 10, 5).diffMonths(date), -9);
_assertPred!"=="(Date(1998, 11, 5).diffMonths(date), -8);
_assertPred!"=="(Date(1998, 12, 5).diffMonths(date), -7);
_assertPred!"=="(Date(1999, 1, 5).diffMonths(date), -6);
_assertPred!"=="(Date(1999, 2, 6).diffMonths(date), -5);
_assertPred!"=="(Date(1999, 3, 6).diffMonths(date), -4);
_assertPred!"=="(Date(1999, 4, 6).diffMonths(date), -3);
_assertPred!"=="(Date(1999, 5, 6).diffMonths(date), -2);
_assertPred!"=="(Date(1999, 6, 6).diffMonths(date), -1);
_assertPred!"=="(Date(1999, 8, 6).diffMonths(date), 1);
_assertPred!"=="(Date(1999, 9, 6).diffMonths(date), 2);
_assertPred!"=="(Date(1999, 10, 6).diffMonths(date), 3);
_assertPred!"=="(Date(1999, 11, 6).diffMonths(date), 4);
_assertPred!"=="(Date(1999, 12, 6).diffMonths(date), 5);
_assertPred!"=="(Date(2000, 1, 6).diffMonths(date), 6);
_assertPred!"=="(Date(2000, 2, 6).diffMonths(date), 7);
_assertPred!"=="(Date(2000, 3, 6).diffMonths(date), 8);
_assertPred!"=="(Date(2000, 4, 6).diffMonths(date), 9);
_assertPred!"=="(Date(2000, 5, 6).diffMonths(date), 10);
_assertPred!"=="(Date(2000, 6, 6).diffMonths(date), 11);
_assertPred!"=="(Date(2000, 7, 6).diffMonths(date), 12);
_assertPred!"=="(Date(2000, 8, 6).diffMonths(date), 13);
_assertPred!"=="(date.diffMonths(Date(1999, 6, 30)), 1);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 1)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 6)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 11)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 16)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 21)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 26)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 7, 31)), 0);
_assertPred!"=="(date.diffMonths(Date(1999, 8, 1)), -1);
_assertPred!"=="(date.diffMonths(Date(1990, 6, 30)), 109);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 1)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 6)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 11)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 16)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 21)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 26)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 7, 31)), 108);
_assertPred!"=="(date.diffMonths(Date(1990, 8, 1)), 107);
_assertPred!"=="(Date(1999, 6, 30).diffMonths(date), -1);
_assertPred!"=="(Date(1999, 7, 1).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 6).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 11).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 16).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 21).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 26).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 7, 31).diffMonths(date), 0);
_assertPred!"=="(Date(1999, 8, 1).diffMonths(date), 1);
_assertPred!"=="(Date(1990, 6, 30).diffMonths(date), -109);
_assertPred!"=="(Date(1990, 7, 1).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 6).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 11).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 16).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 21).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 26).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 7, 31).diffMonths(date), -108);
_assertPred!"=="(Date(1990, 8, 1).diffMonths(date), -107);
//Test B.C.
auto dateBC = Date(-1999, 7, 6);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 6, 5)), 13);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 7, 5)), 12);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 8, 5)), 11);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 9, 5)), 10);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 10, 5)), 9);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 11, 5)), 8);
_assertPred!"=="(dateBC.diffMonths(Date(-2000, 12, 5)), 7);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 1, 5)), 6);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 2, 6)), 5);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 3, 6)), 4);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 4, 6)), 3);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 5, 6)), 2);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 6, 6)), 1);
_assertPred!"=="(dateBC.diffMonths(dateBC), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 8, 6)), -1);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 9, 6)), -2);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 10, 6)), -3);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 11, 6)), -4);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 12, 6)), -5);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 1, 6)), -6);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 2, 6)), -7);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 3, 6)), -8);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 4, 6)), -9);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 5, 6)), -10);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 6, 6)), -11);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 7, 6)), -12);
_assertPred!"=="(dateBC.diffMonths(Date(-1998, 8, 6)), -13);
_assertPred!"=="(Date(-2000, 6, 5).diffMonths(dateBC), -13);
_assertPred!"=="(Date(-2000, 7, 5).diffMonths(dateBC), -12);
_assertPred!"=="(Date(-2000, 8, 5).diffMonths(dateBC), -11);
_assertPred!"=="(Date(-2000, 9, 5).diffMonths(dateBC), -10);
_assertPred!"=="(Date(-2000, 10, 5).diffMonths(dateBC), -9);
_assertPred!"=="(Date(-2000, 11, 5).diffMonths(dateBC), -8);
_assertPred!"=="(Date(-2000, 12, 5).diffMonths(dateBC), -7);
_assertPred!"=="(Date(-1999, 1, 5).diffMonths(dateBC), -6);
_assertPred!"=="(Date(-1999, 2, 6).diffMonths(dateBC), -5);
_assertPred!"=="(Date(-1999, 3, 6).diffMonths(dateBC), -4);
_assertPred!"=="(Date(-1999, 4, 6).diffMonths(dateBC), -3);
_assertPred!"=="(Date(-1999, 5, 6).diffMonths(dateBC), -2);
_assertPred!"=="(Date(-1999, 6, 6).diffMonths(dateBC), -1);
_assertPred!"=="(Date(-1999, 8, 6).diffMonths(dateBC), 1);
_assertPred!"=="(Date(-1999, 9, 6).diffMonths(dateBC), 2);
_assertPred!"=="(Date(-1999, 10, 6).diffMonths(dateBC), 3);
_assertPred!"=="(Date(-1999, 11, 6).diffMonths(dateBC), 4);
_assertPred!"=="(Date(-1999, 12, 6).diffMonths(dateBC), 5);
_assertPred!"=="(Date(-1998, 1, 6).diffMonths(dateBC), 6);
_assertPred!"=="(Date(-1998, 2, 6).diffMonths(dateBC), 7);
_assertPred!"=="(Date(-1998, 3, 6).diffMonths(dateBC), 8);
_assertPred!"=="(Date(-1998, 4, 6).diffMonths(dateBC), 9);
_assertPred!"=="(Date(-1998, 5, 6).diffMonths(dateBC), 10);
_assertPred!"=="(Date(-1998, 6, 6).diffMonths(dateBC), 11);
_assertPred!"=="(Date(-1998, 7, 6).diffMonths(dateBC), 12);
_assertPred!"=="(Date(-1998, 8, 6).diffMonths(dateBC), 13);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 6, 30)), 1);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 1)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 6)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 11)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 16)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 21)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 26)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 7, 31)), 0);
_assertPred!"=="(dateBC.diffMonths(Date(-1999, 8, 1)), -1);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 6, 30)), 109);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 1)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 6)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 11)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 16)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 21)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 26)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 7, 31)), 108);
_assertPred!"=="(dateBC.diffMonths(Date(-2008, 8, 1)), 107);
_assertPred!"=="(Date(-1999, 6, 30).diffMonths(dateBC), -1);
_assertPred!"=="(Date(-1999, 7, 1).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 6).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 11).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 16).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 21).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 26).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 7, 31).diffMonths(dateBC), 0);
_assertPred!"=="(Date(-1999, 8, 1).diffMonths(dateBC), 1);
_assertPred!"=="(Date(-2008, 6, 30).diffMonths(dateBC), -109);
_assertPred!"=="(Date(-2008, 7, 1).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 6).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 11).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 16).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 21).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 26).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 7, 31).diffMonths(dateBC), -108);
_assertPred!"=="(Date(-2008, 8, 1).diffMonths(dateBC), -107);
//Test Both
_assertPred!"=="(Date(3, 3, 3).diffMonths(Date(-5, 5, 5)), 94);
_assertPred!"=="(Date(-5, 5, 5).diffMonths(Date(3, 3, 3)), -94);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date.diffMonths(date)));
static assert(__traits(compiles, cdate.diffMonths(date)));
static assert(__traits(compiles, idate.diffMonths(date)));
static assert(__traits(compiles, date.diffMonths(cdate)));
static assert(__traits(compiles, cdate.diffMonths(cdate)));
static assert(__traits(compiles, idate.diffMonths(cdate)));
static assert(__traits(compiles, date.diffMonths(idate)));
static assert(__traits(compiles, cdate.diffMonths(idate)));
static assert(__traits(compiles, idate.diffMonths(idate)));
//Verify Examples.
assert(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31)) == 1);
assert(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1)) == -1);
assert(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1)) == 2);
assert(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31)) == -2);
}
}
/++
Whether this $(D Date) is in a leap year.
+/
@property bool isLeapYear() const pure nothrow
{
return yearIsLeapYear(_year);
}
unittest
{
version(testStdDateTime)
{
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, date.isLeapYear = true));
static assert(!__traits(compiles, cdate.isLeapYear = true));
static assert(!__traits(compiles, idate.isLeapYear = true));
}
}
/++
Day of the week this $(D Date) is on.
+/
@property DayOfWeek dayOfWeek() const pure nothrow
{
return getDayOfWeek(dayOfGregorianCal);
}
unittest
{
version(testStdDateTime)
{
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.dayOfWeek == DayOfWeek.sun));
static assert(!__traits(compiles, cdate.dayOfWeek = DayOfWeek.sun));
static assert(__traits(compiles, idate.dayOfWeek == DayOfWeek.sun));
static assert(!__traits(compiles, idate.dayOfWeek = DayOfWeek.sun));
}
}
/++
Day of the year this $(D Date) is on.
Examples:
--------------------
assert(Date(1999, 1, 1).dayOfYear == 1);
assert(Date(1999, 12, 31).dayOfYear == 365);
assert(Date(2000, 12, 31).dayOfYear == 366);
--------------------
+/
@property ushort dayOfYear() const pure nothrow
{
if (_month >= Month.jan && _month <= Month.dec)
{
immutable int[] lastDay = isLeapYear ? lastDayLeap : lastDayNonLeap;
auto monthIndex = _month - Month.jan;
return cast(ushort)(lastDay[monthIndex] + _day);
}
assert(0, "Invalid month.");
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(Date(1999, 1, 1).dayOfYear == 1);
assert(Date(1999, 12, 31).dayOfYear == 365);
assert(Date(2000, 12, 31).dayOfYear == 366);
}
version(testStdDateTime) unittest
{
foreach(year; filter!((a){return !yearIsLeapYear(a);})
(chain(testYearsBC, testYearsAD)))
{
foreach(doy; testDaysOfYear)
{
_assertPred!"=="(Date(year, doy.md.month, doy.md.day).dayOfYear,
doy.day);
}
}
foreach(year; filter!((a){return yearIsLeapYear(a);})
(chain(testYearsBC, testYearsAD)))
{
foreach(doy; testDaysOfLeapYear)
{
_assertPred!"=="(Date(year, doy.md.month, doy.md.day).dayOfYear,
doy.day);
}
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.dayOfYear == 187));
static assert(__traits(compiles, idate.dayOfYear == 187));
}
/++
Day of the year.
Params:
day = The day of the year to set which day of the year this
$(D Date) is on.
Throws:
$(D DateTimeException) if the given day is an invalid day of the
year.
+/
@property void dayOfYear(int day) pure
{
immutable int[] lastDay = isLeapYear ? lastDayLeap : lastDayNonLeap;
if(day <= 0 || day > (isLeapYear ? daysInLeapYear : daysInYear) )
throw new DateTimeException("Invalid day of the year.");
foreach (i; 1..lastDay.length)
{
if (day <= lastDay[i])
{
_month = cast(Month)(cast(int)Month.jan + i - 1);
_day = cast(ubyte)(day - lastDay[i - 1]);
return;
}
}
assert(0, "Invalid day of the year.");
}
version(testStdDateTime) unittest
{
static void test(Date date, int day, MonthDay expected, size_t line = __LINE__)
{
date.dayOfYear = day;
_assertPred!"=="(date.month, expected.month, "", __FILE__, line);
_assertPred!"=="(date.day, expected.day, "", __FILE__, line);
}
foreach(doy; testDaysOfYear)
{
test(Date(1999, 1, 1), doy.day, doy.md);
test(Date(-1, 1, 1), doy.day, doy.md);
}
foreach(doy; testDaysOfLeapYear)
{
test(Date(2000, 1, 1), doy.day, doy.md);
test(Date(-4, 1, 1), doy.day, doy.md);
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.dayOfYear = 187));
static assert(!__traits(compiles, idate.dayOfYear = 187));
}
/++
The Xth day of the Gregorian Calendar that this $(D Date) is on.
Examples:
--------------------
assert(Date(1, 1, 1).dayOfGregorianCal == 1);
assert(Date(1, 12, 31).dayOfGregorianCal == 365);
assert(Date(2, 1, 1).dayOfGregorianCal == 366);
assert(Date(0, 12, 31).dayOfGregorianCal == 0);
assert(Date(0, 1, 1).dayOfGregorianCal == -365);
assert(Date(-1, 12, 31).dayOfGregorianCal == -366);
assert(Date(2000, 1, 1).dayOfGregorianCal == 730_120);
assert(Date(2010, 12, 31).dayOfGregorianCal == 734_137);
--------------------
+/
@property int dayOfGregorianCal() const pure nothrow
{
if(isAD)
{
if(_year == 1)
return dayOfYear;
int years = _year - 1;
auto days = (years / 400) * daysIn400Years;
years %= 400;
days += (years / 100) * daysIn100Years;
years %= 100;
days += (years / 4) * daysIn4Years;
years %= 4;
days += years * daysInYear;
days += dayOfYear;
return days;
}
else if(_year == 0)
return dayOfYear - daysInLeapYear;
else
{
int years = _year;
auto days = (years / 400) * daysIn400Years;
years %= 400;
days += (years / 100) * daysIn100Years;
years %= 100;
days += (years / 4) * daysIn4Years;
years %= 4;
if(years < 0)
{
days -= daysInLeapYear;
++years;
days += years * daysInYear;
days -= daysInYear - dayOfYear;
}
else
days -= daysInLeapYear - dayOfYear;
return days;
}
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(Date(1, 1, 1).dayOfGregorianCal == 1);
assert(Date(1, 12, 31).dayOfGregorianCal == 365);
assert(Date(2, 1, 1).dayOfGregorianCal == 366);
assert(Date(0, 12, 31).dayOfGregorianCal == 0);
assert(Date(0, 1, 1).dayOfGregorianCal == -365);
assert(Date(-1, 12, 31).dayOfGregorianCal == -366);
assert(Date(2000, 1, 1).dayOfGregorianCal == 730_120);
assert(Date(2010, 12, 31).dayOfGregorianCal == 734_137);
}
version(testStdDateTime) unittest
{
foreach(gd; chain(testGregDaysBC, testGregDaysAD))
_assertPred!"=="(gd.date.dayOfGregorianCal, gd.day);
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date.dayOfGregorianCal));
static assert(__traits(compiles, cdate.dayOfGregorianCal));
static assert(__traits(compiles, idate.dayOfGregorianCal));
}
/++
The Xth day of the Gregorian Calendar that this $(D Date) is on.
Params:
day = The day of the Gregorian Calendar to set this $(D Date) to.
Examples:
--------------------
auto date = Date.init;
date.dayOfGregorianCal = 1;
assert(date == Date(1, 1, 1));
date.dayOfGregorianCal = 365;
assert(date == Date(1, 12, 31));
date.dayOfGregorianCal = 366;
assert(date == Date(2, 1, 1));
date.dayOfGregorianCal = 0;
assert(date == Date(0, 12, 31));
date.dayOfGregorianCal = -365;
assert(date == Date(-0, 1, 1));
date.dayOfGregorianCal = -366;
assert(date == Date(-1, 12, 31));
date.dayOfGregorianCal = 730_120;
assert(date == Date(2000, 1, 1));
date.dayOfGregorianCal = 734_137;
assert(date == Date(2010, 12, 31));
--------------------
+/
@property void dayOfGregorianCal(int day) pure nothrow
{
this = Date(day);
}
unittest
{
version(testStdDateTime)
{
{
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date.dayOfGregorianCal = 187));
static assert(!__traits(compiles, cdate.dayOfGregorianCal = 187));
static assert(!__traits(compiles, idate.dayOfGregorianCal = 187));
}
//Verify Examples.
{
auto date = Date.init;
date.dayOfGregorianCal = 1;
assert(date == Date(1, 1, 1));
date.dayOfGregorianCal = 365;
assert(date == Date(1, 12, 31));
date.dayOfGregorianCal = 366;
assert(date == Date(2, 1, 1));
date.dayOfGregorianCal = 0;
assert(date == Date(0, 12, 31));
date.dayOfGregorianCal = -365;
assert(date == Date(-0, 1, 1));
date.dayOfGregorianCal = -366;
assert(date == Date(-1, 12, 31));
date.dayOfGregorianCal = 730_120;
assert(date == Date(2000, 1, 1));
date.dayOfGregorianCal = 734_137;
assert(date == Date(2010, 12, 31));
}
}
}
/++
The ISO 8601 week of the year that this $(D Date) is in.
See_Also:
$(WEB en.wikipedia.org/wiki/ISO_week_date, ISO Week Date)
+/
@property ubyte isoWeek() const pure nothrow
{
immutable weekday = dayOfWeek;
immutable adjustedWeekday = weekday == DayOfWeek.sun ? 7 : weekday;
immutable week = (dayOfYear - adjustedWeekday + 10) / 7;
try
{
if(week == 53)
{
switch(Date(_year + 1, 1, 1).dayOfWeek)
{
case DayOfWeek.mon:
case DayOfWeek.tue:
case DayOfWeek.wed:
case DayOfWeek.thu:
return 1;
case DayOfWeek.fri:
case DayOfWeek.sat:
case DayOfWeek.sun:
return 53;
default:
assert(0, "Invalid ISO Week");
}
}
else if(week > 0)
return cast(ubyte)week;
else
return Date(_year - 1, 12, 31).isoWeek;
}
catch(Exception e)
assert(0, "Date's constructor threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(2009, 12, 28).isoWeek, 53);
_assertPred!"=="(Date(2009, 12, 29).isoWeek, 53);
_assertPred!"=="(Date(2009, 12, 30).isoWeek, 53);
_assertPred!"=="(Date(2009, 12, 31).isoWeek, 53);
_assertPred!"=="(Date(2010, 1, 1).isoWeek, 53);
_assertPred!"=="(Date(2010, 1, 2).isoWeek, 53);
_assertPred!"=="(Date(2010, 1, 3).isoWeek, 53);
_assertPred!"=="(Date(2010, 1, 4).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 5).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 6).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 7).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 8).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 9).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 10).isoWeek, 1);
_assertPred!"=="(Date(2010, 1, 11).isoWeek, 2);
_assertPred!"=="(Date(2010, 12, 31).isoWeek, 52);
_assertPred!"=="(Date(2004, 12, 26).isoWeek, 52);
_assertPred!"=="(Date(2004, 12, 27).isoWeek, 53);
_assertPred!"=="(Date(2004, 12, 28).isoWeek, 53);
_assertPred!"=="(Date(2004, 12, 29).isoWeek, 53);
_assertPred!"=="(Date(2004, 12, 30).isoWeek, 53);
_assertPred!"=="(Date(2004, 12, 31).isoWeek, 53);
_assertPred!"=="(Date(2005, 1, 1).isoWeek, 53);
_assertPred!"=="(Date(2005, 1, 2).isoWeek, 53);
_assertPred!"=="(Date(2005, 12, 31).isoWeek, 52);
_assertPred!"=="(Date(2007, 1, 1).isoWeek, 1);
_assertPred!"=="(Date(2007, 12, 30).isoWeek, 52);
_assertPred!"=="(Date(2007, 12, 31).isoWeek, 1);
_assertPred!"=="(Date(2008, 1, 1).isoWeek, 1);
_assertPred!"=="(Date(2008, 12, 28).isoWeek, 52);
_assertPred!"=="(Date(2008, 12, 29).isoWeek, 1);
_assertPred!"=="(Date(2008, 12, 30).isoWeek, 1);
_assertPred!"=="(Date(2008, 12, 31).isoWeek, 1);
_assertPred!"=="(Date(2009, 1, 1).isoWeek, 1);
_assertPred!"=="(Date(2009, 1, 2).isoWeek, 1);
_assertPred!"=="(Date(2009, 1, 3).isoWeek, 1);
_assertPred!"=="(Date(2009, 1, 4).isoWeek, 1);
//Test B.C.
//The algorithm should work identically for both A.D. and B.C. since
//it doesn't really take the year into account, so B.C. testing
//probably isn't really needed.
_assertPred!"=="(Date(0, 12, 31).isoWeek, 52);
_assertPred!"=="(Date(0, 1, 4).isoWeek, 1);
_assertPred!"=="(Date(0, 1, 1).isoWeek, 52);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.isoWeek == 3));
static assert(!__traits(compiles, cdate.isoWeek = 3));
static assert(__traits(compiles, idate.isoWeek == 3));
static assert(!__traits(compiles, idate.isoWeek = 3));
}
}
/++
$(D Date) for the last day in the month that this $(D Date) is in.
Examples:
--------------------
assert(Date(1999, 1, 6).endOfMonth == Date(1999, 1, 31));
assert(Date(1999, 2, 7).endOfMonth == Date(1999, 2, 28));
assert(Date(2000, 2, 7).endOfMonth == Date(1999, 2, 29));
assert(Date(2000, 6, 4).endOfMonth == Date(1999, 6, 30));
--------------------
+/
@property Date endOfMonth() const pure nothrow
{
try
return Date(_year, _month, maxDay(_year, _month));
catch(Exception e)
assert(0, "Date's constructor threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(1999, 1, 1).endOfMonth, Date(1999, 1, 31));
_assertPred!"=="(Date(1999, 2, 1).endOfMonth, Date(1999, 2, 28));
_assertPred!"=="(Date(2000, 2, 1).endOfMonth, Date(2000, 2, 29));
_assertPred!"=="(Date(1999, 3, 1).endOfMonth, Date(1999, 3, 31));
_assertPred!"=="(Date(1999, 4, 1).endOfMonth, Date(1999, 4, 30));
_assertPred!"=="(Date(1999, 5, 1).endOfMonth, Date(1999, 5, 31));
_assertPred!"=="(Date(1999, 6, 1).endOfMonth, Date(1999, 6, 30));
_assertPred!"=="(Date(1999, 7, 1).endOfMonth, Date(1999, 7, 31));
_assertPred!"=="(Date(1999, 8, 1).endOfMonth, Date(1999, 8, 31));
_assertPred!"=="(Date(1999, 9, 1).endOfMonth, Date(1999, 9, 30));
_assertPred!"=="(Date(1999, 10, 1).endOfMonth, Date(1999, 10, 31));
_assertPred!"=="(Date(1999, 11, 1).endOfMonth, Date(1999, 11, 30));
_assertPred!"=="(Date(1999, 12, 1).endOfMonth, Date(1999, 12, 31));
//Test B.C.
_assertPred!"=="(Date(-1999, 1, 1).endOfMonth, Date(-1999, 1, 31));
_assertPred!"=="(Date(-1999, 2, 1).endOfMonth, Date(-1999, 2, 28));
_assertPred!"=="(Date(-2000, 2, 1).endOfMonth, Date(-2000, 2, 29));
_assertPred!"=="(Date(-1999, 3, 1).endOfMonth, Date(-1999, 3, 31));
_assertPred!"=="(Date(-1999, 4, 1).endOfMonth, Date(-1999, 4, 30));
_assertPred!"=="(Date(-1999, 5, 1).endOfMonth, Date(-1999, 5, 31));
_assertPred!"=="(Date(-1999, 6, 1).endOfMonth, Date(-1999, 6, 30));
_assertPred!"=="(Date(-1999, 7, 1).endOfMonth, Date(-1999, 7, 31));
_assertPred!"=="(Date(-1999, 8, 1).endOfMonth, Date(-1999, 8, 31));
_assertPred!"=="(Date(-1999, 9, 1).endOfMonth, Date(-1999, 9, 30));
_assertPred!"=="(Date(-1999, 10, 1).endOfMonth, Date(-1999, 10, 31));
_assertPred!"=="(Date(-1999, 11, 1).endOfMonth, Date(-1999, 11, 30));
_assertPred!"=="(Date(-1999, 12, 1).endOfMonth, Date(-1999, 12, 31));
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.endOfMonth = Date(1999, 7, 30)));
static assert(!__traits(compiles, idate.endOfMonth = Date(1999, 7, 30)));
//Verify Examples.
assert(Date(1999, 1, 6).endOfMonth == Date(1999, 1, 31));
assert(Date(1999, 2, 7).endOfMonth == Date(1999, 2, 28));
assert(Date(2000, 2, 7).endOfMonth == Date(2000, 2, 29));
assert(Date(2000, 6, 4).endOfMonth == Date(2000, 6, 30));
}
}
/++
The last day in the month that this $(D Date) is in.
Examples:
--------------------
assert(Date(1999, 1, 6).daysInMonth == 31);
assert(Date(1999, 2, 7).daysInMonth == 28);
assert(Date(2000, 2, 7).daysInMonth == 29);
assert(Date(2000, 6, 4).daysInMonth == 30);
--------------------
+/
@property ubyte daysInMonth() const pure nothrow
{
return maxDay(_year, _month);
}
//Explicitly undocumented. Do not use. To be removed in March 2013.
deprecated("Please use daysInMonth instead.") @property ubyte endOfMonthDay() const nothrow
{
return maxDay(_year, _month);
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(1999, 1, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 2, 1).daysInMonth, 28);
_assertPred!"=="(Date(2000, 2, 1).daysInMonth, 29);
_assertPred!"=="(Date(1999, 3, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 4, 1).daysInMonth, 30);
_assertPred!"=="(Date(1999, 5, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 6, 1).daysInMonth, 30);
_assertPred!"=="(Date(1999, 7, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 8, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 9, 1).daysInMonth, 30);
_assertPred!"=="(Date(1999, 10, 1).daysInMonth, 31);
_assertPred!"=="(Date(1999, 11, 1).daysInMonth, 30);
_assertPred!"=="(Date(1999, 12, 1).daysInMonth, 31);
//Test B.C.
_assertPred!"=="(Date(-1999, 1, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 2, 1).daysInMonth, 28);
_assertPred!"=="(Date(-2000, 2, 1).daysInMonth, 29);
_assertPred!"=="(Date(-1999, 3, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 4, 1).daysInMonth, 30);
_assertPred!"=="(Date(-1999, 5, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 6, 1).daysInMonth, 30);
_assertPred!"=="(Date(-1999, 7, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 8, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 9, 1).daysInMonth, 30);
_assertPred!"=="(Date(-1999, 10, 1).daysInMonth, 31);
_assertPred!"=="(Date(-1999, 11, 1).daysInMonth, 30);
_assertPred!"=="(Date(-1999, 12, 1).daysInMonth, 31);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.daysInMonth = 30));
static assert(!__traits(compiles, idate.daysInMonth = 30));
//Verify Examples.
assert(Date(1999, 1, 6).daysInMonth == 31);
assert(Date(1999, 2, 7).daysInMonth == 28);
assert(Date(2000, 2, 7).daysInMonth == 29);
assert(Date(2000, 6, 4).daysInMonth == 30);
}
}
/++
Whether the current year is a date in A.D.
Examples:
--------------------
assert(Date(1, 1, 1).isAD);
assert(Date(2010, 12, 31).isAD);
assert(!Date(0, 12, 31).isAD);
assert(!Date(-2010, 1, 1).isAD);
--------------------
+/
@property bool isAD() const pure nothrow
{
return _year > 0;
}
unittest
{
version(testStdDateTime)
{
assert(Date(2010, 7, 4).isAD);
assert(Date(1, 1, 1).isAD);
assert(!Date(0, 1, 1).isAD);
assert(!Date(-1, 1, 1).isAD);
assert(!Date(-2010, 7, 4).isAD);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.isAD));
static assert(__traits(compiles, idate.isAD));
//Verify Examples.
assert(Date(1, 1, 1).isAD);
assert(Date(2010, 12, 31).isAD);
assert(!Date(0, 12, 31).isAD);
assert(!Date(-2010, 1, 1).isAD);
}
}
/++
The julian day for this $(D Date) at noon (since the julian day changes
at noon).
+/
@property long julianDay() const pure nothrow
{
return dayOfGregorianCal + 1_721_425;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date(-4713, 11, 24).julianDay, 0);
_assertPred!"=="(Date(0, 12, 31).julianDay, 1_721_425);
_assertPred!"=="(Date(1, 1, 1).julianDay, 1_721_426);
_assertPred!"=="(Date(1582, 10, 15).julianDay, 2_299_161);
_assertPred!"=="(Date(1858, 11, 17).julianDay, 2_400_001);
_assertPred!"=="(Date(1982, 1, 4).julianDay, 2_444_974);
_assertPred!"=="(Date(1996, 3, 31).julianDay, 2_450_174);
_assertPred!"=="(Date(2010, 8, 24).julianDay, 2_455_433);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.julianDay));
static assert(__traits(compiles, idate.julianDay));
}
}
/++
The modified julian day for any time on this date (since, the modified
julian day changes at midnight).
+/
@property long modJulianDay() const pure nothrow
{
return julianDay - 2_400_001;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date(1858, 11, 17).modJulianDay, 0);
_assertPred!"=="(Date(2010, 8, 24).modJulianDay, 55_432);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.modJulianDay));
static assert(__traits(compiles, idate.modJulianDay));
}
}
/++
Converts this $(D Date) to a string with the format YYYYMMDD.
Examples:
--------------------
assert(Date(2010, 7, 4).toISOString() == "20100704");
assert(Date(1998, 12, 25).toISOString() == "19981225");
assert(Date(0, 1, 5).toISOString() == "00000105");
assert(Date(-4, 1, 5).toISOString() == "-00040105");
--------------------
+/
string toISOString() const nothrow
{
try
{
if(_year >= 0)
{
if(_year < 10_000)
return format("%04d%02d%02d", _year, _month, _day);
else
return format("+%05d%02d%02d", _year, _month, _day);
}
else if(_year > -10_000)
return format("%05d%02d%02d", _year, _month, _day);
else
return format("%06d%02d%02d", _year, _month, _day);
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(9, 12, 4).toISOString(), "00091204");
_assertPred!"=="(Date(99, 12, 4).toISOString(), "00991204");
_assertPred!"=="(Date(999, 12, 4).toISOString(), "09991204");
_assertPred!"=="(Date(9999, 7, 4).toISOString(), "99990704");
_assertPred!"=="(Date(10000, 10, 20).toISOString(), "+100001020");
//Test B.C.
_assertPred!"=="(Date(0, 12, 4).toISOString(), "00001204");
_assertPred!"=="(Date(-9, 12, 4).toISOString(), "-00091204");
_assertPred!"=="(Date(-99, 12, 4).toISOString(), "-00991204");
_assertPred!"=="(Date(-999, 12, 4).toISOString(), "-09991204");
_assertPred!"=="(Date(-9999, 7, 4).toISOString(), "-99990704");
_assertPred!"=="(Date(-10000, 10, 20).toISOString(), "-100001020");
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.toISOString()));
static assert(__traits(compiles, idate.toISOString()));
//Verify Examples.
assert(Date(2010, 7, 4).toISOString() == "20100704");
assert(Date(1998, 12, 25).toISOString() == "19981225");
assert(Date(0, 1, 5).toISOString() == "00000105");
assert(Date(-4, 1, 5).toISOString() == "-00040105");
}
}
/++
Converts this $(D Date) to a string with the format YYYY-MM-DD.
Examples:
--------------------
assert(Date(2010, 7, 4).toISOExtString() == "2010-07-04");
assert(Date(1998, 12, 25).toISOExtString() == "1998-12-25");
assert(Date(0, 1, 5).toISOExtString() == "0000-01-05");
assert(Date(-4, 1, 5).toISOExtString() == "-0004-01-05");
--------------------
+/
string toISOExtString() const nothrow
{
try
{
if(_year >= 0)
{
if(_year < 10_000)
return format("%04d-%02d-%02d", _year, _month, _day);
else
return format("+%05d-%02d-%02d", _year, _month, _day);
}
else if(_year > -10_000)
return format("%05d-%02d-%02d", _year, _month, _day);
else
return format("%06d-%02d-%02d", _year, _month, _day);
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(9, 12, 4).toISOExtString(), "0009-12-04");
_assertPred!"=="(Date(99, 12, 4).toISOExtString(), "0099-12-04");
_assertPred!"=="(Date(999, 12, 4).toISOExtString(), "0999-12-04");
_assertPred!"=="(Date(9999, 7, 4).toISOExtString(), "9999-07-04");
_assertPred!"=="(Date(10000, 10, 20).toISOExtString(), "+10000-10-20");
//Test B.C.
_assertPred!"=="(Date(0, 12, 4).toISOExtString(), "0000-12-04");
_assertPred!"=="(Date(-9, 12, 4).toISOExtString(), "-0009-12-04");
_assertPred!"=="(Date(-99, 12, 4).toISOExtString(), "-0099-12-04");
_assertPred!"=="(Date(-999, 12, 4).toISOExtString(), "-0999-12-04");
_assertPred!"=="(Date(-9999, 7, 4).toISOExtString(), "-9999-07-04");
_assertPred!"=="(Date(-10000, 10, 20).toISOExtString(), "-10000-10-20");
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.toISOExtString()));
static assert(__traits(compiles, idate.toISOExtString()));
//Verify Examples.
assert(Date(2010, 7, 4).toISOExtString() == "2010-07-04");
assert(Date(1998, 12, 25).toISOExtString() == "1998-12-25");
assert(Date(0, 1, 5).toISOExtString() == "0000-01-05");
assert(Date(-4, 1, 5).toISOExtString() == "-0004-01-05");
}
}
/++
Converts this $(D Date) to a string with the format YYYY-Mon-DD.
Examples:
--------------------
assert(Date(2010, 7, 4).toSimpleString() == "2010-Jul-04");
assert(Date(1998, 12, 25).toSimpleString() == "1998-Dec-25");
assert(Date(0, 1, 5).toSimpleString() == "0000-Jan-05");
assert(Date(-4, 1, 5).toSimpleString() == "-0004-Jan-05");
--------------------
+/
string toSimpleString() const nothrow
{
try
{
if(_year >= 0)
{
if(_year < 10_000)
return format("%04d-%s-%02d", _year, monthToString(_month, false), _day);
else
return format("+%05d-%s-%02d", _year, monthToString(_month, false), _day);
}
else if(_year > -10_000)
return format("%05d-%s-%02d", _year, monthToString(_month, false), _day);
else
return format("%06d-%s-%02d", _year, monthToString(_month, false), _day);
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(Date(9, 12, 4).toSimpleString(), "0009-Dec-04");
_assertPred!"=="(Date(99, 12, 4).toSimpleString(), "0099-Dec-04");
_assertPred!"=="(Date(999, 12, 4).toSimpleString(), "0999-Dec-04");
_assertPred!"=="(Date(9999, 7, 4).toSimpleString(), "9999-Jul-04");
_assertPred!"=="(Date(10000, 10, 20).toSimpleString(), "+10000-Oct-20");
//Test B.C.
_assertPred!"=="(Date(0, 12, 4).toSimpleString(), "0000-Dec-04");
_assertPred!"=="(Date(-9, 12, 4).toSimpleString(), "-0009-Dec-04");
_assertPred!"=="(Date(-99, 12, 4).toSimpleString(), "-0099-Dec-04");
_assertPred!"=="(Date(-999, 12, 4).toSimpleString(), "-0999-Dec-04");
_assertPred!"=="(Date(-9999, 7, 4).toSimpleString(), "-9999-Jul-04");
_assertPred!"=="(Date(-10000, 10, 20).toSimpleString(), "-10000-Oct-20");
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, cdate.toSimpleString()));
static assert(__traits(compiles, idate.toSimpleString()));
//Verify Examples.
assert(Date(2010, 7, 4).toSimpleString() == "2010-Jul-04");
assert(Date(1998, 12, 25).toSimpleString() == "1998-Dec-25");
assert(Date(0, 1, 5).toSimpleString() == "0000-Jan-05");
assert(Date(-4, 1, 5).toSimpleString() == "-0004-Jan-05");
}
}
//TODO Add a function which returns a string in a user-specified format.
/+
Converts this $(D Date) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return toSimpleString();
}
/++
Converts this $(D Date) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return toSimpleString();
}
unittest
{
version(testStdDateTime)
{
auto date = Date(1999, 7, 6);
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(__traits(compiles, date.toString()));
static assert(__traits(compiles, cdate.toString()));
static assert(__traits(compiles, idate.toString()));
}
}
/++
Creates a $(D Date) from a string with the format YYYYMMDD. Whitespace
is stripped from the given string.
Params:
isoString = A string formatted in the ISO format for dates.
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D Date) would not be valid.
Examples:
--------------------
assert(Date.fromISOString("20100704") == Date(2010, 7, 4));
assert(Date.fromISOString("19981225") == Date(1998, 12, 25));
assert(Date.fromISOString("00000105") == Date(0, 1, 5));
assert(Date.fromISOString("-00040105") == Date(-4, 1, 5));
assert(Date.fromISOString(" 20100704 ") == Date(2010, 7, 4));
--------------------
+/
static Date fromISOString(S)(in S isoString)
if(isSomeString!S)
{
auto dstr = to!dstring(strip(isoString));
enforce(dstr.length >= 8, new DateTimeException(format("Invalid ISO String: %s", isoString)));
auto day = dstr[$-2 .. $];
auto month = dstr[$-4 .. $-2];
auto year = dstr[0 .. $-4];
enforce(!canFind!(not!isDigit)(day), new DateTimeException(format("Invalid ISO String: %s", isoString)));
enforce(!canFind!(not!isDigit)(month), new DateTimeException(format("Invalid ISO String: %s", isoString)));
if(year.length > 4)
{
enforce(year.startsWith("-") || year.startsWith("+"),
new DateTimeException(format("Invalid ISO String: %s", isoString)));
enforce(!canFind!(not!isDigit)(year[1..$]),
new DateTimeException(format("Invalid ISO String: %s", isoString)));
}
else
enforce(!canFind!(not!isDigit)(year), new DateTimeException(format("Invalid ISO String: %s", isoString)));
return Date(to!short(year), to!ubyte(month), to!ubyte(day));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(Date.fromISOString(""));
assertThrown!DateTimeException(Date.fromISOString("990704"));
assertThrown!DateTimeException(Date.fromISOString("0100704"));
assertThrown!DateTimeException(Date.fromISOString("2010070"));
assertThrown!DateTimeException(Date.fromISOString("2010070 "));
assertThrown!DateTimeException(Date.fromISOString("120100704"));
assertThrown!DateTimeException(Date.fromISOString("-0100704"));
assertThrown!DateTimeException(Date.fromISOString("+0100704"));
assertThrown!DateTimeException(Date.fromISOString("2010070a"));
assertThrown!DateTimeException(Date.fromISOString("20100a04"));
assertThrown!DateTimeException(Date.fromISOString("2010a704"));
assertThrown!DateTimeException(Date.fromISOString("99-07-04"));
assertThrown!DateTimeException(Date.fromISOString("010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0 "));
assertThrown!DateTimeException(Date.fromISOString("12010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("-010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("+010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0a"));
assertThrown!DateTimeException(Date.fromISOString("2010-0a-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-a7-04"));
assertThrown!DateTimeException(Date.fromISOString("2010/07/04"));
assertThrown!DateTimeException(Date.fromISOString("2010/7/04"));
assertThrown!DateTimeException(Date.fromISOString("2010/7/4"));
assertThrown!DateTimeException(Date.fromISOString("2010/07/4"));
assertThrown!DateTimeException(Date.fromISOString("2010-7-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-7-4"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-4"));
assertThrown!DateTimeException(Date.fromISOString("99Jul04"));
assertThrown!DateTimeException(Date.fromISOString("010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0 "));
assertThrown!DateTimeException(Date.fromISOString("12010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("-010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("+010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0a"));
assertThrown!DateTimeException(Date.fromISOString("2010Jua04"));
assertThrown!DateTimeException(Date.fromISOString("2010aul04"));
assertThrown!DateTimeException(Date.fromISOString("99-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0 "));
assertThrown!DateTimeException(Date.fromISOString("12010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("-010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("+010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0a"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jua-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jal-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-aul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-04"));
_assertPred!"=="(Date.fromISOString("19990706"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOString("-19990706"), Date(-1999, 7, 6));
_assertPred!"=="(Date.fromISOString("+019990706"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOString("19990706 "), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOString(" 19990706"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOString(" 19990706 "), Date(1999, 7, 6));
//Verify Examples.
assert(Date.fromISOString("20100704") == Date(2010, 7, 4));
assert(Date.fromISOString("19981225") == Date(1998, 12, 25));
assert(Date.fromISOString("00000105") == Date(0, 1, 5));
assert(Date.fromISOString("-00040105") == Date(-4, 1, 5));
assert(Date.fromISOString(" 20100704 ") == Date(2010, 7, 4));
}
}
/++
Creates a $(D Date) from a string with the format YYYY-MM-DD. Whitespace
is stripped from the given string.
Params:
isoExtString = A string formatted in the ISO Extended format for
dates.
Throws:
$(D DateTimeException) if the given string is not in the ISO
Extended format or if the resulting $(D Date) would not be valid.
Examples:
--------------------
assert(Date.fromISOExtString("2010-07-04") == Date(2010, 7, 4));
assert(Date.fromISOExtString("1998-12-25") == Date(1998, 12, 25));
assert(Date.fromISOExtString("0000-01-05") == Date(0, 1, 5));
assert(Date.fromISOExtString("-0004-01-05") == Date(-4, 1, 5));
assert(Date.fromISOExtString(" 2010-07-04 ") == Date(2010, 7, 4));
--------------------
+/
static Date fromISOExtString(S)(in S isoExtString)
if(isSomeString!(S))
{
auto dstr = to!dstring(strip(isoExtString));
enforce(dstr.length >= 10, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto day = dstr[$-2 .. $];
auto month = dstr[$-5 .. $-3];
auto year = dstr[0 .. $-6];
enforce(dstr[$-3] == '-', new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(dstr[$-6] == '-', new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(day),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(month),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
if(year.length > 4)
{
enforce(year.startsWith("-") || year.startsWith("+"),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(year[1..$]),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
}
else
enforce(!canFind!(not!isDigit)(year),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
return Date(to!short(year), to!ubyte(month), to!ubyte(day));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(Date.fromISOExtString(""));
assertThrown!DateTimeException(Date.fromISOExtString("990704"));
assertThrown!DateTimeException(Date.fromISOExtString("0100704"));
assertThrown!DateTimeException(Date.fromISOExtString("2010070"));
assertThrown!DateTimeException(Date.fromISOExtString("2010070 "));
assertThrown!DateTimeException(Date.fromISOExtString("120100704"));
assertThrown!DateTimeException(Date.fromISOExtString("-0100704"));
assertThrown!DateTimeException(Date.fromISOExtString("+0100704"));
assertThrown!DateTimeException(Date.fromISOExtString("2010070a"));
assertThrown!DateTimeException(Date.fromISOExtString("20100a04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010a704"));
assertThrown!DateTimeException(Date.fromISOExtString("99-07-04"));
assertThrown!DateTimeException(Date.fromISOExtString("010-07-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-07-0"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-07-0 "));
assertThrown!DateTimeException(Date.fromISOExtString("12010-07-04"));
assertThrown!DateTimeException(Date.fromISOExtString("-010-07-04"));
assertThrown!DateTimeException(Date.fromISOExtString("+010-07-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-07-0a"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-0a-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-a7-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010/07/04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010/7/04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010/7/4"));
assertThrown!DateTimeException(Date.fromISOExtString("2010/07/4"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-7-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-7-4"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-07-4"));
assertThrown!DateTimeException(Date.fromISOExtString("99Jul04"));
assertThrown!DateTimeException(Date.fromISOExtString("010Jul04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010Jul0"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jul-0 "));
assertThrown!DateTimeException(Date.fromISOExtString("12010Jul04"));
assertThrown!DateTimeException(Date.fromISOExtString("-010Jul04"));
assertThrown!DateTimeException(Date.fromISOExtString("+010Jul04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010Jul0a"));
assertThrown!DateTimeException(Date.fromISOExtString("2010Jua04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010aul04"));
assertThrown!DateTimeException(Date.fromISOExtString("99-Jul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jul-0"));
assertThrown!DateTimeException(Date.fromISOExtString("2010Jul0 "));
assertThrown!DateTimeException(Date.fromISOExtString("12010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("-010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("+010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jul-0a"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jua-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jal-04"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-aul-04"));
assertThrown!DateTimeException(Date.fromISOExtString("20100704"));
assertThrown!DateTimeException(Date.fromISOExtString("2010-Jul-04"));
_assertPred!"=="(Date.fromISOExtString("1999-07-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOExtString("-1999-07-06"), Date(-1999, 7, 6));
_assertPred!"=="(Date.fromISOExtString("+01999-07-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOExtString("1999-07-06 "), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOExtString(" 1999-07-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromISOExtString(" 1999-07-06 "), Date(1999, 7, 6));
//Verify Examples.
assert(Date.fromISOExtString("2010-07-04") == Date(2010, 7, 4));
assert(Date.fromISOExtString("1998-12-25") == Date(1998, 12, 25));
assert(Date.fromISOExtString("0000-01-05") == Date(0, 1, 5));
assert(Date.fromISOExtString("-0004-01-05") == Date(-4, 1, 5));
assert(Date.fromISOExtString(" 2010-07-04 ") == Date(2010, 7, 4));
}
}
/++
Creates a $(D Date) from a string with the format YYYY-Mon-DD.
Whitespace is stripped from the given string.
Params:
simpleString = A string formatted in the way that toSimpleString
formats dates.
Throws:
$(D DateTimeException) if the given string is not in the correct
format or if the resulting $(D Date) would not be valid.
Examples:
--------------------
assert(Date.fromSimpleString("2010-Jul-04") == Date(2010, 7, 4));
assert(Date.fromSimpleString("1998-Dec-25") == Date(1998, 12, 25));
assert(Date.fromSimpleString("0000-Jan-05") == Date(0, 1, 5));
assert(Date.fromSimpleString("-0004-Jan-05") == Date(-4, 1, 5));
assert(Date.fromSimpleString(" 2010-Jul-04 ") == Date(2010, 7, 4));
--------------------
+/
static Date fromSimpleString(S)(in S simpleString)
if(isSomeString!(S))
{
auto dstr = to!dstring(strip(simpleString));
enforce(dstr.length >= 11, new DateTimeException(format("Invalid string format: %s", simpleString)));
auto day = dstr[$-2 .. $];
auto month = monthFromString(to!string(dstr[$-6 .. $-3]));
auto year = dstr[0 .. $-7];
enforce(dstr[$-3] == '-', new DateTimeException(format("Invalid string format: %s", simpleString)));
enforce(dstr[$-7] == '-', new DateTimeException(format("Invalid string format: %s", simpleString)));
enforce(!canFind!(not!isDigit)(day), new DateTimeException(format("Invalid string format: %s", simpleString)));
if(year.length > 4)
{
enforce(year.startsWith("-") || year.startsWith("+"),
new DateTimeException(format("Invalid string format: %s", simpleString)));
enforce(!canFind!(not!isDigit)(year[1..$]),
new DateTimeException(format("Invalid string format: %s", simpleString)));
}
else
enforce(!canFind!(not!isDigit)(year),
new DateTimeException(format("Invalid string format: %s", simpleString)));
return Date(to!short(year), month, to!ubyte(day));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(Date.fromSimpleString(""));
assertThrown!DateTimeException(Date.fromSimpleString("990704"));
assertThrown!DateTimeException(Date.fromSimpleString("0100704"));
assertThrown!DateTimeException(Date.fromSimpleString("2010070"));
assertThrown!DateTimeException(Date.fromSimpleString("2010070 "));
assertThrown!DateTimeException(Date.fromSimpleString("120100704"));
assertThrown!DateTimeException(Date.fromSimpleString("-0100704"));
assertThrown!DateTimeException(Date.fromSimpleString("+0100704"));
assertThrown!DateTimeException(Date.fromSimpleString("2010070a"));
assertThrown!DateTimeException(Date.fromSimpleString("20100a04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010a704"));
assertThrown!DateTimeException(Date.fromSimpleString("99-07-04"));
assertThrown!DateTimeException(Date.fromSimpleString("010-07-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-07-0"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-07-0 "));
assertThrown!DateTimeException(Date.fromSimpleString("12010-07-04"));
assertThrown!DateTimeException(Date.fromSimpleString("-010-07-04"));
assertThrown!DateTimeException(Date.fromSimpleString("+010-07-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-07-0a"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-0a-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-a7-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010/07/04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010/7/04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010/7/4"));
assertThrown!DateTimeException(Date.fromSimpleString("2010/07/4"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-7-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-7-4"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-07-4"));
assertThrown!DateTimeException(Date.fromSimpleString("99Jul04"));
assertThrown!DateTimeException(Date.fromSimpleString("010Jul04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010Jul0"));
assertThrown!DateTimeException(Date.fromSimpleString("2010Jul0 "));
assertThrown!DateTimeException(Date.fromSimpleString("12010Jul04"));
assertThrown!DateTimeException(Date.fromSimpleString("-010Jul04"));
assertThrown!DateTimeException(Date.fromSimpleString("+010Jul04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010Jul0a"));
assertThrown!DateTimeException(Date.fromSimpleString("2010Jua04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010aul04"));
assertThrown!DateTimeException(Date.fromSimpleString("99-Jul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("010-Jul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-Jul-0"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-Jul-0 "));
assertThrown!DateTimeException(Date.fromSimpleString("12010-Jul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("-010-Jul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("+010-Jul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-Jul-0a"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-Jua-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-Jal-04"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-aul-04"));
assertThrown!DateTimeException(Date.fromSimpleString("20100704"));
assertThrown!DateTimeException(Date.fromSimpleString("2010-07-04"));
_assertPred!"=="(Date.fromSimpleString("1999-Jul-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromSimpleString("-1999-Jul-06"), Date(-1999, 7, 6));
_assertPred!"=="(Date.fromSimpleString("+01999-Jul-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromSimpleString("1999-Jul-06 "), Date(1999, 7, 6));
_assertPred!"=="(Date.fromSimpleString(" 1999-Jul-06"), Date(1999, 7, 6));
_assertPred!"=="(Date.fromSimpleString(" 1999-Jul-06 "), Date(1999, 7, 6));
//Verify Examples.
assert(Date.fromSimpleString("2010-Jul-04") == Date(2010, 7, 4));
assert(Date.fromSimpleString("1998-Dec-25") == Date(1998, 12, 25));
assert(Date.fromSimpleString("0000-Jan-05") == Date(0, 1, 5));
assert(Date.fromSimpleString("-0004-Jan-05") == Date(-4, 1, 5));
assert(Date.fromSimpleString(" 2010-Jul-04 ") == Date(2010, 7, 4));
}
}
//TODO Add function which takes a user-specified time format and produces a Date
//TODO Add function which takes pretty much any time-string and produces a Date
// Obviously, it will be less efficient, and it probably won't manage _every_
// possible date format, but a smart conversion function would be nice.
/++
Returns the $(D Date) farthest in the past which is representable by
$(D Date).
+/
@property static Date min() pure nothrow
{
auto date = Date.init;
date._year = short.min;
date._month = Month.jan;
date._day = 1;
return date;
}
unittest
{
version(testStdDateTime)
{
assert(Date.min.year < 0);
assert(Date.min < Date.max);
}
}
/++
Returns the $(D Date) farthest in the future which is representable by
$(D Date).
+/
@property static Date max() pure nothrow
{
auto date = Date.init;
date._year = short.max;
date._month = Month.dec;
date._day = 31;
return date;
}
unittest
{
version(testStdDateTime)
{
assert(Date.max.year > 0);
assert(Date.max > Date.min);
}
}
private:
/+
Whether the given values form a valid date.
Params:
year = The year to test.
month = The month of the Gregorian Calendar to test.
day = The day of the month to test.
+/
static bool _valid(int year, int month, int day) pure nothrow
{
if(!valid!"months"(month))
return false;
return valid!"days"(year, month, day);
}
/+
Adds the given number of days to this $(D Date). A negative number will
subtract.
The month will be adjusted along with the day if the number of days
added (or subtracted) would overflow (or underflow) the current month.
The year will be adjusted along with the month if the increase (or
decrease) to the month would cause it to overflow (or underflow) the
current year.
$(D addDays(numDays)) is effectively equivalent to
$(D date.dayOfGregorianCal = date.dayOfGregorianCal + days).
Params:
days = The number of days to add to this Date.
+/
ref Date addDays(long days) pure nothrow
{
dayOfGregorianCal = cast(int)(dayOfGregorianCal + days);
return this;
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
{
auto date = Date(1999, 2, 28);
date.addDays(1);
_assertPred!"=="(date, Date(1999, 3, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(1999, 2, 28));
}
{
auto date = Date(2000, 2, 28);
date.addDays(1);
_assertPred!"=="(date, Date(2000, 2, 29));
date.addDays(1);
_assertPred!"=="(date, Date(2000, 3, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(2000, 2, 29));
}
{
auto date = Date(1999, 6, 30);
date.addDays(1);
_assertPred!"=="(date, Date(1999, 7, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(1999, 6, 30));
}
{
auto date = Date(1999, 7, 31);
date.addDays(1);
_assertPred!"=="(date, Date(1999, 8, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(1999, 7, 31));
}
{
auto date = Date(1999, 1, 1);
date.addDays(-1);
_assertPred!"=="(date, Date(1998, 12, 31));
date.addDays(1);
_assertPred!"=="(date, Date(1999, 1, 1));
}
{
auto date = Date(1999, 7, 6);
date.addDays(9);
_assertPred!"=="(date, Date(1999, 7, 15));
date.addDays(-11);
_assertPred!"=="(date, Date(1999, 7, 4));
date.addDays(30);
_assertPred!"=="(date, Date(1999, 8, 3));
date.addDays(-3);
_assertPred!"=="(date, Date(1999, 7, 31));
}
{
auto date = Date(1999, 7, 6);
date.addDays(365);
_assertPred!"=="(date, Date(2000, 7, 5));
date.addDays(-365);
_assertPred!"=="(date, Date(1999, 7, 6));
date.addDays(366);
_assertPred!"=="(date, Date(2000, 7, 6));
date.addDays(730);
_assertPred!"=="(date, Date(2002, 7, 6));
date.addDays(-1096);
_assertPred!"=="(date, Date(1999, 7, 6));
}
//Test B.C.
{
auto date = Date(-1999, 2, 28);
date.addDays(1);
_assertPred!"=="(date, Date(-1999, 3, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(-1999, 2, 28));
}
{
auto date = Date(-2000, 2, 28);
date.addDays(1);
_assertPred!"=="(date, Date(-2000, 2, 29));
date.addDays(1);
_assertPred!"=="(date, Date(-2000, 3, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(-2000, 2, 29));
}
{
auto date = Date(-1999, 6, 30);
date.addDays(1);
_assertPred!"=="(date, Date(-1999, 7, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(-1999, 6, 30));
}
{
auto date = Date(-1999, 7, 31);
date.addDays(1);
_assertPred!"=="(date, Date(-1999, 8, 1));
date.addDays(-1);
_assertPred!"=="(date, Date(-1999, 7, 31));
}
{
auto date = Date(-1999, 1, 1);
date.addDays(-1);
_assertPred!"=="(date, Date(-2000, 12, 31));
date.addDays(1);
_assertPred!"=="(date, Date(-1999, 1, 1));
}
{
auto date = Date(-1999, 7, 6);
date.addDays(9);
_assertPred!"=="(date, Date(-1999, 7, 15));
date.addDays(-11);
_assertPred!"=="(date, Date(-1999, 7, 4));
date.addDays(30);
_assertPred!"=="(date, Date(-1999, 8, 3));
date.addDays(-3);
}
{
auto date = Date(-1999, 7, 6);
date.addDays(365);
_assertPred!"=="(date, Date(-1998, 7, 6));
date.addDays(-365);
_assertPred!"=="(date, Date(-1999, 7, 6));
date.addDays(366);
_assertPred!"=="(date, Date(-1998, 7, 7));
date.addDays(730);
_assertPred!"=="(date, Date(-1996, 7, 6));
date.addDays(-1096);
_assertPred!"=="(date, Date(-1999, 7, 6));
}
//Test Both
{
auto date = Date(1, 7, 6);
date.addDays(-365);
_assertPred!"=="(date, Date(0, 7, 6));
date.addDays(365);
_assertPred!"=="(date, Date(1, 7, 6));
date.addDays(-731);
_assertPred!"=="(date, Date(-1, 7, 6));
date.addDays(730);
_assertPred!"=="(date, Date(1, 7, 5));
}
const cdate = Date(1999, 7, 6);
immutable idate = Date(1999, 7, 6);
static assert(!__traits(compiles, cdate.addDays(12)));
static assert(!__traits(compiles, idate.addDays(12)));
}
}
pure invariant()
{
assert(valid!"months"(_month), "Invariant Failure: year [" ~
numToString(_year) ~
"] month [" ~
numToString(_month) ~
"] day [" ~
numToString(_day) ~
"]");
assert(valid!"days"(_year, _month, _day), "Invariant Failure: year [" ~
numToString(_year) ~
"] month [" ~
numToString(_month) ~
"] day [" ~
numToString(_day) ~
"]");
}
short _year = 1;
Month _month = Month.jan;
ubyte _day = 1;
}
/++
Represents a time of day with hours, minutes, and seconds. It uses 24 hour
time.
+/
struct TimeOfDay
{
public:
/++
Params:
hour = Hour of the day [0 - 24$(RPAREN).
minute = Minute of the hour [0 - 60$(RPAREN).
second = Second of the minute [0 - 60$(RPAREN).
Throws:
$(D DateTimeException) if the resulting $(D TimeOfDay) would be not
be valid.
+/
this(int hour, int minute, int second = 0) pure
{
enforceValid!"hours"(hour);
enforceValid!"minutes"(minute);
enforceValid!"seconds"(second);
_hour = cast(ubyte)hour;
_minute = cast(ubyte)minute;
_second = cast(ubyte)second;
}
unittest
{
version(testStdDateTime)
{
assert(TimeOfDay(0, 0) == TimeOfDay.init);
{
auto tod = TimeOfDay(0, 0);
_assertPred!"=="(tod._hour, 0);
_assertPred!"=="(tod._minute, 0);
_assertPred!"=="(tod._second, 0);
}
{
auto tod = TimeOfDay(12, 30, 33);
_assertPred!"=="(tod._hour, 12);
_assertPred!"=="(tod._minute, 30);
_assertPred!"=="(tod._second, 33);
}
{
auto tod = TimeOfDay(23, 59, 59);
_assertPred!"=="(tod._hour, 23);
_assertPred!"=="(tod._minute, 59);
_assertPred!"=="(tod._second, 59);
}
assertThrown!DateTimeException(TimeOfDay(24, 0, 0));
assertThrown!DateTimeException(TimeOfDay(0, 60, 0));
assertThrown!DateTimeException(TimeOfDay(0, 0, 60));
}
}
/++
Compares this $(D TimeOfDay) with the given $(D TimeOfDay).
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
+/
int opCmp(in TimeOfDay rhs) const pure nothrow
{
if(_hour < rhs._hour)
return -1;
if(_hour > rhs._hour)
return 1;
if(_minute < rhs._minute)
return -1;
if(_minute > rhs._minute)
return 1;
if(_second < rhs._second)
return -1;
if(_second > rhs._second)
return 1;
return 0;
}
unittest
{
version(testStdDateTime)
{
_assertPred!("opCmp", "==")(TimeOfDay(0, 0, 0), TimeOfDay.init);
_assertPred!("opCmp", "==")(TimeOfDay(0, 0, 0), TimeOfDay(0, 0, 0));
_assertPred!("opCmp", "==")(TimeOfDay(12, 0, 0), TimeOfDay(12, 0, 0));
_assertPred!("opCmp", "==")(TimeOfDay(0, 30, 0), TimeOfDay(0, 30, 0));
_assertPred!("opCmp", "==")(TimeOfDay(0, 0, 33), TimeOfDay(0, 0, 33));
_assertPred!("opCmp", "==")(TimeOfDay(12, 30, 0), TimeOfDay(12, 30, 0));
_assertPred!("opCmp", "==")(TimeOfDay(12, 30, 33), TimeOfDay(12, 30, 33));
_assertPred!("opCmp", "==")(TimeOfDay(0, 30, 33), TimeOfDay(0, 30, 33));
_assertPred!("opCmp", "==")(TimeOfDay(0, 0, 33), TimeOfDay(0, 0, 33));
_assertPred!("opCmp", "<")(TimeOfDay(12, 30, 33), TimeOfDay(13, 30, 33));
_assertPred!("opCmp", ">")(TimeOfDay(13, 30, 33), TimeOfDay(12, 30, 33));
_assertPred!("opCmp", "<")(TimeOfDay(12, 30, 33), TimeOfDay(12, 31, 33));
_assertPred!("opCmp", ">")(TimeOfDay(12, 31, 33), TimeOfDay(12, 30, 33));
_assertPred!("opCmp", "<")(TimeOfDay(12, 30, 33), TimeOfDay(12, 30, 34));
_assertPred!("opCmp", ">")(TimeOfDay(12, 30, 34), TimeOfDay(12, 30, 33));
_assertPred!("opCmp", ">")(TimeOfDay(13, 30, 33), TimeOfDay(12, 30, 34));
_assertPred!("opCmp", "<")(TimeOfDay(12, 30, 34), TimeOfDay(13, 30, 33));
_assertPred!("opCmp", ">")(TimeOfDay(13, 30, 33), TimeOfDay(12, 31, 33));
_assertPred!("opCmp", "<")(TimeOfDay(12, 31, 33), TimeOfDay(13, 30, 33));
_assertPred!("opCmp", ">")(TimeOfDay(12, 31, 33), TimeOfDay(12, 30, 34));
_assertPred!("opCmp", "<")(TimeOfDay(12, 30, 34), TimeOfDay(12, 31, 33));
const ctod = TimeOfDay(12, 30, 33);
immutable itod = TimeOfDay(12, 30, 33);
static assert(__traits(compiles, ctod.opCmp(itod)));
static assert(__traits(compiles, itod.opCmp(ctod)));
}
}
/++
Hours passed midnight.
+/
@property ubyte hour() const pure nothrow
{
return _hour;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(TimeOfDay.init.hour, 0);
_assertPred!"=="(TimeOfDay(12, 0, 0).hour, 12);
const ctod = TimeOfDay(12, 0, 0);
immutable itod = TimeOfDay(12, 0, 0);
static assert(__traits(compiles, ctod.hour == 12));
static assert(__traits(compiles, itod.hour == 12));
}
}
/++
Hours passed midnight.
Params:
hour = The hour of the day to set this $(D TimeOfDay)'s hour to.
Throws:
$(D DateTimeException) if the given hour would result in an invalid
$(D TimeOfDay).
+/
@property void hour(int hour) pure
{
enforceValid!"hours"(hour);
_hour = cast(ubyte)hour;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){TimeOfDay(0, 0, 0).hour = 24;}());
auto tod = TimeOfDay(0, 0, 0);
tod.hour = 12;
_assertPred!"=="(tod, TimeOfDay(12, 0, 0));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.hour = 12));
static assert(!__traits(compiles, itod.hour = 12));
}
}
/++
Minutes passed the hour.
+/
@property ubyte minute() const pure nothrow
{
return _minute;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(TimeOfDay.init.minute, 0);
_assertPred!"=="(TimeOfDay(0, 30, 0).minute, 30);
const ctod = TimeOfDay(0, 30, 0);
immutable itod = TimeOfDay(0, 30, 0);
static assert(__traits(compiles, ctod.minute == 30));
static assert(__traits(compiles, itod.minute == 30));
}
}
/++
Minutes passed the hour.
Params:
minute = The minute to set this $(D TimeOfDay)'s minute to.
Throws:
$(D DateTimeException) if the given minute would result in an
invalid $(D TimeOfDay).
+/
@property void minute(int minute) pure
{
enforceValid!"minutes"(minute);
_minute = cast(ubyte)minute;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){TimeOfDay(0, 0, 0).minute = 60;}());
auto tod = TimeOfDay(0, 0, 0);
tod.minute = 30;
_assertPred!"=="(tod, TimeOfDay(0, 30, 0));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.minute = 30));
static assert(!__traits(compiles, itod.minute = 30));
}
}
/++
Seconds passed the minute.
+/
@property ubyte second() const pure nothrow
{
return _second;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(TimeOfDay.init.second, 0);
_assertPred!"=="(TimeOfDay(0, 0, 33).second, 33);
const ctod = TimeOfDay(0, 0, 33);
immutable itod = TimeOfDay(0, 0, 33);
static assert(__traits(compiles, ctod.second == 33));
static assert(__traits(compiles, itod.second == 33));
}
}
/++
Seconds passed the minute.
Params:
second = The second to set this $(D TimeOfDay)'s second to.
Throws:
$(D DateTimeException) if the given second would result in an
invalid $(D TimeOfDay).
+/
@property void second(int second) pure
{
enforceValid!"seconds"(second);
_second = cast(ubyte)second;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){TimeOfDay(0, 0, 0).second = 60;}());
auto tod = TimeOfDay(0, 0, 0);
tod.second = 33;
_assertPred!"=="(tod, TimeOfDay(0, 0, 33));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.second = 33));
static assert(!__traits(compiles, itod.second = 33));
}
}
/++
Adds the given number of units to this $(D TimeOfDay). A negative number
will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. For instance, rolling a $(D TimeOfDay)
one hours's worth of minutes gets the exact same
$(D TimeOfDay).
Accepted units are $(D "hours"), $(D "minutes"), and $(D "seconds").
Params:
units = The units to add.
value = The number of $(D_PARAM units) to add to this
$(D TimeOfDay).
Examples:
--------------------
auto tod1 = TimeOfDay(7, 12, 0);
tod1.roll!"hours"(1);
assert(tod1 == TimeOfDay(8, 12, 0));
auto tod2 = TimeOfDay(7, 12, 0);
tod2.roll!"hours"(-1);
assert(tod2 == TimeOfDay(6, 12, 0));
auto tod3 = TimeOfDay(23, 59, 0);
tod3.roll!"minutes"(1);
assert(tod3 == TimeOfDay(23, 0, 0));
auto tod4 = TimeOfDay(0, 0, 0);
tod4.roll!"minutes"(-1);
assert(tod4 == TimeOfDay(0, 59, 0));
auto tod5 = TimeOfDay(23, 59, 59);
tod5.roll!"seconds"(1);
assert(tod5 == TimeOfDay(23, 59, 0));
auto tod6 = TimeOfDay(0, 0, 0);
tod6.roll!"seconds"(-1);
assert(tod6 == TimeOfDay(0, 0, 59));
--------------------
+/
/+ref TimeOfDay+/ void roll(string units)(long value) pure nothrow
if(units == "hours")
{
this += dur!"hours"(value);
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto tod1 = TimeOfDay(7, 12, 0);
tod1.roll!"hours"(1);
assert(tod1 == TimeOfDay(8, 12, 0));
auto tod2 = TimeOfDay(7, 12, 0);
tod2.roll!"hours"(-1);
assert(tod2 == TimeOfDay(6, 12, 0));
auto tod3 = TimeOfDay(23, 59, 0);
tod3.roll!"minutes"(1);
assert(tod3 == TimeOfDay(23, 0, 0));
auto tod4 = TimeOfDay(0, 0, 0);
tod4.roll!"minutes"(-1);
assert(tod4 == TimeOfDay(0, 59, 0));
auto tod5 = TimeOfDay(23, 59, 59);
tod5.roll!"seconds"(1);
assert(tod5 == TimeOfDay(23, 59, 0));
auto tod6 = TimeOfDay(0, 0, 0);
tod6.roll!"seconds"(-1);
assert(tod6 == TimeOfDay(0, 0, 59));
}
}
unittest
{
version(testStdDateTime)
{
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.roll!"hours"(53)));
static assert(!__traits(compiles, itod.roll!"hours"(53)));
}
}
//Shares documentation with "hours" version.
/+ref TimeOfDay+/ void roll(string units)(long value) pure nothrow
if(units == "minutes" ||
units == "seconds")
{
static if(units == "minutes")
enum memberVarStr = "minute";
else static if(units == "seconds")
enum memberVarStr = "second";
else
static assert(0);
value %= 60;
mixin("auto newVal = cast(ubyte)(_" ~ memberVarStr ~ ") + value;");
if(value < 0)
{
if(newVal < 0)
newVal += 60;
}
else if(newVal >= 60)
newVal -= 60;
mixin("_" ~ memberVarStr ~ " = cast(ubyte)newVal;");
}
//Test roll!"minutes"().
unittest
{
version(testStdDateTime)
{
static void testTOD(TimeOfDay orig, int minutes, in TimeOfDay expected, size_t line = __LINE__)
{
orig.roll!"minutes"(minutes);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
testTOD(TimeOfDay(12, 30, 33), 0, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 1, TimeOfDay(12, 31, 33));
testTOD(TimeOfDay(12, 30, 33), 2, TimeOfDay(12, 32, 33));
testTOD(TimeOfDay(12, 30, 33), 3, TimeOfDay(12, 33, 33));
testTOD(TimeOfDay(12, 30, 33), 4, TimeOfDay(12, 34, 33));
testTOD(TimeOfDay(12, 30, 33), 5, TimeOfDay(12, 35, 33));
testTOD(TimeOfDay(12, 30, 33), 10, TimeOfDay(12, 40, 33));
testTOD(TimeOfDay(12, 30, 33), 15, TimeOfDay(12, 45, 33));
testTOD(TimeOfDay(12, 30, 33), 29, TimeOfDay(12, 59, 33));
testTOD(TimeOfDay(12, 30, 33), 30, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), 45, TimeOfDay(12, 15, 33));
testTOD(TimeOfDay(12, 30, 33), 60, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 75, TimeOfDay(12, 45, 33));
testTOD(TimeOfDay(12, 30, 33), 90, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), 100, TimeOfDay(12, 10, 33));
testTOD(TimeOfDay(12, 30, 33), 689, TimeOfDay(12, 59, 33));
testTOD(TimeOfDay(12, 30, 33), 690, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), 691, TimeOfDay(12, 1, 33));
testTOD(TimeOfDay(12, 30, 33), 960, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 1439, TimeOfDay(12, 29, 33));
testTOD(TimeOfDay(12, 30, 33), 1440, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 1441, TimeOfDay(12, 31, 33));
testTOD(TimeOfDay(12, 30, 33), 2880, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -1, TimeOfDay(12, 29, 33));
testTOD(TimeOfDay(12, 30, 33), -2, TimeOfDay(12, 28, 33));
testTOD(TimeOfDay(12, 30, 33), -3, TimeOfDay(12, 27, 33));
testTOD(TimeOfDay(12, 30, 33), -4, TimeOfDay(12, 26, 33));
testTOD(TimeOfDay(12, 30, 33), -5, TimeOfDay(12, 25, 33));
testTOD(TimeOfDay(12, 30, 33), -10, TimeOfDay(12, 20, 33));
testTOD(TimeOfDay(12, 30, 33), -15, TimeOfDay(12, 15, 33));
testTOD(TimeOfDay(12, 30, 33), -29, TimeOfDay(12, 1, 33));
testTOD(TimeOfDay(12, 30, 33), -30, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), -45, TimeOfDay(12, 45, 33));
testTOD(TimeOfDay(12, 30, 33), -60, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -75, TimeOfDay(12, 15, 33));
testTOD(TimeOfDay(12, 30, 33), -90, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), -100, TimeOfDay(12, 50, 33));
testTOD(TimeOfDay(12, 30, 33), -749, TimeOfDay(12, 1, 33));
testTOD(TimeOfDay(12, 30, 33), -750, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 30, 33), -751, TimeOfDay(12, 59, 33));
testTOD(TimeOfDay(12, 30, 33), -960, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -1439, TimeOfDay(12, 31, 33));
testTOD(TimeOfDay(12, 30, 33), -1440, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -1441, TimeOfDay(12, 29, 33));
testTOD(TimeOfDay(12, 30, 33), -2880, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 0, 33), 1, TimeOfDay(12, 1, 33));
testTOD(TimeOfDay(12, 0, 33), 0, TimeOfDay(12, 0, 33));
testTOD(TimeOfDay(12, 0, 33), -1, TimeOfDay(12, 59, 33));
testTOD(TimeOfDay(11, 59, 33), 1, TimeOfDay(11, 0, 33));
testTOD(TimeOfDay(11, 59, 33), 0, TimeOfDay(11, 59, 33));
testTOD(TimeOfDay(11, 59, 33), -1, TimeOfDay(11, 58, 33));
testTOD(TimeOfDay(0, 0, 33), 1, TimeOfDay(0, 1, 33));
testTOD(TimeOfDay(0, 0, 33), 0, TimeOfDay(0, 0, 33));
testTOD(TimeOfDay(0, 0, 33), -1, TimeOfDay(0, 59, 33));
testTOD(TimeOfDay(23, 59, 33), 1, TimeOfDay(23, 0, 33));
testTOD(TimeOfDay(23, 59, 33), 0, TimeOfDay(23, 59, 33));
testTOD(TimeOfDay(23, 59, 33), -1, TimeOfDay(23, 58, 33));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.roll!"minutes"(7)));
static assert(!__traits(compiles, itod.roll!"minutes"(7)));
//Verify Examples.
auto tod1 = TimeOfDay(7, 12, 0);
tod1.roll!"minutes"(1);
assert(tod1 == TimeOfDay(7, 13, 0));
auto tod2 = TimeOfDay(7, 12, 0);
tod2.roll!"minutes"(-1);
assert(tod2 == TimeOfDay(7, 11, 0));
auto tod3 = TimeOfDay(23, 59, 0);
tod3.roll!"minutes"(1);
assert(tod3 == TimeOfDay(23, 0, 0));
auto tod4 = TimeOfDay(0, 0, 0);
tod4.roll!"minutes"(-1);
assert(tod4 == TimeOfDay(0, 59, 0));
auto tod5 = TimeOfDay(7, 32, 12);
tod5.roll!"seconds"(1);
assert(tod5 == TimeOfDay(7, 32, 13));
auto tod6 = TimeOfDay(7, 32, 12);
tod6.roll!"seconds"(-1);
assert(tod6 == TimeOfDay(7, 32, 11));
auto tod7 = TimeOfDay(23, 59, 59);
tod7.roll!"seconds"(1);
assert(tod7 == TimeOfDay(23, 59, 0));
auto tod8 = TimeOfDay(0, 0, 0);
tod8.roll!"seconds"(-1);
assert(tod8 == TimeOfDay(0, 0, 59));
}
}
//Test roll!"seconds"().
unittest
{
version(testStdDateTime)
{
static void testTOD(TimeOfDay orig, int seconds, in TimeOfDay expected, size_t line = __LINE__)
{
orig.roll!"seconds"(seconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
testTOD(TimeOfDay(12, 30, 33), 0, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 1, TimeOfDay(12, 30, 34));
testTOD(TimeOfDay(12, 30, 33), 2, TimeOfDay(12, 30, 35));
testTOD(TimeOfDay(12, 30, 33), 3, TimeOfDay(12, 30, 36));
testTOD(TimeOfDay(12, 30, 33), 4, TimeOfDay(12, 30, 37));
testTOD(TimeOfDay(12, 30, 33), 5, TimeOfDay(12, 30, 38));
testTOD(TimeOfDay(12, 30, 33), 10, TimeOfDay(12, 30, 43));
testTOD(TimeOfDay(12, 30, 33), 15, TimeOfDay(12, 30, 48));
testTOD(TimeOfDay(12, 30, 33), 26, TimeOfDay(12, 30, 59));
testTOD(TimeOfDay(12, 30, 33), 27, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 33), 30, TimeOfDay(12, 30, 3));
testTOD(TimeOfDay(12, 30, 33), 59, TimeOfDay(12, 30, 32));
testTOD(TimeOfDay(12, 30, 33), 60, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 61, TimeOfDay(12, 30, 34));
testTOD(TimeOfDay(12, 30, 33), 1766, TimeOfDay(12, 30, 59));
testTOD(TimeOfDay(12, 30, 33), 1767, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 33), 1768, TimeOfDay(12, 30, 1));
testTOD(TimeOfDay(12, 30, 33), 2007, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 33), 3599, TimeOfDay(12, 30, 32));
testTOD(TimeOfDay(12, 30, 33), 3600, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 3601, TimeOfDay(12, 30, 34));
testTOD(TimeOfDay(12, 30, 33), 7200, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -1, TimeOfDay(12, 30, 32));
testTOD(TimeOfDay(12, 30, 33), -2, TimeOfDay(12, 30, 31));
testTOD(TimeOfDay(12, 30, 33), -3, TimeOfDay(12, 30, 30));
testTOD(TimeOfDay(12, 30, 33), -4, TimeOfDay(12, 30, 29));
testTOD(TimeOfDay(12, 30, 33), -5, TimeOfDay(12, 30, 28));
testTOD(TimeOfDay(12, 30, 33), -10, TimeOfDay(12, 30, 23));
testTOD(TimeOfDay(12, 30, 33), -15, TimeOfDay(12, 30, 18));
testTOD(TimeOfDay(12, 30, 33), -33, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 33), -34, TimeOfDay(12, 30, 59));
testTOD(TimeOfDay(12, 30, 33), -35, TimeOfDay(12, 30, 58));
testTOD(TimeOfDay(12, 30, 33), -59, TimeOfDay(12, 30, 34));
testTOD(TimeOfDay(12, 30, 33), -60, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -61, TimeOfDay(12, 30, 32));
testTOD(TimeOfDay(12, 30, 0), 1, TimeOfDay(12, 30, 1));
testTOD(TimeOfDay(12, 30, 0), 0, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 0), -1, TimeOfDay(12, 30, 59));
testTOD(TimeOfDay(12, 0, 0), 1, TimeOfDay(12, 0, 1));
testTOD(TimeOfDay(12, 0, 0), 0, TimeOfDay(12, 0, 0));
testTOD(TimeOfDay(12, 0, 0), -1, TimeOfDay(12, 0, 59));
testTOD(TimeOfDay(0, 0, 0), 1, TimeOfDay(0, 0, 1));
testTOD(TimeOfDay(0, 0, 0), 0, TimeOfDay(0, 0, 0));
testTOD(TimeOfDay(0, 0, 0), -1, TimeOfDay(0, 0, 59));
testTOD(TimeOfDay(23, 59, 59), 1, TimeOfDay(23, 59, 0));
testTOD(TimeOfDay(23, 59, 59), 0, TimeOfDay(23, 59, 59));
testTOD(TimeOfDay(23, 59, 59), -1, TimeOfDay(23, 59, 58));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.roll!"seconds"(7)));
static assert(!__traits(compiles, itod.roll!"seconds"(7)));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D TimeOfDay).
The legal types of arithmetic for $(D TimeOfDay) using this operator are
$(BOOKTABLE,
$(TR $(TD TimeOfDay) $(TD +) $(TD duration) $(TD -->) $(TD TimeOfDay))
$(TR $(TD TimeOfDay) $(TD -) $(TD duration) $(TD -->) $(TD TimeOfDay))
)
Params:
duration = The duration to add to or subtract from this
$(D TimeOfDay).
+/
TimeOfDay opBinary(string op, D)(in D duration) const pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
TimeOfDay retval = this;
static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
immutable hnsecs = duration.hnsecs;
//Ideally, this would just be
//return retval.addSeconds(convert!("hnsecs", "seconds")(unaryFun!(op ~ "a")(hnsecs)));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
return retval.addSeconds(convert!("hnsecs", "seconds")(signedHNSecs));
}
unittest
{
version(testStdDateTime)
{
auto tod = TimeOfDay(12, 30, 33);
_assertPred!"=="(tod + dur!"hours"(7), TimeOfDay(19, 30, 33));
_assertPred!"=="(tod + dur!"hours"(-7), TimeOfDay(5, 30, 33));
_assertPred!"=="(tod + dur!"minutes"(7), TimeOfDay(12, 37, 33));
_assertPred!"=="(tod + dur!"minutes"(-7), TimeOfDay(12, 23, 33));
_assertPred!"=="(tod + dur!"seconds"(7), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod + dur!"seconds"(-7), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod + dur!"msecs"(7000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod + dur!"msecs"(-7000), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod + dur!"usecs"(7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod + dur!"usecs"(-7_000_000), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod + dur!"hnsecs"(70_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod + dur!"hnsecs"(-70_000_000), TimeOfDay(12, 30, 26));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(tod + TickDuration.from!"usecs"(7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod + TickDuration.from!"usecs"(-7_000_000), TimeOfDay(12, 30, 26));
}
_assertPred!"=="(tod - dur!"hours"(-7), TimeOfDay(19, 30, 33));
_assertPred!"=="(tod - dur!"hours"(7), TimeOfDay(5, 30, 33));
_assertPred!"=="(tod - dur!"minutes"(-7), TimeOfDay(12, 37, 33));
_assertPred!"=="(tod - dur!"minutes"(7), TimeOfDay(12, 23, 33));
_assertPred!"=="(tod - dur!"seconds"(-7), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod - dur!"seconds"(7), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod - dur!"msecs"(-7000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod - dur!"msecs"(7000), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod - dur!"usecs"(-7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod - dur!"usecs"(7_000_000), TimeOfDay(12, 30, 26));
_assertPred!"=="(tod - dur!"hnsecs"(-70_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod - dur!"hnsecs"(70_000_000), TimeOfDay(12, 30, 26));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(tod - TickDuration.from!"usecs"(-7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"=="(tod - TickDuration.from!"usecs"(7_000_000), TimeOfDay(12, 30, 26));
}
auto duration = dur!"hours"(11);
const ctod = TimeOfDay(12, 33, 30);
immutable itod = TimeOfDay(12, 33, 30);
static assert(__traits(compiles, tod + duration));
static assert(__traits(compiles, ctod + duration));
static assert(__traits(compiles, itod + duration));
static assert(__traits(compiles, tod - duration));
static assert(__traits(compiles, ctod - duration));
static assert(__traits(compiles, itod - duration));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D TimeOfDay), as well as assigning the result to this
$(D TimeOfDay).
The legal types of arithmetic for $(D TimeOfDay) using this operator are
$(BOOKTABLE,
$(TR $(TD TimeOfDay) $(TD +) $(TD duration) $(TD -->) $(TD TimeOfDay))
$(TR $(TD TimeOfDay) $(TD -) $(TD duration) $(TD -->) $(TD TimeOfDay))
)
Params:
duration = The duration to add to or subtract from this
$(D TimeOfDay).
+/
/+ref+/ TimeOfDay opOpAssign(string op, D)(in D duration) pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
immutable hnsecs = duration.hnsecs;
//Ideally, this would just be
//return addSeconds(convert!("hnsecs", "seconds")(unaryFun!(op ~ "a")(hnsecs)));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
return addSeconds(convert!("hnsecs", "seconds")(signedHNSecs));
}
unittest
{
version(testStdDateTime)
{
auto duration = dur!"hours"(12);
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"hours"(7), TimeOfDay(19, 30, 33));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"hours"(-7), TimeOfDay(5, 30, 33));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"minutes"(7), TimeOfDay(12, 37, 33));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"minutes"(-7), TimeOfDay(12, 23, 33));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"seconds"(7), TimeOfDay(12, 30, 40));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"seconds"(-7), TimeOfDay(12, 30, 26));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"msecs"(7000), TimeOfDay(12, 30, 40));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"msecs"(-7000), TimeOfDay(12, 30, 26));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"usecs"(7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"usecs"(-7_000_000), TimeOfDay(12, 30, 26));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"hnsecs"(70_000_000), TimeOfDay(12, 30, 40));
_assertPred!"+="(TimeOfDay(12, 30, 33), dur!"hnsecs"(-70_000_000), TimeOfDay(12, 30, 26));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"hours"(-7), TimeOfDay(19, 30, 33));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"hours"(7), TimeOfDay(5, 30, 33));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"minutes"(-7), TimeOfDay(12, 37, 33));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"minutes"(7), TimeOfDay(12, 23, 33));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"seconds"(-7), TimeOfDay(12, 30, 40));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"seconds"(7), TimeOfDay(12, 30, 26));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"msecs"(-7000), TimeOfDay(12, 30, 40));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"msecs"(7000), TimeOfDay(12, 30, 26));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"usecs"(-7_000_000), TimeOfDay(12, 30, 40));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"usecs"(7_000_000), TimeOfDay(12, 30, 26));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"hnsecs"(-70_000_000), TimeOfDay(12, 30, 40));
_assertPred!"-="(TimeOfDay(12, 30, 33), dur!"hnsecs"(70_000_000), TimeOfDay(12, 30, 26));
const ctod = TimeOfDay(12, 33, 30);
immutable itod = TimeOfDay(12, 33, 30);
static assert(!__traits(compiles, ctod += duration));
static assert(!__traits(compiles, itod += duration));
static assert(!__traits(compiles, ctod -= duration));
static assert(!__traits(compiles, itod -= duration));
}
}
/++
Gives the difference between two $(D TimeOfDay)s.
The legal types of arithmetic for $(D TimeOfDay) using this operator are
$(BOOKTABLE,
$(TR $(TD TimeOfDay) $(TD -) $(TD TimeOfDay) $(TD -->) $(TD duration))
)
Params:
rhs = The $(D TimeOfDay) to subtract from this one.
+/
Duration opBinary(string op)(in TimeOfDay rhs) const pure nothrow
if(op == "-")
{
immutable lhsSec = _hour * 3600 + _minute * 60 + _second;
immutable rhsSec = rhs._hour * 3600 + rhs._minute * 60 + rhs._second;
return dur!"seconds"(lhsSec - rhsSec);
}
unittest
{
version(testStdDateTime)
{
auto tod = TimeOfDay(12, 30, 33);
_assertPred!"=="(TimeOfDay(7, 12, 52) - TimeOfDay(12, 30, 33), dur!"seconds"(-19_061));
_assertPred!"=="(TimeOfDay(12, 30, 33) - TimeOfDay(7, 12, 52), dur!"seconds"(19_061));
_assertPred!"=="(TimeOfDay(12, 30, 33) - TimeOfDay(14, 30, 33), dur!"seconds"(-7200));
_assertPred!"=="(TimeOfDay(14, 30, 33) - TimeOfDay(12, 30, 33), dur!"seconds"(7200));
_assertPred!"=="(TimeOfDay(12, 30, 33) - TimeOfDay(12, 34, 33), dur!"seconds"(-240));
_assertPred!"=="(TimeOfDay(12, 34, 33) - TimeOfDay(12, 30, 33), dur!"seconds"(240));
_assertPred!"=="(TimeOfDay(12, 30, 33) - TimeOfDay(12, 30, 34), dur!"seconds"(-1));
_assertPred!"=="(TimeOfDay(12, 30, 34) - TimeOfDay(12, 30, 33), dur!"seconds"(1));
const ctod = TimeOfDay(12, 30, 33);
immutable itod = TimeOfDay(12, 30, 33);
static assert(__traits(compiles, tod - tod));
static assert(__traits(compiles, ctod - tod));
static assert(__traits(compiles, itod - tod));
static assert(__traits(compiles, tod - ctod));
static assert(__traits(compiles, ctod - ctod));
static assert(__traits(compiles, itod - ctod));
static assert(__traits(compiles, tod - itod));
static assert(__traits(compiles, ctod - itod));
static assert(__traits(compiles, itod - itod));
}
}
/++
Converts this $(D TimeOfDay) to a string with the format HHMMSS.
Examples:
--------------------
assert(TimeOfDay(0, 0, 0).toISOString() == "000000");
assert(TimeOfDay(12, 30, 33).toISOString() == "123033");
--------------------
+/
string toISOString() const nothrow
{
try
return format("%02d%02d%02d", _hour, _minute, _second);
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
auto tod = TimeOfDay(12, 30, 33);
const ctod = TimeOfDay(12, 30, 33);
immutable itod = TimeOfDay(12, 30, 33);
static assert(__traits(compiles, tod.toISOString()));
static assert(__traits(compiles, ctod.toISOString()));
static assert(__traits(compiles, itod.toISOString()));
//Verify Examples.
assert(TimeOfDay(0, 0, 0).toISOString() == "000000");
assert(TimeOfDay(12, 30, 33).toISOString() == "123033");
}
}
/++
Converts this $(D TimeOfDay) to a string with the format HH:MM:SS.
Examples:
--------------------
assert(TimeOfDay(0, 0, 0).toISOExtString() == "000000");
assert(TimeOfDay(12, 30, 33).toISOExtString() == "123033");
--------------------
+/
string toISOExtString() const nothrow
{
try
return format("%02d:%02d:%02d", _hour, _minute, _second);
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
auto tod = TimeOfDay(12, 30, 33);
const ctod = TimeOfDay(12, 30, 33);
immutable itod = TimeOfDay(12, 30, 33);
static assert(__traits(compiles, tod.toISOExtString()));
static assert(__traits(compiles, ctod.toISOExtString()));
static assert(__traits(compiles, itod.toISOExtString()));
//Verify Examples.
assert(TimeOfDay(0, 0, 0).toISOExtString() == "00:00:00");
assert(TimeOfDay(12, 30, 33).toISOExtString() == "12:30:33");
}
}
/+
Converts this $(D TimeOfDay) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return toISOExtString();
}
/++
Converts this TimeOfDay to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return toISOExtString();
}
unittest
{
version(testStdDateTime)
{
auto tod = TimeOfDay(12, 30, 33);
const ctod = TimeOfDay(12, 30, 33);
immutable itod = TimeOfDay(12, 30, 33);
static assert(__traits(compiles, tod.toString()));
static assert(__traits(compiles, ctod.toString()));
static assert(__traits(compiles, itod.toString()));
}
}
//TODO Add a function which returns a string in a user-specified format.
/++
Creates a $(D TimeOfDay) from a string with the format HHMMSS.
Whitespace is stripped from the given string.
Params:
isoString = A string formatted in the ISO format for times.
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D TimeOfDay) would not be valid.
Examples:
--------------------
assert(TimeOfDay.fromISOString("000000") == TimeOfDay(0, 0, 0));
assert(TimeOfDay.fromISOString("123033") == TimeOfDay(12, 30, 33));
assert(TimeOfDay.fromISOString(" 123033 ") == TimeOfDay(12, 30, 33));
--------------------
+/
static TimeOfDay fromISOString(S)(in S isoString)
if(isSomeString!S)
{
auto dstr = to!dstring(strip(isoString));
enforce(dstr.length == 6, new DateTimeException(format("Invalid ISO String: %s", isoString)));
auto hours = dstr[0 .. 2];
auto minutes = dstr[2 .. 4];
auto seconds = dstr[4 .. $];
enforce(!canFind!(not!isDigit)(hours), new DateTimeException(format("Invalid ISO String: %s", isoString)));
enforce(!canFind!(not!isDigit)(minutes), new DateTimeException(format("Invalid ISO String: %s", isoString)));
enforce(!canFind!(not!isDigit)(seconds), new DateTimeException(format("Invalid ISO String: %s", isoString)));
return TimeOfDay(to!int(hours), to!int(minutes), to!int(seconds));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(TimeOfDay.fromISOString(""));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("00"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("000"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0000"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("00000"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("13033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("1277"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12707"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12070"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12303a"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("1230a3"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("123a33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12a033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("1a0033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("a20033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("1200330"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("-120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("+120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("120033am"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("120033pm"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0::"));
assertThrown!DateTimeException(TimeOfDay.fromISOString(":0:"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("::0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0:0:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0:0:00"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("0:00:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("00:0:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("00:00:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("00:0:00"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("13:0:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:7:7"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:7:07"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:07:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:30:3a"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:30:a3"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:3a:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:a0:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("1a:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("a2:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:003:30"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("120:03:30"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("012:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("01:200:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("-12:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("+12:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:00:33am"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:00:33pm"));
assertThrown!DateTimeException(TimeOfDay.fromISOString("12:00:33"));
_assertPred!"=="(TimeOfDay.fromISOString("011217"), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOString("001412"), TimeOfDay(0, 14, 12));
_assertPred!"=="(TimeOfDay.fromISOString("000007"), TimeOfDay(0, 0, 7));
_assertPred!"=="(TimeOfDay.fromISOString("011217 "), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOString(" 011217"), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOString(" 011217 "), TimeOfDay(1, 12, 17));
//Verify Examples.
assert(TimeOfDay.fromISOString("000000") == TimeOfDay(0, 0, 0));
assert(TimeOfDay.fromISOString("123033") == TimeOfDay(12, 30, 33));
assert(TimeOfDay.fromISOString(" 123033 ") == TimeOfDay(12, 30, 33));
}
}
/++
Creates a $(D TimeOfDay) from a string with the format HH:MM:SS.
Whitespace is stripped from the given string.
Params:
isoString = A string formatted in the ISO Extended format for times.
Throws:
$(D DateTimeException) if the given string is not in the ISO
Extended format or if the resulting $(D TimeOfDay) would not be
valid.
Examples:
--------------------
assert(TimeOfDay.fromISOExtString("00:00:00") == TimeOfDay(0, 0, 0));
assert(TimeOfDay.fromISOExtString("12:30:33") == TimeOfDay(12, 30, 33));
assert(TimeOfDay.fromISOExtString(" 12:30:33 ") == TimeOfDay(12, 30, 33));
--------------------
+/
static TimeOfDay fromISOExtString(S)(in S isoExtString)
if(isSomeString!S)
{
auto dstr = to!dstring(strip(isoExtString));
enforce(dstr.length == 8, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto hours = dstr[0 .. 2];
auto minutes = dstr[3 .. 5];
auto seconds = dstr[6 .. $];
enforce(dstr[2] == ':', new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(dstr[5] == ':', new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(hours),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(minutes),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
enforce(!canFind!(not!isDigit)(seconds),
new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
return TimeOfDay(to!int(hours), to!int(minutes), to!int(seconds));
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(TimeOfDay.fromISOExtString(""));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("00"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("000"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0000"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("00000"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("13033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("1277"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12707"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12070"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12303a"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("1230a3"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("123a33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12a033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("1a0033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("a20033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("1200330"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("-120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("+120033"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("120033am"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("120033pm"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0::"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString(":0:"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("::0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0:0:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0:0:00"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("0:00:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("00:0:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("00:00:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("00:0:00"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("13:0:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:7:7"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:7:07"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:07:0"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:30:3a"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:30:a3"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:3a:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:a0:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("1a:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("a2:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:003:30"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("120:03:30"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("012:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("01:200:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("-12:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("+12:00:33"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:00:33am"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("12:00:33pm"));
assertThrown!DateTimeException(TimeOfDay.fromISOExtString("120033"));
_assertPred!"=="(TimeOfDay.fromISOExtString("01:12:17"), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOExtString("00:14:12"), TimeOfDay(0, 14, 12));
_assertPred!"=="(TimeOfDay.fromISOExtString("00:00:07"), TimeOfDay(0, 0, 7));
_assertPred!"=="(TimeOfDay.fromISOExtString("01:12:17 "), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOExtString(" 01:12:17"), TimeOfDay(1, 12, 17));
_assertPred!"=="(TimeOfDay.fromISOExtString(" 01:12:17 "), TimeOfDay(1, 12, 17));
//Verify Examples.
assert(TimeOfDay.fromISOExtString("00:00:00") == TimeOfDay(0, 0, 0));
assert(TimeOfDay.fromISOExtString("12:30:33") == TimeOfDay(12, 30, 33));
assert(TimeOfDay.fromISOExtString(" 12:30:33 ") == TimeOfDay(12, 30, 33));
}
}
//TODO Add function which takes a user-specified time format and produces a TimeOfDay
//TODO Add function which takes pretty much any time-string and produces a TimeOfDay
// Obviously, it will be less efficient, and it probably won't manage _every_
// possible date format, but a smart conversion function would be nice.
/++
Returns midnight.
+/
@property static TimeOfDay min() pure nothrow
{
return TimeOfDay.init;
}
unittest
{
version(testStdDateTime)
{
assert(TimeOfDay.min.hour == 0);
assert(TimeOfDay.min.minute == 0);
assert(TimeOfDay.min.second == 0);
assert(TimeOfDay.min < TimeOfDay.max);
}
}
/++
Returns one second short of midnight.
+/
@property static TimeOfDay max() pure nothrow
{
auto tod = TimeOfDay.init;
tod._hour = maxHour;
tod._minute = maxMinute;
tod._second = maxSecond;
return tod;
}
unittest
{
version(testStdDateTime)
{
assert(TimeOfDay.max.hour == 23);
assert(TimeOfDay.max.minute == 59);
assert(TimeOfDay.max.second == 59);
assert(TimeOfDay.max > TimeOfDay.min);
}
}
private:
/+
Add seconds to the time of day. Negative values will subtract. If the
number of seconds overflows (or underflows), then the seconds will wrap,
increasing (or decreasing) the number of minutes accordingly. If the
number of minutes overflows (or underflows), then the minutes will wrap.
If the number of minutes overflows(or underflows), then the hour will
wrap. (e.g. adding 90 seconds to 23:59:00 would result in 00:00:30).
Params:
seconds = The number of seconds to add to this TimeOfDay.
+/
ref TimeOfDay addSeconds(long seconds) pure nothrow
{
long hnsecs = convert!("seconds", "hnsecs")(seconds);
hnsecs += convert!("hours", "hnsecs")(_hour);
hnsecs += convert!("minutes", "hnsecs")(_minute);
hnsecs += convert!("seconds", "hnsecs")(_second);
hnsecs %= convert!("days", "hnsecs")(1);
if(hnsecs < 0)
hnsecs += convert!("days", "hnsecs")(1);
immutable newHours = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable newMinutes = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable newSeconds = splitUnitsFromHNSecs!"seconds"(hnsecs);
_hour = cast(ubyte)newHours;
_minute = cast(ubyte)newMinutes;
_second = cast(ubyte)newSeconds;
return this;
}
unittest
{
version(testStdDateTime)
{
static void testTOD(TimeOfDay orig, int seconds, in TimeOfDay expected, size_t line = __LINE__)
{
orig.addSeconds(seconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
testTOD(TimeOfDay(12, 30, 33), 0, TimeOfDay(12, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 1, TimeOfDay(12, 30, 34));
testTOD(TimeOfDay(12, 30, 33), 2, TimeOfDay(12, 30, 35));
testTOD(TimeOfDay(12, 30, 33), 3, TimeOfDay(12, 30, 36));
testTOD(TimeOfDay(12, 30, 33), 4, TimeOfDay(12, 30, 37));
testTOD(TimeOfDay(12, 30, 33), 5, TimeOfDay(12, 30, 38));
testTOD(TimeOfDay(12, 30, 33), 10, TimeOfDay(12, 30, 43));
testTOD(TimeOfDay(12, 30, 33), 15, TimeOfDay(12, 30, 48));
testTOD(TimeOfDay(12, 30, 33), 26, TimeOfDay(12, 30, 59));
testTOD(TimeOfDay(12, 30, 33), 27, TimeOfDay(12, 31, 0));
testTOD(TimeOfDay(12, 30, 33), 30, TimeOfDay(12, 31, 3));
testTOD(TimeOfDay(12, 30, 33), 59, TimeOfDay(12, 31, 32));
testTOD(TimeOfDay(12, 30, 33), 60, TimeOfDay(12, 31, 33));
testTOD(TimeOfDay(12, 30, 33), 61, TimeOfDay(12, 31, 34));
testTOD(TimeOfDay(12, 30, 33), 1766, TimeOfDay(12, 59, 59));
testTOD(TimeOfDay(12, 30, 33), 1767, TimeOfDay(13, 0, 0));
testTOD(TimeOfDay(12, 30, 33), 1768, TimeOfDay(13, 0, 1));
testTOD(TimeOfDay(12, 30, 33), 2007, TimeOfDay(13, 4, 0));
testTOD(TimeOfDay(12, 30, 33), 3599, TimeOfDay(13, 30, 32));
testTOD(TimeOfDay(12, 30, 33), 3600, TimeOfDay(13, 30, 33));
testTOD(TimeOfDay(12, 30, 33), 3601, TimeOfDay(13, 30, 34));
testTOD(TimeOfDay(12, 30, 33), 7200, TimeOfDay(14, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -1, TimeOfDay(12, 30, 32));
testTOD(TimeOfDay(12, 30, 33), -2, TimeOfDay(12, 30, 31));
testTOD(TimeOfDay(12, 30, 33), -3, TimeOfDay(12, 30, 30));
testTOD(TimeOfDay(12, 30, 33), -4, TimeOfDay(12, 30, 29));
testTOD(TimeOfDay(12, 30, 33), -5, TimeOfDay(12, 30, 28));
testTOD(TimeOfDay(12, 30, 33), -10, TimeOfDay(12, 30, 23));
testTOD(TimeOfDay(12, 30, 33), -15, TimeOfDay(12, 30, 18));
testTOD(TimeOfDay(12, 30, 33), -33, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 33), -34, TimeOfDay(12, 29, 59));
testTOD(TimeOfDay(12, 30, 33), -35, TimeOfDay(12, 29, 58));
testTOD(TimeOfDay(12, 30, 33), -59, TimeOfDay(12, 29, 34));
testTOD(TimeOfDay(12, 30, 33), -60, TimeOfDay(12, 29, 33));
testTOD(TimeOfDay(12, 30, 33), -61, TimeOfDay(12, 29, 32));
testTOD(TimeOfDay(12, 30, 33), -1833, TimeOfDay(12, 0, 0));
testTOD(TimeOfDay(12, 30, 33), -1834, TimeOfDay(11, 59, 59));
testTOD(TimeOfDay(12, 30, 33), -3600, TimeOfDay(11, 30, 33));
testTOD(TimeOfDay(12, 30, 33), -3601, TimeOfDay(11, 30, 32));
testTOD(TimeOfDay(12, 30, 33), -5134, TimeOfDay(11, 4, 59));
testTOD(TimeOfDay(12, 30, 33), -7200, TimeOfDay(10, 30, 33));
testTOD(TimeOfDay(12, 30, 0), 1, TimeOfDay(12, 30, 1));
testTOD(TimeOfDay(12, 30, 0), 0, TimeOfDay(12, 30, 0));
testTOD(TimeOfDay(12, 30, 0), -1, TimeOfDay(12, 29, 59));
testTOD(TimeOfDay(12, 0, 0), 1, TimeOfDay(12, 0, 1));
testTOD(TimeOfDay(12, 0, 0), 0, TimeOfDay(12, 0, 0));
testTOD(TimeOfDay(12, 0, 0), -1, TimeOfDay(11, 59, 59));
testTOD(TimeOfDay(0, 0, 0), 1, TimeOfDay(0, 0, 1));
testTOD(TimeOfDay(0, 0, 0), 0, TimeOfDay(0, 0, 0));
testTOD(TimeOfDay(0, 0, 0), -1, TimeOfDay(23, 59, 59));
testTOD(TimeOfDay(23, 59, 59), 1, TimeOfDay(0, 0, 0));
testTOD(TimeOfDay(23, 59, 59), 0, TimeOfDay(23, 59, 59));
testTOD(TimeOfDay(23, 59, 59), -1, TimeOfDay(23, 59, 58));
const ctod = TimeOfDay(0, 0, 0);
immutable itod = TimeOfDay(0, 0, 0);
static assert(!__traits(compiles, ctod.addSeconds(7)));
static assert(!__traits(compiles, itod.addSeconds(7)));
}
}
/+
Whether the given values form a valid $(D TimeOfDay).
+/
static bool _valid(int hour, int minute, int second) pure nothrow
{
return valid!"hours"(hour) && valid!"minutes"(minute) && valid!"seconds"(second);
}
pure invariant()
{
assert(_valid(_hour, _minute, _second),
"Invariant Failure: hour [" ~
numToString(_hour) ~
"] minute [" ~
numToString(_minute) ~
"] second [" ~
numToString(_second) ~
"]");
}
ubyte _hour;
ubyte _minute;
ubyte _second;
enum ubyte maxHour = 24 - 1;
enum ubyte maxMinute = 60 - 1;
enum ubyte maxSecond = 60 - 1;
}
/++
Combines the $(D Date) and $(D TimeOfDay) structs to give an object
which holds both the date and the time. It is optimized for calendar-based
operations and has no concept of time zone. For an object which is
optimized for time operations based on the system time, use
$(D SysTime). $(D SysTime) has a concept of time zone and has much higher
precision (hnsecs). $(D DateTime) is intended primarily for calendar-based
uses rather than precise time operations.
+/
struct DateTime
{
public:
/++
Params:
date = The date portion of $(D DateTime).
tod = The time portion of $(D DateTime).
+/
this(in Date date, in TimeOfDay tod = TimeOfDay.init) pure nothrow
{
_date = date;
_tod = tod;
}
unittest
{
version(testStdDateTime)
{
{
auto dt = DateTime.init;
_assertPred!"=="(dt._date, Date.init);
_assertPred!"=="(dt._tod, TimeOfDay.init);
}
{
auto dt = DateTime(Date(1999, 7 ,6));
_assertPred!"=="(dt._date, Date(1999, 7, 6));
_assertPred!"=="(dt._tod, TimeOfDay.init);
}
{
auto dt = DateTime(Date(1999, 7 ,6), TimeOfDay(12, 30, 33));
_assertPred!"=="(dt._date, Date(1999, 7, 6));
_assertPred!"=="(dt._tod, TimeOfDay(12, 30, 33));
}
}
}
/++
Params:
year = The year portion of the date.
month = The month portion of the date.
day = The day portion of the date.
hour = The hour portion of the time;
minute = The minute portion of the time;
second = The second portion of the time;
+/
this(int year, int month, int day,
int hour = 0, int minute = 0, int second = 0) pure
{
_date = Date(year, month, day);
_tod = TimeOfDay(hour, minute, second);
}
unittest
{
version(testStdDateTime)
{
{
auto dt = DateTime(1999, 7 ,6);
_assertPred!"=="(dt._date, Date(1999, 7, 6));
_assertPred!"=="(dt._tod, TimeOfDay.init);
}
{
auto dt = DateTime(1999, 7 ,6, 12, 30, 33);
_assertPred!"=="(dt._date, Date(1999, 7, 6));
_assertPred!"=="(dt._tod, TimeOfDay(12, 30, 33));
}
}
}
/++
Compares this $(D DateTime) with the given $(D DateTime.).
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
+/
int opCmp(in DateTime rhs) const pure nothrow
{
immutable dateResult = _date.opCmp(rhs._date);
if(dateResult != 0)
return dateResult;
return _tod.opCmp(rhs._tod);
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!("opCmp", "==")(DateTime(Date.init, TimeOfDay.init), DateTime.init);
_assertPred!("opCmp", "==")(DateTime(Date(1999, 1, 1)), DateTime(Date(1999, 1, 1)));
_assertPred!("opCmp", "==")(DateTime(Date(1, 7, 1)), DateTime(Date(1, 7, 1)));
_assertPred!("opCmp", "==")(DateTime(Date(1, 1, 6)), DateTime(Date(1, 1, 6)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 1)), DateTime(Date(1999, 7, 1)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6)), DateTime(Date(1999, 7, 6)));
_assertPred!("opCmp", "==")(DateTime(Date(1, 7, 6)), DateTime(Date(1, 7, 6)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6)), DateTime(Date(2000, 7, 6)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 7, 6)), DateTime(Date(1999, 7, 6)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6)), DateTime(Date(1999, 8, 6)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 8, 6)), DateTime(Date(1999, 7, 6)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6)), DateTime(Date(1999, 7, 7)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 7)), DateTime(Date(1999, 7, 6)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 8, 7)), DateTime(Date(2000, 7, 6)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 8, 6)), DateTime(Date(1999, 7, 7)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 7)), DateTime(Date(2000, 7, 6)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 7, 6)), DateTime(Date(1999, 7, 7)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 7)), DateTime(Date(1999, 8, 6)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 8, 6)), DateTime(Date(1999, 7, 7)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)),
DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 0)),
DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 0)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(2000, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)),
DateTime(Date(1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
DateTime(Date(1999, 7, 7), TimeOfDay(12, 31, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
DateTime(Date(1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
//Test B.C.
_assertPred!("opCmp", "==")(DateTime(Date(-1, 1, 1), TimeOfDay(12, 30, 33)),
DateTime(Date(-1, 1, 1), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(-1, 7, 1), TimeOfDay(12, 30, 33)),
DateTime(Date(-1, 7, 1), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(-1, 1, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1, 1, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(-1999, 7, 1), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 1), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "==")(DateTime(Date(-1, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-2000, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-2000, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 8, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(-2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-2000, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(-2000, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)));
//Test Both
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 8, 7), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 8, 7), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", "<")(DateTime(Date(-1999, 8, 6), TimeOfDay(12, 30, 33)),
DateTime(Date(1999, 6, 6), TimeOfDay(12, 30, 33)));
_assertPred!("opCmp", ">")(DateTime(Date(1999, 6, 8), TimeOfDay(12, 30, 33)),
DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 33, 30));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 33, 30));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 33, 30));
static assert(__traits(compiles, dt.opCmp(dt)));
static assert(__traits(compiles, dt.opCmp(cdt)));
static assert(__traits(compiles, dt.opCmp(idt)));
static assert(__traits(compiles, cdt.opCmp(dt)));
static assert(__traits(compiles, cdt.opCmp(cdt)));
static assert(__traits(compiles, cdt.opCmp(idt)));
static assert(__traits(compiles, idt.opCmp(dt)));
static assert(__traits(compiles, idt.opCmp(cdt)));
static assert(__traits(compiles, idt.opCmp(idt)));
}
}
/++
The date portion of $(D DateTime).
+/
@property Date date() const pure nothrow
{
return _date;
}
unittest
{
version(testStdDateTime)
{
{
auto dt = DateTime.init;
_assertPred!"=="(dt.date, Date.init);
}
{
auto dt = DateTime(Date(1999, 7, 6));
_assertPred!"=="(dt.date, Date(1999, 7, 6));
}
const cdt = DateTime(1999, 7, 6);
immutable idt = DateTime(1999, 7, 6);
static assert(__traits(compiles, cdt.date == Date(2010, 1, 1)));
static assert(__traits(compiles, idt.date == Date(2010, 1, 1)));
}
}
/++
The date portion of $(D DateTime).
Params:
date = The Date to set this $(D DateTime)'s date portion to.
+/
@property void date(in Date date) pure nothrow
{
_date = date;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime.init;
dt.date = Date(1999, 7, 6);
_assertPred!"=="(dt._date, Date(1999, 7, 6));
_assertPred!"=="(dt._tod, TimeOfDay.init);
const cdt = DateTime(1999, 7, 6);
immutable idt = DateTime(1999, 7, 6);
static assert(!__traits(compiles, cdt.date = Date(2010, 1, 1)));
static assert(!__traits(compiles, idt.date = Date(2010, 1, 1)));
}
}
/++
The time portion of $(D DateTime).
+/
@property TimeOfDay timeOfDay() const pure nothrow
{
return _tod;
}
unittest
{
version(testStdDateTime)
{
{
auto dt = DateTime.init;
_assertPred!"=="(dt.timeOfDay, TimeOfDay.init);
}
{
auto dt = DateTime(Date.init, TimeOfDay(12, 30, 33));
_assertPred!"=="(dt.timeOfDay, TimeOfDay(12, 30, 33));
}
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.timeOfDay == TimeOfDay(12, 30, 33)));
static assert(__traits(compiles, idt.timeOfDay == TimeOfDay(12, 30, 33)));
}
}
/++
The time portion of $(D DateTime).
Params:
tod = The $(D TimeOfDay) to set this $(D DateTime)'s time portion
to.
+/
@property void timeOfDay(in TimeOfDay tod) pure nothrow
{
_tod = tod;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime.init;
dt.timeOfDay = TimeOfDay(12, 30, 33);
_assertPred!"=="(dt._date, date.init);
_assertPred!"=="(dt._tod, TimeOfDay(12, 30, 33));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.timeOfDay = TimeOfDay(12, 30, 33)));
static assert(!__traits(compiles, idt.timeOfDay = TimeOfDay(12, 30, 33)));
}
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
+/
@property short year() const pure nothrow
{
return _date.year;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Date.init.year, 1);
_assertPred!"=="(Date(1999, 7, 6).year, 1999);
_assertPred!"=="(Date(-1999, 7, 6).year, -1999);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, idt.year));
static assert(__traits(compiles, idt.year));
}
}
/++
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Params:
year = The year to set this $(D DateTime)'s year to.
Throws:
$(D DateTimeException) if the new year is not a leap year and if the
resulting date would be on February 29th.
Examples:
--------------------
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year == 1999);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year == 2010);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year == -7);
--------------------
+/
@property void year(int year) pure
{
_date.year = year;
}
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime dt, int year, in DateTime expected, size_t line = __LINE__)
{
dt.year = year;
_assertPred!"=="(dt, expected, "", __FILE__, line);
}
testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), 1999, DateTime(Date(1999, 1, 1), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), 0, DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), -1999, DateTime(Date(-1999, 1, 1), TimeOfDay(12, 30, 33)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.year = 7));
static assert(!__traits(compiles, idt.year = 7));
//Verify Examples.
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year == 1999);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year == 2010);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year == -7);
}
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Throws:
$(D DateTimeException) if $(D isAD) is true.
Examples:
--------------------
assert(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC == 1);
assert(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC == 2);
assert(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC == 101);
--------------------
+/
@property short yearBC() const pure
{
return _date.yearBC;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((in DateTime dt){dt.yearBC;}(DateTime(Date(1, 1, 1))));
auto dt = DateTime(1999, 7, 6, 12, 30, 33);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, dt.yearBC = 12));
static assert(!__traits(compiles, cdt.yearBC = 12));
static assert(!__traits(compiles, idt.yearBC = 12));
//Verify Examples.
assert(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC == 1);
assert(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC == 2);
assert(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC == 101);
}
}
/++
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Params:
year = The year B.C. to set this $(D DateTime)'s year to.
Throws:
$(D DateTimeException) if a non-positive value is given.
Examples:
--------------------
auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0));
dt.yearBC = 1;
assert(dt == DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0)));
dt.yearBC = 10;
assert(dt == DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0)));
--------------------
+/
@property void yearBC(int year) pure
{
_date.yearBC = year;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((DateTime dt){dt.yearBC = -1;}(DateTime(Date(1, 1, 1))));
{
auto dt = DateTime(1999, 7, 6, 12, 30, 33);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, dt.yearBC = 12));
static assert(!__traits(compiles, cdt.yearBC = 12));
static assert(!__traits(compiles, idt.yearBC = 12));
}
//Verify Examples.
{
auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0));
dt.yearBC = 1;
assert(dt == DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0)));
dt.yearBC = 10;
assert(dt == DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0)));
}
}
}
/++
Month of a Gregorian Year.
Examples:
--------------------
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month == 7);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month == 10);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month == 4);
--------------------
+/
@property Month month() const pure nothrow
{
return _date.month;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime.init.month, 1);
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)).month, 7);
_assertPred!"=="(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)).month, 7);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.month));
static assert(__traits(compiles, idt.month));
//Verify Examples.
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month == 7);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month == 10);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month == 4);
}
}
/++
Month of a Gregorian Year.
Params:
month = The month to set this $(D DateTime)'s month to.
Throws:
$(D DateTimeException) if the given month is not a valid month.
+/
@property void month(Month month) pure
{
_date.month = month;
}
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime dt, Month month, in DateTime expected = DateTime.init, size_t line = __LINE__)
{
dt.month = month;
assert(expected != DateTime.init);
_assertPred!"=="(dt, expected, "", __FILE__, line);
}
assertThrown!DateTimeException(testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), cast(Month)0));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), cast(Month)13));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(12, 30, 33)), cast(Month)7, DateTime(Date(1, 7, 1), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(12, 30, 33)), cast(Month)7, DateTime(Date(-1, 7, 1), TimeOfDay(12, 30, 33)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.month = 12));
static assert(!__traits(compiles, idt.month = 12));
}
}
/++
Day of a Gregorian Month.
Examples:
--------------------
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day == 6);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day == 4);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day == 5);
--------------------
+/
@property ubyte day() const pure nothrow
{
return _date.day;
}
//Verify Examples.
version(testStdDateTime) unittest
{
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day == 6);
assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day == 4);
assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day == 5);
}
version(testStdDateTime) unittest
{
static void test(DateTime dateTime, int expected, size_t line = __LINE__)
{
_assertPred!"=="(dateTime.day, expected,
format("Value given: %s", dateTime), __FILE__, line);
}
foreach(year; chain(testYearsBC, testYearsAD))
{
foreach(md; testMonthDays)
{
foreach(tod; testTODs)
test(DateTime(Date(year, md.month, md.day), tod), md.day);
}
}
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.day));
static assert(__traits(compiles, idt.day));
}
/++
Day of a Gregorian Month.
Params:
day = The day of the month to set this $(D DateTime)'s day to.
Throws:
$(D DateTimeException) if the given day is not a valid day of the
current month.
+/
@property void day(int day) pure
{
_date.day = day;
}
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime dt, int day)
{
dt.day = day;
}
//Test A.D.
assertThrown!DateTimeException(testDT(DateTime(Date(1, 1, 1)), 0));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 1, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 2, 1)), 29));
assertThrown!DateTimeException(testDT(DateTime(Date(4, 2, 1)), 30));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 3, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 4, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 5, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 6, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 7, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 8, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 9, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 10, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 11, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(1, 12, 1)), 32));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 1, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 2, 1)), 28));
assertNotThrown!DateTimeException(testDT(DateTime(Date(4, 2, 1)), 29));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 3, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 4, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 5, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 6, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 7, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 8, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 9, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 10, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 11, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(1, 12, 1)), 31));
{
auto dt = DateTime(Date(1, 1, 1), TimeOfDay(7, 12, 22));
dt.day = 6;
_assertPred!"=="(dt, DateTime(Date(1, 1, 6), TimeOfDay(7, 12, 22)));
}
//Test B.C.
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 1, 1)), 0));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 1, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 2, 1)), 29));
assertThrown!DateTimeException(testDT(DateTime(Date(0, 2, 1)), 30));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 3, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 4, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 5, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 6, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 7, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 8, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 9, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 10, 1)), 32));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 11, 1)), 31));
assertThrown!DateTimeException(testDT(DateTime(Date(-1, 12, 1)), 32));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 1, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 2, 1)), 28));
assertNotThrown!DateTimeException(testDT(DateTime(Date(0, 2, 1)), 29));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 3, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 4, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 5, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 6, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 7, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 8, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 9, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 10, 1)), 31));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 11, 1)), 30));
assertNotThrown!DateTimeException(testDT(DateTime(Date(-1, 12, 1)), 31));
auto dt = DateTime(Date(-1, 1, 1), TimeOfDay(7, 12, 22));
dt.day = 6;
_assertPred!"=="(dt, DateTime(Date(-1, 1, 6), TimeOfDay(7, 12, 22)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.day = 27));
static assert(!__traits(compiles, idt.day = 27));
}
}
/++
Hours passed midnight.
+/
@property ubyte hour() const pure nothrow
{
return _tod.hour;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime.init.hour, 0);
_assertPred!"=="(DateTime(Date.init, TimeOfDay(12, 0, 0)).hour, 12);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.hour));
static assert(__traits(compiles, idt.hour));
}
}
/++
Hours passed midnight.
Params:
hour = The hour of the day to set this $(D DateTime)'s hour to.
Throws:
$(D DateTimeException) if the given hour would result in an invalid
$(D DateTime).
+/
@property void hour(int hour) pure
{
_tod.hour = hour;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)).hour = 24;}());
auto dt = DateTime.init;
dt.hour = 12;
_assertPred!"=="(dt, DateTime(1, 1, 1, 12, 0, 0));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.hour = 27));
static assert(!__traits(compiles, idt.hour = 27));
}
}
/++
Minutes passed the hour.
+/
@property ubyte minute() const pure nothrow
{
return _tod.minute;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime.init.minute, 0);
_assertPred!"=="(DateTime(1, 1, 1, 0, 30, 0).minute, 30);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.minute));
static assert(__traits(compiles, idt.minute));
}
}
/++
Minutes passed the hour.
Params:
minute = The minute to set this $(D DateTime)'s minute to.
Throws:
$(D DateTimeException) if the given minute would result in an
invalid $(D DateTime).
+/
@property void minute(int minute) pure
{
_tod.minute = minute;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){DateTime.init.minute = 60;}());
auto dt = DateTime.init;
dt.minute = 30;
_assertPred!"=="(dt, DateTime(1, 1, 1, 0, 30, 0));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.minute = 27));
static assert(!__traits(compiles, idt.minute = 27));
}
}
/++
Seconds passed the minute.
+/
@property ubyte second() const pure nothrow
{
return _tod.second;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime.init.second, 0);
_assertPred!"=="(DateTime(1, 1, 1, 0, 0, 33).second, 33);
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.second));
static assert(__traits(compiles, idt.second));
}
}
/++
Seconds passed the minute.
Params:
second = The second to set this $(D DateTime)'s second to.
Throws:
$(D DateTimeException) if the given seconds would result in an
invalid $(D DateTime).
+/
@property void second(int second) pure
{
_tod.second = second;
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException((){DateTime.init.second = 60;}());
auto dt = DateTime.init;
dt.second = 33;
_assertPred!"=="(dt, DateTime(1, 1, 1, 0, 0, 33));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.second = 27));
static assert(!__traits(compiles, idt.second = 27));
}
}
/++
Adds the given number of years or months to this $(D DateTime). A
negative number will subtract.
Note that if day overflow is allowed, and the date with the adjusted
year/month overflows the number of days in the new month, then the month
will be incremented by one, and the day set to the number of days
overflowed. (e.g. if the day were 31 and the new month were June, then
the month would be incremented to July, and the new day would be 1). If
day overflow is not allowed, then the day will be set to the last valid
day in the month (e.g. June 31st would become June 30th).
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D DateTime).
allowOverflow = Whether the days should be allowed to overflow,
causing the month to increment.
Examples:
--------------------
auto dt1 = DateTime(2010, 1, 1, 12, 30, 33);
dt1.add!"months"(11);
assert(dt1 == DateTime(2010, 12, 1, 12, 30, 33));
auto dt2 = DateTime(2010, 1, 1, 12, 30, 33);
dt2.add!"months"(-11);
assert(dt2 == DateTime(2009, 2, 1, 12, 30, 33));
auto dt3 = DateTime(2000, 2, 29, 12, 30, 33);
dt3.add!"years"(1);
assert(dt3 == DateTime(2001, 3, 1, 12, 30, 33));
auto dt4 = DateTime(2000, 2, 29, 12, 30, 33);
dt4.add!"years"(1, AllowDayOverflow.no);
assert(dt4 == DateTime(2001, 2, 28, 12, 30, 33));
--------------------
+/
/+ref DateTime+/ void add(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "years" ||
units == "months")
{
_date.add!units(value, allowOverflow);
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto dt1 = DateTime(2010, 1, 1, 12, 30, 33);
dt1.add!"months"(11);
assert(dt1 == DateTime(2010, 12, 1, 12, 30, 33));
auto dt2 = DateTime(2010, 1, 1, 12, 30, 33);
dt2.add!"months"(-11);
assert(dt2 == DateTime(2009, 2, 1, 12, 30, 33));
auto dt3 = DateTime(2000, 2, 29, 12, 30, 33);
dt3.add!"years"(1);
assert(dt3 == DateTime(2001, 3, 1, 12, 30, 33));
auto dt4 = DateTime(2000, 2, 29, 12, 30, 33);
dt4.add!"years"(1, AllowDayOverflow.no);
assert(dt4 == DateTime(2001, 2, 28, 12, 30, 33));
}
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.add!"years"(4)));
static assert(!__traits(compiles, idt.add!"years"(4)));
static assert(!__traits(compiles, cdt.add!"months"(4)));
static assert(!__traits(compiles, idt.add!"months"(4)));
}
}
/++
Adds the given number of years or months to this $(D DateTime). A
negative number will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. Rolling a $(D DateTime) 12 months
gets the exact same $(D DateTime). However, the days can still be
affected due to the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Params:
units = The type of units to add ("years" or "months").
value = The number of months or years to add to this
$(D DateTime).
allowOverflow = Whether the days should be allowed to overflow,
causing the month to increment.
Examples:
--------------------
auto dt1 = DateTime(2010, 1, 1, 12, 33, 33);
dt1.roll!"months"(1);
assert(dt1 == DateTime(2010, 2, 1, 12, 33, 33));
auto dt2 = DateTime(2010, 1, 1, 12, 33, 33);
dt2.roll!"months"(-1);
assert(dt2 == DateTime(2010, 12, 1, 12, 33, 33));
auto dt3 = DateTime(1999, 1, 29, 12, 33, 33);
dt3.roll!"months"(1);
assert(dt3 == DateTime(1999, 3, 1, 12, 33, 33));
auto dt4 = DateTime(1999, 1, 29, 12, 33, 33);
dt4.roll!"months"(1, AllowDayOverflow.no);
assert(dt4 == DateTime(1999, 2, 28, 12, 33, 33));
auto dt5 = DateTime(2000, 2, 29, 12, 30, 33);
dt5.roll!"years"(1);
assert(dt5 == DateTime(2001, 3, 1, 12, 30, 33));
auto dt6 = DateTime(2000, 2, 29, 12, 30, 33);
dt6.roll!"years"(1, AllowDayOverflow.no);
assert(dt6 == DateTime(2001, 2, 28, 12, 30, 33));
--------------------
+/
/+ref DateTime+/ void roll(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) pure nothrow
if(units == "years" ||
units == "months")
{
_date.roll!units(value, allowOverflow);
}
//Verify Examples.
unittest
{
version(testdStdDateTime)
{
auto dt1 = DateTime(2010, 1, 1, 12, 33, 33);
dt1.roll!"months"(1);
assert(dt1 == DateTime(2010, 2, 1, 12, 33, 33));
auto dt2 = DateTime(2010, 1, 1, 12, 33, 33);
dt2.roll!"months"(-1);
assert(dt2 == DateTime(2010, 12, 1, 12, 33, 33));
auto dt3 = DateTime(1999, 1, 29, 12, 33, 33);
dt3.roll!"months"(1);
assert(dt3 == DateTime(1999, 3, 1, 12, 33, 33));
auto dt4 = DateTime(1999, 1, 29, 12, 33, 33);
dt4.roll!"months"(1, AllowDayOverflow.no);
assert(dt4 == DateTime(1999, 2, 28, 12, 33, 33));
auto dt5 = DateTime(2000, 2, 29, 12, 30, 33);
dt5.roll!"years"(1);
assert(dt5 == DateTime(2001, 3, 1, 12, 30, 33));
auto dt6 = DateTime(2000, 2, 29, 12, 30, 33);
dt6.roll!"years"(1, AllowDayOverflow.no);
assert(dt6 == DateTime(2001, 2, 28, 12, 30, 33));
}
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.roll!"years"(4)));
static assert(!__traits(compiles, idt.roll!"years"(4)));
static assert(!__traits(compiles, cdt.roll!"months"(4)));
static assert(!__traits(compiles, idt.roll!"months"(4)));
static assert(!__traits(compiles, cdt.roll!"days"(4)));
static assert(!__traits(compiles, idt.roll!"days"(4)));
}
}
/++
Adds the given number of units to this $(D DateTime). A negative number
will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. For instance, rolling a $(D DateTime) one
year's worth of days gets the exact same $(D DateTime).
Accepted units are $(D "days"), $(D "minutes"), $(D "hours"),
$(D "minutes"), and $(D "seconds").
Params:
units = The units to add.
value = The number of $(D_PARAM units) to add to this $(D DateTime).
Examples:
--------------------
auto dt1 = DateTime(2010, 1, 1, 11, 23, 12);
dt1.roll!"days"(1);
assert(dt1 == DateTime(2010, 1, 2, 11, 23, 12));
dt1.roll!"days"(365);
assert(dt1 == DateTime(2010, 1, 26, 11, 23, 12));
dt1.roll!"days"(-32);
assert(dt1 == DateTime(2010, 1, 25, 11, 23, 12));
auto dt2 = DateTime(2010, 7, 4, 12, 0, 0);
dt2.roll!"hours"(1);
assert(dt2 == DateTime(2010, 7, 4, 13, 0, 0));
auto dt3 = DateTime(2010, 1, 1, 0, 0, 0);
dt3.roll!"seconds"(-1);
assert(dt3 == DateTime(2010, 1, 1, 0, 0, 59));
--------------------
+/
/+ref DateTime+/ void roll(string units)(long days) pure nothrow
if(units == "days")
{
_date.roll!"days"(days);
}
//Verify Examples.
unittest
{
version(testStdDateTime)
{
auto dt1 = DateTime(2010, 1, 1, 11, 23, 12);
dt1.roll!"days"(1);
assert(dt1 == DateTime(2010, 1, 2, 11, 23, 12));
dt1.roll!"days"(365);
assert(dt1 == DateTime(2010, 1, 26, 11, 23, 12));
dt1.roll!"days"(-32);
assert(dt1 == DateTime(2010, 1, 25, 11, 23, 12));
auto dt2 = DateTime(2010, 7, 4, 12, 0, 0);
dt2.roll!"hours"(1);
assert(dt2 == DateTime(2010, 7, 4, 13, 0, 0));
auto dt3 = DateTime(2010, 1, 1, 0, 0, 0);
dt3.roll!"seconds"(-1);
assert(dt3 == DateTime(2010, 1, 1, 0, 0, 59));
}
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.roll!"days"(4)));
static assert(!__traits(compiles, idt.roll!"days"(4)));
}
}
//Shares documentation with "days" version.
/+ref DateTime+/ void roll(string units)(long value) pure nothrow
if(units == "hours" ||
units == "minutes" ||
units == "seconds")
{
_tod.roll!units(value);
}
//Test roll!"hours"().
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime orig, int hours, in DateTime expected, size_t line = __LINE__)
{
orig.roll!"hours"(hours);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(1999, 7, 6), TimeOfDay(14, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(1999, 7, 6), TimeOfDay(15, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(1999, 7, 6), TimeOfDay(16, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(1999, 7, 6), TimeOfDay(17, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 6, DateTime(Date(1999, 7, 6), TimeOfDay(18, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 7, DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 8, DateTime(Date(1999, 7, 6), TimeOfDay(20, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 9, DateTime(Date(1999, 7, 6), TimeOfDay(21, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 11, DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 12, DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 13, DateTime(Date(1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 14, DateTime(Date(1999, 7, 6), TimeOfDay(2, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(1999, 7, 6), TimeOfDay(3, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 16, DateTime(Date(1999, 7, 6), TimeOfDay(4, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 17, DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 18, DateTime(Date(1999, 7, 6), TimeOfDay(6, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 19, DateTime(Date(1999, 7, 6), TimeOfDay(7, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 20, DateTime(Date(1999, 7, 6), TimeOfDay(8, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 21, DateTime(Date(1999, 7, 6), TimeOfDay(9, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 22, DateTime(Date(1999, 7, 6), TimeOfDay(10, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 23, DateTime(Date(1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 24, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 25, DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(1999, 7, 6), TimeOfDay(10, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(1999, 7, 6), TimeOfDay(9, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(1999, 7, 6), TimeOfDay(8, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(1999, 7, 6), TimeOfDay(7, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -6, DateTime(Date(1999, 7, 6), TimeOfDay(6, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -7, DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -8, DateTime(Date(1999, 7, 6), TimeOfDay(4, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -9, DateTime(Date(1999, 7, 6), TimeOfDay(3, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(1999, 7, 6), TimeOfDay(2, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -11, DateTime(Date(1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -12, DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -13, DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -14, DateTime(Date(1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(1999, 7, 6), TimeOfDay(21, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -16, DateTime(Date(1999, 7, 6), TimeOfDay(20, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -17, DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -18, DateTime(Date(1999, 7, 6), TimeOfDay(18, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -19, DateTime(Date(1999, 7, 6), TimeOfDay(17, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -20, DateTime(Date(1999, 7, 6), TimeOfDay(16, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -21, DateTime(Date(1999, 7, 6), TimeOfDay(15, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -22, DateTime(Date(1999, 7, 6), TimeOfDay(14, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -23, DateTime(Date(1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -24, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -25, DateTime(Date(1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(23, 30, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(1999, 7, 31), TimeOfDay(23, 30, 33)), 1, DateTime(Date(1999, 7, 31), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 8, 1), TimeOfDay(0, 30, 33)), -1, DateTime(Date(1999, 8, 1), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 12, 31), TimeOfDay(23, 30, 33)), 1, DateTime(Date(1999, 12, 31), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(2000, 1, 1), TimeOfDay(0, 30, 33)), -1, DateTime(Date(2000, 1, 1), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(1999, 2, 28), TimeOfDay(23, 30, 33)), 25, DateTime(Date(1999, 2, 28), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(1999, 3, 2), TimeOfDay(0, 30, 33)), -25, DateTime(Date(1999, 3, 2), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(2000, 2, 28), TimeOfDay(23, 30, 33)), 25, DateTime(Date(2000, 2, 28), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(2000, 3, 1), TimeOfDay(0, 30, 33)), -25, DateTime(Date(2000, 3, 1), TimeOfDay(23, 30, 33)));
//Test B.C.
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(-1999, 7, 6), TimeOfDay(14, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(-1999, 7, 6), TimeOfDay(15, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(-1999, 7, 6), TimeOfDay(16, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(-1999, 7, 6), TimeOfDay(17, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 6, DateTime(Date(-1999, 7, 6), TimeOfDay(18, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 7, DateTime(Date(-1999, 7, 6), TimeOfDay(19, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 8, DateTime(Date(-1999, 7, 6), TimeOfDay(20, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 9, DateTime(Date(-1999, 7, 6), TimeOfDay(21, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(-1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 11, DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 12, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 13, DateTime(Date(-1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 14, DateTime(Date(-1999, 7, 6), TimeOfDay(2, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(-1999, 7, 6), TimeOfDay(3, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 16, DateTime(Date(-1999, 7, 6), TimeOfDay(4, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 17, DateTime(Date(-1999, 7, 6), TimeOfDay(5, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 18, DateTime(Date(-1999, 7, 6), TimeOfDay(6, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 19, DateTime(Date(-1999, 7, 6), TimeOfDay(7, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 20, DateTime(Date(-1999, 7, 6), TimeOfDay(8, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 21, DateTime(Date(-1999, 7, 6), TimeOfDay(9, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 22, DateTime(Date(-1999, 7, 6), TimeOfDay(10, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 23, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 24, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 25, DateTime(Date(-1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(-1999, 7, 6), TimeOfDay(10, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(-1999, 7, 6), TimeOfDay(9, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(-1999, 7, 6), TimeOfDay(8, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(-1999, 7, 6), TimeOfDay(7, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -6, DateTime(Date(-1999, 7, 6), TimeOfDay(6, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -7, DateTime(Date(-1999, 7, 6), TimeOfDay(5, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -8, DateTime(Date(-1999, 7, 6), TimeOfDay(4, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -9, DateTime(Date(-1999, 7, 6), TimeOfDay(3, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(-1999, 7, 6), TimeOfDay(2, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -11, DateTime(Date(-1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -12, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -13, DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -14, DateTime(Date(-1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(-1999, 7, 6), TimeOfDay(21, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -16, DateTime(Date(-1999, 7, 6), TimeOfDay(20, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -17, DateTime(Date(-1999, 7, 6), TimeOfDay(19, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -18, DateTime(Date(-1999, 7, 6), TimeOfDay(18, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -19, DateTime(Date(-1999, 7, 6), TimeOfDay(17, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -20, DateTime(Date(-1999, 7, 6), TimeOfDay(16, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -21, DateTime(Date(-1999, 7, 6), TimeOfDay(15, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -22, DateTime(Date(-1999, 7, 6), TimeOfDay(14, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -23, DateTime(Date(-1999, 7, 6), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -24, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -25, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(1, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(23, 30, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(22, 30, 33)));
testDT(DateTime(Date(-1999, 7, 31), TimeOfDay(23, 30, 33)), 1, DateTime(Date(-1999, 7, 31), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-1999, 8, 1), TimeOfDay(0, 30, 33)), -1, DateTime(Date(-1999, 8, 1), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-2001, 12, 31), TimeOfDay(23, 30, 33)), 1, DateTime(Date(-2001, 12, 31), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-2000, 1, 1), TimeOfDay(0, 30, 33)), -1, DateTime(Date(-2000, 1, 1), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-2001, 2, 28), TimeOfDay(23, 30, 33)), 25, DateTime(Date(-2001, 2, 28), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-2001, 3, 2), TimeOfDay(0, 30, 33)), -25, DateTime(Date(-2001, 3, 2), TimeOfDay(23, 30, 33)));
testDT(DateTime(Date(-2000, 2, 28), TimeOfDay(23, 30, 33)), 25, DateTime(Date(-2000, 2, 28), TimeOfDay(0, 30, 33)));
testDT(DateTime(Date(-2000, 3, 1), TimeOfDay(0, 30, 33)), -25, DateTime(Date(-2000, 3, 1), TimeOfDay(23, 30, 33)));
//Test Both
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)), 17_546, DateTime(Date(-1, 1, 1), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)), -17_546, DateTime(Date(1, 1, 1), TimeOfDay(11, 30, 33)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.roll!"hours"(4)));
static assert(!__traits(compiles, idt.roll!"hours"(4)));
//Verify Examples.
auto dt1 = DateTime(Date(2010, 7, 4), TimeOfDay(12, 0, 0));
dt1.roll!"hours"(1);
assert(dt1 == DateTime(Date(2010, 7, 4), TimeOfDay(13, 0, 0)));
auto dt2 = DateTime(Date(2010, 2, 12), TimeOfDay(12, 0, 0));
dt2.roll!"hours"(-1);
assert(dt2 == DateTime(Date(2010, 2, 12), TimeOfDay(11, 0, 0)));
auto dt3 = DateTime(Date(2009, 12, 31), TimeOfDay(23, 0, 0));
dt3.roll!"hours"(1);
assert(dt3 == DateTime(Date(2009, 12, 31), TimeOfDay(0, 0, 0)));
auto dt4 = DateTime(Date(2010, 1, 1), TimeOfDay(0, 0, 0));
dt4.roll!"hours"(-1);
assert(dt4 == DateTime(Date(2010, 1, 1), TimeOfDay(23, 0, 0)));
}
}
//Test roll!"minutes"().
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime orig, int minutes, in DateTime expected, size_t line = __LINE__)
{
orig.roll!"minutes"(minutes);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(1999, 7, 6), TimeOfDay(12, 32, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(1999, 7, 6), TimeOfDay(12, 33, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(1999, 7, 6), TimeOfDay(12, 34, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(1999, 7, 6), TimeOfDay(12, 35, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(1999, 7, 6), TimeOfDay(12, 40, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 29, DateTime(Date(1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 30, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 45, DateTime(Date(1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 60, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 75, DateTime(Date(1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 90, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 100, DateTime(Date(1999, 7, 6), TimeOfDay(12, 10, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 689, DateTime(Date(1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 690, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 691, DateTime(Date(1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 960, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1439, DateTime(Date(1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1440, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1441, DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 2880, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(1999, 7, 6), TimeOfDay(12, 28, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(1999, 7, 6), TimeOfDay(12, 27, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(1999, 7, 6), TimeOfDay(12, 26, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(1999, 7, 6), TimeOfDay(12, 25, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(1999, 7, 6), TimeOfDay(12, 20, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -29, DateTime(Date(1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -30, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -45, DateTime(Date(1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -60, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -75, DateTime(Date(1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -90, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -100, DateTime(Date(1999, 7, 6), TimeOfDay(12, 50, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -749, DateTime(Date(1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -750, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -751, DateTime(Date(1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -960, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1439, DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1440, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1441, DateTime(Date(1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -2880, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(11, 59, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(11, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(11, 59, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(11, 59, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(11, 59, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(11, 58, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(0, 1, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(0, 59, 33)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 33)), 1, DateTime(Date(1999, 7, 5), TimeOfDay(23, 0, 33)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 33)), 0, DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 33)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 33)), -1, DateTime(Date(1999, 7, 5), TimeOfDay(23, 58, 33)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 33)), 1, DateTime(Date(1998, 12, 31), TimeOfDay(23, 0, 33)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 33)), 0, DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 33)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 33)), -1, DateTime(Date(1998, 12, 31), TimeOfDay(23, 58, 33)));
//Test B.C.
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 32, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 33, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 34, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 35, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 40, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 29, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 30, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 45, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 60, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 75, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 90, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 100, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 10, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 689, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 690, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 691, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 960, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1439, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1440, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1441, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 2880, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 28, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 27, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 26, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 25, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 20, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -29, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -30, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -45, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 45, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -60, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -75, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 15, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -90, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -100, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 50, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -749, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -750, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -751, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -960, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1439, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 31, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1440, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1441, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 29, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -2880, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 1, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 59, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(11, 59, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(11, 59, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 59, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(11, 59, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(11, 58, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 1, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 59, 33)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 33)), 1, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 0, 33)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 33)), 0, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 33)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 33)), -1, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 58, 33)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 33)), 1, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 0, 33)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 33)), 0, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 33)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 33)), -1, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 58, 33)));
//Test Both
testDT(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)), -1, DateTime(Date(1, 1, 1), TimeOfDay(0, 59, 0)));
testDT(DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 0)), 1, DateTime(Date(0, 12, 31), TimeOfDay(23, 0, 0)));
testDT(DateTime(Date(0, 1, 1), TimeOfDay(0, 0, 0)), -1, DateTime(Date(0, 1, 1), TimeOfDay(0, 59, 0)));
testDT(DateTime(Date(-1, 12, 31), TimeOfDay(23, 59, 0)), 1, DateTime(Date(-1, 12, 31), TimeOfDay(23, 0, 0)));
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)), 1_052_760, DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)), -1_052_760, DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)), 1_052_782, DateTime(Date(-1, 1, 1), TimeOfDay(11, 52, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(13, 52, 33)), -1_052_782, DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.roll!"minutes"(4)));
static assert(!__traits(compiles, idt.roll!"minutes"(4)));
}
}
//Test roll!"seconds"().
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime orig, int seconds, in DateTime expected, size_t line = __LINE__)
{
orig.roll!"seconds"(seconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 35)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 36)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 37)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 38)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 43)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 48)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 26, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 27, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 30, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 3)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 59, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 60, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 61, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1766, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1767, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 1768, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 1)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 2007, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3599, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3600, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 3601, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), 7200, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 31)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 30)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 29)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 28)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 23)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 18)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -33, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -34, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -35, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 58)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -59, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -60, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), -61, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 1)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 0)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 1)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 0)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(12, 0, 59)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)), 1, DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 1)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)), 0, DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)));
testDT(DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 0)), -1, DateTime(Date(1999, 7, 6), TimeOfDay(0, 0, 59)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 59)), 1, DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 59)), 0, DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 59)));
testDT(DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 59)), -1, DateTime(Date(1999, 7, 5), TimeOfDay(23, 59, 58)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 59)), 1, DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 59)), 0, DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 59)));
testDT(DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 59)), -1, DateTime(Date(1998, 12, 31), TimeOfDay(23, 59, 58)));
//Test B.C.
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 2, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 35)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 36)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 4, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 37)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 5, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 38)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 10, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 43)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 15, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 48)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 26, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 27, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 30, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 3)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 59, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 60, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 61, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1766, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1767, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 1768, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 1)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 2007, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3599, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3600, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 3601, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), 7200, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -2, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 31)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -3, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 30)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -4, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 29)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -5, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 28)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -10, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 23)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -15, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 18)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -33, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -34, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -35, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 58)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -59, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 34)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -60, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)), -61, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 32)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 1)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 0)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 59)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 0)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 1)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 0)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 0)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(12, 0, 59)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 0)), 1, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 1)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 0)), 0, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 0)));
testDT(DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 0)), -1, DateTime(Date(-1999, 7, 6), TimeOfDay(0, 0, 59)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 59)), 1, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 59)), 0, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 59)));
testDT(DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 59)), -1, DateTime(Date(-1999, 7, 5), TimeOfDay(23, 59, 58)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 59)), 1, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 59)), 0, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 59)));
testDT(DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 59)), -1, DateTime(Date(-2000, 12, 31), TimeOfDay(23, 59, 58)));
//Test Both
testDT(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)), -1, DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 59)));
testDT(DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)), 1, DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(0, 1, 1), TimeOfDay(0, 0, 0)), -1, DateTime(Date(0, 1, 1), TimeOfDay(0, 0, 59)));
testDT(DateTime(Date(-1, 12, 31), TimeOfDay(23, 59, 59)), 1, DateTime(Date(-1, 12, 31), TimeOfDay(23, 59, 0)));
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)), 63_165_600L, DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)), -63_165_600L, DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)));
testDT(DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 33)), 63_165_617L, DateTime(Date(-1, 1, 1), TimeOfDay(11, 30, 50)));
testDT(DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 50)), -63_165_617L, DateTime(Date(1, 1, 1), TimeOfDay(13, 30, 33)));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.roll!"seconds"(4)));
static assert(!__traits(compiles, idt.roll!"seconds"(4)));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D DateTime).
The legal types of arithmetic for $(D DateTime) using this operator are
$(BOOKTABLE,
$(TR $(TD DateTime) $(TD +) $(TD duration) $(TD -->) $(TD DateTime))
$(TR $(TD DateTime) $(TD -) $(TD duration) $(TD -->) $(TD DateTime))
)
Params:
duration = The duration to add to or subtract from this
$(D DateTime).
+/
DateTime opBinary(string op, D)(in D duration) const pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
DateTime retval = this;
static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
immutable hnsecs = duration.hnsecs;
//Ideally, this would just be
//return retval.addSeconds(convert!("hnsecs", "seconds")(unaryFun!(op ~ "a")(hnsecs)));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
return retval.addSeconds(convert!("hnsecs", "seconds")(signedHNSecs));
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
_assertPred!"=="(dt + dur!"weeks"(7), DateTime(Date(1999, 8, 24), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt + dur!"weeks"(-7), DateTime(Date(1999, 5, 18), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt + dur!"days"(7), DateTime(Date(1999, 7, 13), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt + dur!"days"(-7), DateTime(Date(1999, 6, 29), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt + dur!"hours"(7), DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
_assertPred!"=="(dt + dur!"hours"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
_assertPred!"=="(dt + dur!"minutes"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 37, 33)));
_assertPred!"=="(dt + dur!"minutes"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 23, 33)));
_assertPred!"=="(dt + dur!"seconds"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt + dur!"seconds"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt + dur!"msecs"(7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt + dur!"msecs"(-7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt + dur!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt + dur!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt + dur!"hnsecs"(70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt + dur!"hnsecs"(-70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(dt + TickDuration.from!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt + TickDuration.from!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
}
_assertPred!"=="(dt - dur!"weeks"(-7), DateTime(Date(1999, 8, 24), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt - dur!"weeks"(7), DateTime(Date(1999, 5, 18), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt - dur!"days"(-7), DateTime(Date(1999, 7, 13), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt - dur!"days"(7), DateTime(Date(1999, 6, 29), TimeOfDay(12, 30, 33)));
_assertPred!"=="(dt - dur!"hours"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
_assertPred!"=="(dt - dur!"hours"(7), DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
_assertPred!"=="(dt - dur!"minutes"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 37, 33)));
_assertPred!"=="(dt - dur!"minutes"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 23, 33)));
_assertPred!"=="(dt - dur!"seconds"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt - dur!"seconds"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt - dur!"msecs"(-7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt - dur!"msecs"(7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt - dur!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt - dur!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"=="(dt - dur!"hnsecs"(-70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt - dur!"hnsecs"(70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
//This probably only runs in cases where gettimeofday() is used, but it's
//hard to do this test correctly with variable ticksPerSec.
if(TickDuration.ticksPerSec == 1_000_000)
{
_assertPred!"=="(dt - TickDuration.from!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"=="(dt - TickDuration.from!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
}
auto duration = dur!"seconds"(12);
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt + duration));
static assert(__traits(compiles, idt + duration));
static assert(__traits(compiles, cdt - duration));
static assert(__traits(compiles, idt - duration));
}
}
/++
Gives the result of adding or subtracting a duration from this
$(D DateTime), as well as assigning the result to this $(D DateTime).
The legal types of arithmetic for $(D DateTime) using this operator are
$(BOOKTABLE,
$(TR $(TD DateTime) $(TD +) $(TD duration) $(TD -->) $(TD DateTime))
$(TR $(TD DateTime) $(TD -) $(TD duration) $(TD -->) $(TD DateTime))
)
Params:
duration = The duration to add to or subtract from this
$(D DateTime).
+/
/+ref+/ DateTime opOpAssign(string op, D)(in D duration) pure nothrow
if((op == "+" || op == "-") &&
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
DateTime retval = this;
static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
else static if(is(Unqual!D == TickDuration))
immutable hnsecs = duration.hnsecs;
//Ideally, this would just be
//return addSeconds(convert!("hnsecs", "seconds")(unaryFun!(op ~ "a")(hnsecs)));
//But there isn't currently a pure version of unaryFun!().
static if(op == "+")
immutable signedHNSecs = hnsecs;
else static if(op == "-")
immutable signedHNSecs = -hnsecs;
else
static assert(0);
return addSeconds(convert!("hnsecs", "seconds")(signedHNSecs));
}
unittest
{
version(testStdDateTime)
{
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"weeks"(7), DateTime(Date(1999, 8, 24), TimeOfDay(12, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"weeks"(-7), DateTime(Date(1999, 5, 18), TimeOfDay(12, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"days"(7), DateTime(Date(1999, 7, 13), TimeOfDay(12, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"days"(-7), DateTime(Date(1999, 6, 29), TimeOfDay(12, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hours"(7), DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hours"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"minutes"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 37, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"minutes"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 23, 33)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"seconds"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"seconds"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"msecs"(7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"msecs"(-7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hnsecs"(70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"+="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hnsecs"(-70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"weeks"(-7), DateTime(Date(1999, 8, 24), TimeOfDay(12, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"weeks"(7), DateTime(Date(1999, 5, 18), TimeOfDay(12, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"days"(-7), DateTime(Date(1999, 7, 13), TimeOfDay(12, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"days"(7), DateTime(Date(1999, 6, 29), TimeOfDay(12, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hours"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(19, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hours"(7), DateTime(Date(1999, 7, 6), TimeOfDay(5, 30, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"minutes"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 37, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"minutes"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 23, 33)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"seconds"(-7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"seconds"(7), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"msecs"(-7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"msecs"(7_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"usecs"(-7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"usecs"(7_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hnsecs"(-70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 40)));
_assertPred!"-="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)), dur!"hnsecs"(70_000_000), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 26)));
auto duration = dur!"seconds"(12);
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(!__traits(compiles, cdt += duration));
static assert(!__traits(compiles, idt += duration));
static assert(!__traits(compiles, cdt -= duration));
static assert(!__traits(compiles, idt -= duration));
}
}
/++
Gives the difference between two $(D DateTime)s.
The legal types of arithmetic for $(D DateTime) using this operator are
$(BOOKTABLE,
$(TR $(TD DateTime) $(TD -) $(TD DateTime) $(TD -->) $(TD duration))
)
+/
Duration opBinary(string op)(in DateTime rhs) const pure nothrow
if(op == "-")
{
immutable dateResult = _date - rhs.date;
immutable todResult = _tod - rhs._tod;
return dur!"hnsecs"(dateResult.total!"hnsecs" + todResult.total!"hnsecs");
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(1999, 7, 6, 12, 30, 33);
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1998, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(31_536_000));
_assertPred!"=="(DateTime(Date(1998, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(-31_536_000));
_assertPred!"=="(DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(26_78_400));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 8, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(-26_78_400));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 5), TimeOfDay(12, 30, 33)),
dur!"seconds"(86_400));
_assertPred!"=="(DateTime(Date(1999, 7, 5), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(-86_400));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(11, 30, 33)),
dur!"seconds"(3600));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(11, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(-3600));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(60));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 31, 33)),
dur!"seconds"(-60));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)),
dur!"seconds"(1));
_assertPred!"=="(DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)) -
DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 34)),
dur!"seconds"(-1));
_assertPred!"=="(DateTime(1, 1, 1, 12, 30, 33) - DateTime(1, 1, 1, 0, 0, 0), dur!"seconds"(45033));
_assertPred!"=="(DateTime(1, 1, 1, 0, 0, 0) - DateTime(1, 1, 1, 12, 30, 33), dur!"seconds"(-45033));
_assertPred!"=="(DateTime(0, 12, 31, 12, 30, 33) - DateTime(1, 1, 1, 0, 0, 0), dur!"seconds"(-41367));
_assertPred!"=="(DateTime(1, 1, 1, 0, 0, 0) - DateTime(0, 12, 31, 12, 30, 33), dur!"seconds"(41367));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt - dt));
static assert(__traits(compiles, cdt - dt));
static assert(__traits(compiles, idt - dt));
static assert(__traits(compiles, dt - cdt));
static assert(__traits(compiles, cdt - cdt));
static assert(__traits(compiles, idt - cdt));
static assert(__traits(compiles, dt - idt));
static assert(__traits(compiles, cdt - idt));
static assert(__traits(compiles, idt - idt));
}
}
/++
Returns the difference between the two $(D DateTime)s in months.
To get the difference in years, subtract the year property
of two $(D SysTime)s. To get the difference in days or weeks,
subtract the $(D SysTime)s themselves and use the $(D Duration)
that results. Because converting between months and smaller
units requires a specific date (which $(D Duration)s don't have),
getting the difference in months requires some math using both
the year and month properties, so this is a convenience function for
getting the difference in months.
Note that the number of days in the months or how far into the month
either date is is irrelevant. It is the difference in the month property
combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Params:
rhs = The $(D DateTime) to subtract from this one.
Examples:
--------------------
assert(DateTime(1999, 2, 1, 12, 2, 3).diffMonths(
DateTime(1999, 1, 31, 23, 59, 59)) == 1);
assert(DateTime(1999, 1, 31, 0, 0, 0).diffMonths(
DateTime(1999, 2, 1, 12, 3, 42)) == -1);
assert(DateTime(1999, 3, 1, 5, 30, 0).diffMonths(
DateTime(1999, 1, 1, 2, 4, 7)) == 2);
assert(DateTime(1999, 1, 1, 7, 2, 4).diffMonths(
DateTime(1999, 3, 31, 0, 30, 58)) == -2);
--------------------
+/
int diffMonths(in DateTime rhs) const pure nothrow
{
return _date.diffMonths(rhs._date);
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.diffMonths(dt)));
static assert(__traits(compiles, cdt.diffMonths(dt)));
static assert(__traits(compiles, idt.diffMonths(dt)));
static assert(__traits(compiles, dt.diffMonths(cdt)));
static assert(__traits(compiles, cdt.diffMonths(cdt)));
static assert(__traits(compiles, idt.diffMonths(cdt)));
static assert(__traits(compiles, dt.diffMonths(idt)));
static assert(__traits(compiles, cdt.diffMonths(idt)));
static assert(__traits(compiles, idt.diffMonths(idt)));
//Verify Examples.
assert(DateTime(1999, 2, 1, 12, 2, 3).diffMonths(DateTime(1999, 1, 31, 23, 59, 59)) == 1);
assert(DateTime(1999, 1, 31, 0, 0, 0).diffMonths(DateTime(1999, 2, 1, 12, 3, 42)) == -1);
assert(DateTime(1999, 3, 1, 5, 30, 0).diffMonths(DateTime(1999, 1, 1, 2, 4, 7)) == 2);
assert(DateTime(1999, 1, 1, 7, 2, 4).diffMonths(DateTime(1999, 3, 31, 0, 30, 58)) == -2);
}
}
/++
Whether this $(D DateTime) is in a leap year.
+/
@property bool isLeapYear() const pure nothrow
{
return _date.isLeapYear;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.isLeapYear));
static assert(__traits(compiles, cdt.isLeapYear));
static assert(__traits(compiles, idt.isLeapYear));
}
}
/++
Day of the week this $(D DateTime) is on.
+/
@property DayOfWeek dayOfWeek() const pure nothrow
{
return _date.dayOfWeek;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.dayOfWeek));
static assert(__traits(compiles, cdt.dayOfWeek));
static assert(__traits(compiles, idt.dayOfWeek));
}
}
/++
Day of the year this $(D DateTime) is on.
Examples:
--------------------
assert(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear == 1);
assert(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear == 365);
assert(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear == 366);
--------------------
+/
@property ushort dayOfYear() const pure nothrow
{
return _date.dayOfYear;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.dayOfYear));
static assert(__traits(compiles, cdt.dayOfYear));
static assert(__traits(compiles, idt.dayOfYear));
//Verify Examples.
assert(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear == 1);
assert(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear == 365);
assert(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear == 366);
}
}
/++
Day of the year.
Params:
day = The day of the year to set which day of the year this
$(D DateTime) is on.
+/
@property void dayOfYear(int day) pure
{
_date.dayOfYear = day;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.dayOfYear = 12));
static assert(!__traits(compiles, cdt.dayOfYear = 12));
static assert(!__traits(compiles, idt.dayOfYear = 12));
}
}
/++
The Xth day of the Gregorian Calendar that this $(D DateTime) is on.
Examples:
--------------------
assert(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal ==
1);
assert(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal ==
365);
assert(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal ==
366);
assert(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal ==
0);
assert(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal ==
-365);
assert(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal ==
-366);
assert(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal ==
730_120);
assert(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal ==
734_137);
--------------------
+/
@property int dayOfGregorianCal() const pure nothrow
{
return _date.dayOfGregorianCal;
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.dayOfGregorianCal));
static assert(__traits(compiles, idt.dayOfGregorianCal));
//Verify Examples.
assert(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal == 1);
assert(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal == 365);
assert(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal == 366);
assert(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal == 0);
assert(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal == -365);
assert(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal == -366);
assert(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal == 730_120);
assert(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal == 734_137);
}
}
/++
The Xth day of the Gregorian Calendar that this $(D DateTime) is on.
Setting this property does not affect the time portion of
$(D DateTime).
Params:
days = The day of the Gregorian Calendar to set this $(D DateTime)
to.
Examples:
--------------------
auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0));
dt.dayOfGregorianCal = 1;
assert(dt == DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 365;
assert(dt == DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 366;
assert(dt == DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 0;
assert(dt == DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = -365;
assert(dt == DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = -366;
assert(dt == DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 730_120;
assert(dt == DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 734_137;
assert(dt == DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0)));
--------------------
+/
@property void dayOfGregorianCal(int days) pure nothrow
{
_date.dayOfGregorianCal = days;
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(!__traits(compiles, cdt.dayOfGregorianCal = 7));
static assert(!__traits(compiles, idt.dayOfGregorianCal = 7));
//Verify Examples.
auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0));
dt.dayOfGregorianCal = 1;
assert(dt == DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 365;
assert(dt == DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 366;
assert(dt == DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 0;
assert(dt == DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = -365;
assert(dt == DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = -366;
assert(dt == DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 730_120;
assert(dt == DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0)));
dt.dayOfGregorianCal = 734_137;
assert(dt == DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0)));
}
}
/++
The ISO 8601 week of the year that this $(D DateTime) is in.
See_Also:
$(WEB en.wikipedia.org/wiki/ISO_week_date, ISO Week Date)
+/
@property ubyte isoWeek() const pure nothrow
{
return _date.isoWeek;
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.isoWeek));
static assert(__traits(compiles, cdt.isoWeek));
static assert(__traits(compiles, idt.isoWeek));
}
}
/++
$(D DateTime) for the last day in the month that this $(D DateTime) is
in. The time portion of endOfMonth is always 23:59:59.
Examples:
--------------------
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonth ==
DateTime(Date(1999, 1, 31), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonth ==
DateTime(Date(1999, 2, 28), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonth ==
DateTime(Date(2000, 2, 29), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonth ==
DateTime(Date(2000, 6, 30), TimeOfDay(23, 59, 59)));
--------------------
+/
@property DateTime endOfMonth() const pure nothrow
{
try
return DateTime(_date.endOfMonth, TimeOfDay(23, 59, 59));
catch(Exception e)
assert(0, "DateTime constructor threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(DateTime(1999, 1, 1, 0, 13, 26).endOfMonth, DateTime(1999, 1, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 2, 1, 1, 14, 27).endOfMonth, DateTime(1999, 2, 28, 23, 59, 59));
_assertPred!"=="(DateTime(2000, 2, 1, 2, 15, 28).endOfMonth, DateTime(2000, 2, 29, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 3, 1, 3, 16, 29).endOfMonth, DateTime(1999, 3, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 4, 1, 4, 17, 30).endOfMonth, DateTime(1999, 4, 30, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 5, 1, 5, 18, 31).endOfMonth, DateTime(1999, 5, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 6, 1, 6, 19, 32).endOfMonth, DateTime(1999, 6, 30, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 7, 1, 7, 20, 33).endOfMonth, DateTime(1999, 7, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 8, 1, 8, 21, 34).endOfMonth, DateTime(1999, 8, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 9, 1, 9, 22, 35).endOfMonth, DateTime(1999, 9, 30, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 10, 1, 10, 23, 36).endOfMonth, DateTime(1999, 10, 31, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 11, 1, 11, 24, 37).endOfMonth, DateTime(1999, 11, 30, 23, 59, 59));
_assertPred!"=="(DateTime(1999, 12, 1, 12, 25, 38).endOfMonth, DateTime(1999, 12, 31, 23, 59, 59));
//Test B.C.
_assertPred!"=="(DateTime(-1999, 1, 1, 0, 13, 26).endOfMonth, DateTime(-1999, 1, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 2, 1, 1, 14, 27).endOfMonth, DateTime(-1999, 2, 28, 23, 59, 59));
_assertPred!"=="(DateTime(-2000, 2, 1, 2, 15, 28).endOfMonth, DateTime(-2000, 2, 29, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 3, 1, 3, 16, 29).endOfMonth, DateTime(-1999, 3, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 4, 1, 4, 17, 30).endOfMonth, DateTime(-1999, 4, 30, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 5, 1, 5, 18, 31).endOfMonth, DateTime(-1999, 5, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 6, 1, 6, 19, 32).endOfMonth, DateTime(-1999, 6, 30, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 7, 1, 7, 20, 33).endOfMonth, DateTime(-1999, 7, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 8, 1, 8, 21, 34).endOfMonth, DateTime(-1999, 8, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 9, 1, 9, 22, 35).endOfMonth, DateTime(-1999, 9, 30, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 10, 1, 10, 23, 36).endOfMonth, DateTime(-1999, 10, 31, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 11, 1, 11, 24, 37).endOfMonth, DateTime(-1999, 11, 30, 23, 59, 59));
_assertPred!"=="(DateTime(-1999, 12, 1, 12, 25, 38).endOfMonth, DateTime(-1999, 12, 31, 23, 59, 59));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.endOfMonth));
static assert(__traits(compiles, idt.endOfMonth));
//Verify Examples.
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonth == DateTime(Date(1999, 1, 31), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonth == DateTime(Date(1999, 2, 28), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonth == DateTime(Date(2000, 2, 29), TimeOfDay(23, 59, 59)));
assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonth == DateTime(Date(2000, 6, 30), TimeOfDay(23, 59, 59)));
}
}
/++
The last day in the month that this $(D DateTime) is in.
Examples:
--------------------
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth == 31);
assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth == 28);
assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth == 29);
assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth == 30);
--------------------
+/
@property ubyte daysInMonth() const pure nothrow
{
return _date.daysInMonth;
}
//Explicitly undocumented. Do not use. To be removed in March 2013.
deprecated("Please use daysInMonth instead.") @property ubyte endOfMonthDay() const nothrow
{
return _date.daysInMonth;
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.daysInMonth));
static assert(__traits(compiles, idt.daysInMonth));
//Verify Examples.
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth == 31);
assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth == 28);
assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth == 29);
assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth == 30);
}
}
/++
Whether the current year is a date in A.D.
Examples:
--------------------
assert(DateTime(Date(1, 1, 1), TimeOfDay(12, 7, 0)).isAD);
assert(DateTime(Date(2010, 12, 31), TimeOfDay(0, 0, 0)).isAD);
assert(!DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)).isAD);
assert(!DateTime(Date(-2010, 1, 1), TimeOfDay(2, 2, 2)).isAD);
--------------------
+/
@property bool isAD() const pure nothrow
{
return _date.isAD;
}
unittest
{
version(testStdDateTime)
{
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.isAD));
static assert(__traits(compiles, idt.isAD));
//Verify Examples.
assert(DateTime(Date(1, 1, 1), TimeOfDay(12, 7, 0)).isAD);
assert(DateTime(Date(2010, 12, 31), TimeOfDay(0, 0, 0)).isAD);
assert(!DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)).isAD);
assert(!DateTime(Date(-2010, 1, 1), TimeOfDay(2, 2, 2)).isAD);
}
}
/++
The julian day for this $(D DateTime) at the given time. For example,
prior to noon, 1996-03-31 would be the julian day number 2_450_173, so
this function returns 2_450_173, while from noon onward, the julian
day number would be 2_450_174, so this function returns 2_450_174.
+/
@property long julianDay() const pure nothrow
{
if(_tod._hour < 12)
return _date.julianDay - 1;
else
return _date.julianDay;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime(Date(-4713, 11, 24), TimeOfDay(0, 0, 0)).julianDay, -1);
_assertPred!"=="(DateTime(Date(-4713, 11, 24), TimeOfDay(12, 0, 0)).julianDay, 0);
_assertPred!"=="(DateTime(Date(0, 12, 31), TimeOfDay(0, 0, 0)).julianDay, 1_721_424);
_assertPred!"=="(DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0)).julianDay, 1_721_425);
_assertPred!"=="(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).julianDay, 1_721_425);
_assertPred!"=="(DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0)).julianDay, 1_721_426);
_assertPred!"=="(DateTime(Date(1582, 10, 15), TimeOfDay(0, 0, 0)).julianDay, 2_299_160);
_assertPred!"=="(DateTime(Date(1582, 10, 15), TimeOfDay(12, 0, 0)).julianDay, 2_299_161);
_assertPred!"=="(DateTime(Date(1858, 11, 17), TimeOfDay(0, 0, 0)).julianDay, 2_400_000);
_assertPred!"=="(DateTime(Date(1858, 11, 17), TimeOfDay(12, 0, 0)).julianDay, 2_400_001);
_assertPred!"=="(DateTime(Date(1982, 1, 4), TimeOfDay(0, 0, 0)).julianDay, 2_444_973);
_assertPred!"=="(DateTime(Date(1982, 1, 4), TimeOfDay(12, 0, 0)).julianDay, 2_444_974);
_assertPred!"=="(DateTime(Date(1996, 3, 31), TimeOfDay(0, 0, 0)).julianDay, 2_450_173);
_assertPred!"=="(DateTime(Date(1996, 3, 31), TimeOfDay(12, 0, 0)).julianDay, 2_450_174);
_assertPred!"=="(DateTime(Date(2010, 8, 24), TimeOfDay(0, 0, 0)).julianDay, 2_455_432);
_assertPred!"=="(DateTime(Date(2010, 8, 24), TimeOfDay(12, 0, 0)).julianDay, 2_455_433);
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.julianDay));
static assert(__traits(compiles, idt.julianDay));
}
}
/++
The modified julian day for any time on this date (since, the modified
julian day changes at midnight).
+/
@property long modJulianDay() const pure nothrow
{
return _date.modJulianDay;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DateTime(Date(1858, 11, 17), TimeOfDay(0, 0, 0)).modJulianDay, 0);
_assertPred!"=="(DateTime(Date(1858, 11, 17), TimeOfDay(12, 0, 0)).modJulianDay, 0);
_assertPred!"=="(DateTime(Date(2010, 8, 24), TimeOfDay(0, 0, 0)).modJulianDay, 55_432);
_assertPred!"=="(DateTime(Date(2010, 8, 24), TimeOfDay(12, 0, 0)).modJulianDay, 55_432);
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, cdt.modJulianDay));
static assert(__traits(compiles, idt.modJulianDay));
}
}
/++
Converts this $(D DateTime) to a string with the format YYYYMMDDTHHMMSS.
Examples:
--------------------
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOString() ==
"20100704T070612");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOString() ==
"19981225T021500");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOString() ==
"00000105T230959");
assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOString() ==
"-00040105T000002");
--------------------
+/
string toISOString() const nothrow
{
try
return format("%sT%s", _date.toISOString(), _tod.toISOString());
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(DateTime(Date(9, 12, 4), TimeOfDay(0, 0, 0)).toISOString(), "00091204T000000");
_assertPred!"=="(DateTime(Date(99, 12, 4), TimeOfDay(5, 6, 12)).toISOString(), "00991204T050612");
_assertPred!"=="(DateTime(Date(999, 12, 4), TimeOfDay(13, 44, 59)).toISOString(), "09991204T134459");
_assertPred!"=="(DateTime(Date(9999, 7, 4), TimeOfDay(23, 59, 59)).toISOString(), "99990704T235959");
_assertPred!"=="(DateTime(Date(10000, 10, 20), TimeOfDay(1, 1, 1)).toISOString(), "+100001020T010101");
//Test B.C.
_assertPred!"=="(DateTime(Date(0, 12, 4), TimeOfDay(0, 12, 4)).toISOString(), "00001204T001204");
_assertPred!"=="(DateTime(Date(-9, 12, 4), TimeOfDay(0, 0, 0)).toISOString(), "-00091204T000000");
_assertPred!"=="(DateTime(Date(-99, 12, 4), TimeOfDay(5, 6, 12)).toISOString(), "-00991204T050612");
_assertPred!"=="(DateTime(Date(-999, 12, 4), TimeOfDay(13, 44, 59)).toISOString(), "-09991204T134459");
_assertPred!"=="(DateTime(Date(-9999, 7, 4), TimeOfDay(23, 59, 59)).toISOString(), "-99990704T235959");
_assertPred!"=="(DateTime(Date(-10000, 10, 20), TimeOfDay(1, 1, 1)).toISOString(), "-100001020T010101");
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.toISOString()));
static assert(__traits(compiles, idt.toISOString()));
//Verify Examples.
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOString() == "20100704T070612");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOString() == "19981225T021500");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOString() == "00000105T230959");
assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOString() == "-00040105T000002");
}
}
/++
Converts this $(D DateTime) to a string with the format
YYYY-MM-DDTHH:MM:SS.
Examples:
--------------------
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtString() ==
"2010-07-04T07:06:12");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtString() ==
"1998-12-25T02:15:00");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtString() ==
"0000-01-05T23:09:59");
assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtString() ==
"-0004-01-05T00:00:02");
--------------------
+/
string toISOExtString() const nothrow
{
try
return format("%sT%s", _date.toISOExtString(), _tod.toISOExtString());
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(DateTime(Date(9, 12, 4), TimeOfDay(0, 0, 0)).toISOExtString(), "0009-12-04T00:00:00");
_assertPred!"=="(DateTime(Date(99, 12, 4), TimeOfDay(5, 6, 12)).toISOExtString(), "0099-12-04T05:06:12");
_assertPred!"=="(DateTime(Date(999, 12, 4), TimeOfDay(13, 44, 59)).toISOExtString(), "0999-12-04T13:44:59");
_assertPred!"=="(DateTime(Date(9999, 7, 4), TimeOfDay(23, 59, 59)).toISOExtString(), "9999-07-04T23:59:59");
_assertPred!"=="(DateTime(Date(10000, 10, 20), TimeOfDay(1, 1, 1)).toISOExtString(), "+10000-10-20T01:01:01");
//Test B.C.
_assertPred!"=="(DateTime(Date(0, 12, 4), TimeOfDay(0, 12, 4)).toISOExtString(), "0000-12-04T00:12:04");
_assertPred!"=="(DateTime(Date(-9, 12, 4), TimeOfDay(0, 0, 0)).toISOExtString(), "-0009-12-04T00:00:00");
_assertPred!"=="(DateTime(Date(-99, 12, 4), TimeOfDay(5, 6, 12)).toISOExtString(), "-0099-12-04T05:06:12");
_assertPred!"=="(DateTime(Date(-999, 12, 4), TimeOfDay(13, 44, 59)).toISOExtString(), "-0999-12-04T13:44:59");
_assertPred!"=="(DateTime(Date(-9999, 7, 4), TimeOfDay(23, 59, 59)).toISOExtString(), "-9999-07-04T23:59:59");
_assertPred!"=="(DateTime(Date(-10000, 10, 20), TimeOfDay(1, 1, 1)).toISOExtString(), "-10000-10-20T01:01:01");
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.toISOExtString()));
static assert(__traits(compiles, idt.toISOExtString()));
//Verify Examples.
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtString() == "2010-07-04T07:06:12");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtString() == "1998-12-25T02:15:00");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtString() == "0000-01-05T23:09:59");
assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtString() == "-0004-01-05T00:00:02");
}
}
/++
Converts this $(D DateTime) to a string with the format
YYYY-Mon-DD HH:MM:SS.
Examples:
--------------------
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() ==
"2010-Jul-04 07:06:12");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() ==
"1998-Dec-25 02:15:00");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() ==
"0000-Jan-05 23:09:59");
assert(DateTime(Dte(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() ==
"-0004-Jan-05 00:00:02");
--------------------
+/
string toSimpleString() const nothrow
{
try
return format("%s %s", _date.toSimpleString(), _tod.toString());
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(DateTime(Date(9, 12, 4), TimeOfDay(0, 0, 0)).toSimpleString(), "0009-Dec-04 00:00:00");
_assertPred!"=="(DateTime(Date(99, 12, 4), TimeOfDay(5, 6, 12)).toSimpleString(), "0099-Dec-04 05:06:12");
_assertPred!"=="(DateTime(Date(999, 12, 4), TimeOfDay(13, 44, 59)).toSimpleString(), "0999-Dec-04 13:44:59");
_assertPred!"=="(DateTime(Date(9999, 7, 4), TimeOfDay(23, 59, 59)).toSimpleString(), "9999-Jul-04 23:59:59");
_assertPred!"=="(DateTime(Date(10000, 10, 20), TimeOfDay(1, 1, 1)).toSimpleString(), "+10000-Oct-20 01:01:01");
//Test B.C.
_assertPred!"=="(DateTime(Date(0, 12, 4), TimeOfDay(0, 12, 4)).toSimpleString(), "0000-Dec-04 00:12:04");
_assertPred!"=="(DateTime(Date(-9, 12, 4), TimeOfDay(0, 0, 0)).toSimpleString(), "-0009-Dec-04 00:00:00");
_assertPred!"=="(DateTime(Date(-99, 12, 4), TimeOfDay(5, 6, 12)).toSimpleString(), "-0099-Dec-04 05:06:12");
_assertPred!"=="(DateTime(Date(-999, 12, 4), TimeOfDay(13, 44, 59)).toSimpleString(), "-0999-Dec-04 13:44:59");
_assertPred!"=="(DateTime(Date(-9999, 7, 4), TimeOfDay(23, 59, 59)).toSimpleString(), "-9999-Jul-04 23:59:59");
_assertPred!"=="(DateTime(Date(-10000, 10, 20), TimeOfDay(1, 1, 1)).toSimpleString(), "-10000-Oct-20 01:01:01");
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(__traits(compiles, cdt.toSimpleString()));
static assert(__traits(compiles, idt.toSimpleString()));
//Verify Examples.
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12");
assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() == "1998-Dec-25 02:15:00");
assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() == "0000-Jan-05 23:09:59");
assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() == "-0004-Jan-05 00:00:02");
}
}
/+
Converts this $(D DateTime) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return toSimpleString();
}
/++
Converts this $(D DateTime) to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return toSimpleString();
}
unittest
{
version(testStdDateTime)
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
static assert(__traits(compiles, dt.toString()));
static assert(__traits(compiles, cdt.toString()));
static assert(__traits(compiles, idt.toString()));
}
}
/++
Creates a $(D DateTime) from a string with the format YYYYMMDDTHHMMSS.
Whitespace is stripped from the given string.
Params:
isoString = A string formatted in the ISO format for dates and times.
Throws:
$(D DateTimeException) if the given string is not in the ISO format
or if the resulting $(D DateTime) would not be valid.
Examples:
--------------------
assert(DateTime.fromISOString("20100704T070612") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromISOString("19981225T021500") ==
DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromISOString("00000105T230959") ==
DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromISOString("-00040105T000002") ==
DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromISOString(" 20100704T070612 ") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
--------------------
+/
static DateTime fromISOString(S)(in S isoString)
if(isSomeString!S)
{
immutable dstr = to!dstring(strip(isoString));
enforce(dstr.length >= 15, new DateTimeException(format("Invalid ISO String: %s", isoString)));
auto t = dstr.stds_indexOf('T');
enforce(t != -1, new DateTimeException(format("Invalid ISO String: %s", isoString)));
immutable date = Date.fromISOString(dstr[0..t]);
immutable tod = TimeOfDay.fromISOString(dstr[t+1 .. $]);
return DateTime(date, tod);
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(DateTime.fromISOString(""));
assertThrown!DateTimeException(DateTime.fromISOString("20100704000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704 000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704t000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704T000000."));
assertThrown!DateTimeException(DateTime.fromISOString("20100704T000000.0"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04T00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04T00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-12-22T172201"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Dec-22 17:22:01"));
_assertPred!"=="(DateTime.fromISOString("20101222T172201"), DateTime(Date(2010, 12, 22), TimeOfDay(17, 22, 01)));
_assertPred!"=="(DateTime.fromISOString("19990706T123033"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOString("-19990706T123033"), DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOString("+019990706T123033"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOString("19990706T123033 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOString(" 19990706T123033"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOString(" 19990706T123033 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
//Verify Examples.
assert(DateTime.fromISOString("20100704T070612") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromISOString("19981225T021500") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromISOString("00000105T230959") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromISOString("-00040105T000002") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromISOString(" 20100704T070612 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
}
}
/++
Creates a $(D DateTime) from a string with the format
YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.
Params:
isoString = A string formatted in the ISO Extended format for dates
and times.
Throws:
$(D DateTimeException) if the given string is not in the ISO
Extended format or if the resulting $(D DateTime) would not be
valid.
Examples:
--------------------
assert(DateTime.fromISOExtString("2010-07-04T07:06:12") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromISOExtString("1998-12-25T02:15:00") ==
DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromISOExtString("0000-01-05T23:09:59") ==
DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromISOExtString("-0004-01-05T00:00:02") ==
DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromISOExtString(" 2010-07-04T07:06:12 ") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
--------------------
+/
static DateTime fromISOExtString(S)(in S isoExtString)
if(isSomeString!(S))
{
immutable dstr = to!dstring(strip(isoExtString));
enforce(dstr.length >= 15, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto t = dstr.stds_indexOf('T');
enforce(t != -1, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
immutable date = Date.fromISOExtString(dstr[0..t]);
immutable tod = TimeOfDay.fromISOExtString(dstr[t+1 .. $]);
return DateTime(date, tod);
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(DateTime.fromISOExtString(""));
assertThrown!DateTimeException(DateTime.fromISOExtString("20100704000000"));
assertThrown!DateTimeException(DateTime.fromISOExtString("20100704 000000"));
assertThrown!DateTimeException(DateTime.fromISOExtString("20100704t000000"));
assertThrown!DateTimeException(DateTime.fromISOExtString("20100704T000000."));
assertThrown!DateTimeException(DateTime.fromISOExtString("20100704T000000.0"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07:0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-07-04T00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-Jul-04 00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromISOExtString("20101222T172201"));
assertThrown!DateTimeException(DateTime.fromISOExtString("2010-Dec-22 17:22:01"));
_assertPred!"=="(DateTime.fromISOExtString("2010-12-22T17:22:01"), DateTime(Date(2010, 12, 22), TimeOfDay(17, 22, 01)));
_assertPred!"=="(DateTime.fromISOExtString("1999-07-06T12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOExtString("-1999-07-06T12:30:33"), DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOExtString("+01999-07-06T12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOExtString("1999-07-06T12:30:33 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOExtString(" 1999-07-06T12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromISOExtString(" 1999-07-06T12:30:33 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
//Verify Examples.
assert(DateTime.fromISOExtString("2010-07-04T07:06:12") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromISOExtString("1998-12-25T02:15:00") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromISOExtString("0000-01-05T23:09:59") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromISOExtString("-0004-01-05T00:00:02") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromISOExtString(" 2010-07-04T07:06:12 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
}
}
/++
Creates a $(D DateTime) from a string with the format
YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.
Params:
simpleString = A string formatted in the way that toSimpleString
formats dates and times.
Throws:
$(D DateTimeException) if the given string is not in the correct
format or if the resulting $(D DateTime) would not be valid.
Examples:
--------------------
assert(DateTime.fromSimpleString("2010-Jul-04 07:06:12") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromSimpleString("1998-Dec-25 02:15:00") ==
DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromSimpleString("0000-Jan-05 23:09:59") ==
DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromSimpleString("-0004-Jan-05 00:00:02") ==
DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") ==
DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
--------------------
+/
static DateTime fromSimpleString(S)(in S simpleString)
if(isSomeString!(S))
{
immutable dstr = to!dstring(strip(simpleString));
enforce(dstr.length >= 15, new DateTimeException(format("Invalid string format: %s", simpleString)));
auto t = dstr.stds_indexOf(' ');
enforce(t != -1, new DateTimeException(format("Invalid string format: %s", simpleString)));
immutable date = Date.fromSimpleString(dstr[0..t]);
immutable tod = TimeOfDay.fromISOExtString(dstr[t+1 .. $]);
return DateTime(date, tod);
}
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(DateTime.fromISOString(""));
assertThrown!DateTimeException(DateTime.fromISOString("20100704000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704 000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704t000000"));
assertThrown!DateTimeException(DateTime.fromISOString("20100704T000000."));
assertThrown!DateTimeException(DateTime.fromISOString("20100704T000000.0"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04T00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOString("2010-07-04T00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-0400:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04t00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04T00:00:00"));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00."));
assertThrown!DateTimeException(DateTime.fromISOString("2010-Jul-04 00:00:00.0"));
assertThrown!DateTimeException(DateTime.fromSimpleString("20101222T172201"));
assertThrown!DateTimeException(DateTime.fromSimpleString("2010-12-22T172201"));
_assertPred!"=="(DateTime.fromSimpleString("2010-Dec-22 17:22:01"), DateTime(Date(2010, 12, 22), TimeOfDay(17, 22, 01)));
_assertPred!"=="(DateTime.fromSimpleString("1999-Jul-06 12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromSimpleString("-1999-Jul-06 12:30:33"), DateTime(Date(-1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromSimpleString("+01999-Jul-06 12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromSimpleString("1999-Jul-06 12:30:33 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromSimpleString(" 1999-Jul-06 12:30:33"), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
_assertPred!"=="(DateTime.fromSimpleString(" 1999-Jul-06 12:30:33 "), DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)));
//Verify Examples.
assert(DateTime.fromSimpleString("2010-Jul-04 07:06:12") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
assert(DateTime.fromSimpleString("1998-Dec-25 02:15:00") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)));
assert(DateTime.fromSimpleString("0000-Jan-05 23:09:59") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)));
assert(DateTime.fromSimpleString("-0004-Jan-05 00:00:02") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)));
assert(DateTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
}
}
//TODO Add function which takes a user-specified time format and produces a DateTime
//TODO Add function which takes pretty much any time-string and produces a DateTime
// Obviously, it will be less efficient, and it probably won't manage _every_
// possible date format, but a smart conversion function would be nice.
/++
Returns the $(D DateTime) farthest in the past which is representable by
$(D DateTime).
+/
@property static DateTime min() pure nothrow
out(result)
{
assert(result._date == Date.min);
assert(result._tod == TimeOfDay.min);
}
body
{
auto dt = DateTime.init;
dt._date._year = short.min;
dt._date._month = Month.jan;
dt._date._day = 1;
return dt;
}
unittest
{
version(testStdDateTime)
{
assert(DateTime.min.year < 0);
assert(DateTime.min < DateTime.max);
}
}
/++
Returns the $(D DateTime) farthest in the future which is representable
by $(D DateTime).
+/
@property static DateTime max() pure nothrow
out(result)
{
assert(result._date == Date.max);
assert(result._tod == TimeOfDay.max);
}
body
{
auto dt = DateTime.init;
dt._date._year = short.max;
dt._date._month = Month.dec;
dt._date._day = 31;
dt._tod._hour = TimeOfDay.maxHour;
dt._tod._minute = TimeOfDay.maxMinute;
dt._tod._second = TimeOfDay.maxSecond;
return dt;
}
unittest
{
version(testStdDateTime)
{
assert(DateTime.max.year > 0);
assert(DateTime.max > DateTime.min);
}
}
private:
/+
Add seconds to the time of day. Negative values will subtract. If the
number of seconds overflows (or underflows), then the seconds will wrap,
increasing (or decreasing) the number of minutes accordingly. The
same goes for any larger units.
Params:
seconds = The number of seconds to add to this $(D DateTime).
+/
ref DateTime addSeconds(long seconds) pure nothrow
{
long hnsecs = convert!("seconds", "hnsecs")(seconds);
hnsecs += convert!("hours", "hnsecs")(_tod._hour);
hnsecs += convert!("minutes", "hnsecs")(_tod._minute);
hnsecs += convert!("seconds", "hnsecs")(_tod._second);
auto days = splitUnitsFromHNSecs!"days"(hnsecs);
if(hnsecs < 0)
{
hnsecs += convert!("days", "hnsecs")(1);
--days;
}
_date.addDays(days);
immutable newHours = splitUnitsFromHNSecs!"hours"(hnsecs);
immutable newMinutes = splitUnitsFromHNSecs!"minutes"(hnsecs);
immutable newSeconds = splitUnitsFromHNSecs!"seconds"(hnsecs);
_tod._hour = cast(ubyte)newHours;
_tod._minute = cast(ubyte)newMinutes;
_tod._second = cast(ubyte)newSeconds;
return this;
}
unittest
{
version(testStdDateTime)
{
static void testDT(DateTime orig, int seconds, in DateTime expected, size_t line = __LINE__)
{
orig.addSeconds(seconds);
_assertPred!"=="(orig, expected, "", __FILE__, line);
}
//Test A.D.
testDT(DateTime(1999, 7, 6, 12, 30, 33), 0, DateTime(1999, 7, 6, 12, 30, 33));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 1, DateTime(1999, 7, 6, 12, 30, 34));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 2, DateTime(1999, 7, 6, 12, 30, 35));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 3, DateTime(1999, 7, 6, 12, 30, 36));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 4, DateTime(1999, 7, 6, 12, 30, 37));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 5, DateTime(1999, 7, 6, 12, 30, 38));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 10, DateTime(1999, 7, 6, 12, 30, 43));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 15, DateTime(1999, 7, 6, 12, 30, 48));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 26, DateTime(1999, 7, 6, 12, 30, 59));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 27, DateTime(1999, 7, 6, 12, 31, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 30, DateTime(1999, 7, 6, 12, 31, 3));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 59, DateTime(1999, 7, 6, 12, 31, 32));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 60, DateTime(1999, 7, 6, 12, 31, 33));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 61, DateTime(1999, 7, 6, 12, 31, 34));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 1766, DateTime(1999, 7, 6, 12, 59, 59));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 1767, DateTime(1999, 7, 6, 13, 0, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 1768, DateTime(1999, 7, 6, 13, 0, 1));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 2007, DateTime(1999, 7, 6, 13, 4, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 3599, DateTime(1999, 7, 6, 13, 30, 32));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 3600, DateTime(1999, 7, 6, 13, 30, 33));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 3601, DateTime(1999, 7, 6, 13, 30, 34));
testDT(DateTime(1999, 7, 6, 12, 30, 33), 7200, DateTime(1999, 7, 6, 14, 30, 33));
testDT(DateTime(1999, 7, 6, 23, 0, 0), 432_123, DateTime(1999, 7, 11, 23, 2, 3));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -1, DateTime(1999, 7, 6, 12, 30, 32));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -2, DateTime(1999, 7, 6, 12, 30, 31));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -3, DateTime(1999, 7, 6, 12, 30, 30));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -4, DateTime(1999, 7, 6, 12, 30, 29));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -5, DateTime(1999, 7, 6, 12, 30, 28));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -10, DateTime(1999, 7, 6, 12, 30, 23));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -15, DateTime(1999, 7, 6, 12, 30, 18));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -33, DateTime(1999, 7, 6, 12, 30, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -34, DateTime(1999, 7, 6, 12, 29, 59));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -35, DateTime(1999, 7, 6, 12, 29, 58));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -59, DateTime(1999, 7, 6, 12, 29, 34));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -60, DateTime(1999, 7, 6, 12, 29, 33));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -61, DateTime(1999, 7, 6, 12, 29, 32));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -1833, DateTime(1999, 7, 6, 12, 0, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -1834, DateTime(1999, 7, 6, 11, 59, 59));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -3600, DateTime(1999, 7, 6, 11, 30, 33));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -3601, DateTime(1999, 7, 6, 11, 30, 32));
testDT(DateTime(1999, 7, 6, 12, 30, 33), -5134, DateTime(1999, 7, 6, 11, 4, 59));
testDT(DateTime(1999, 7, 6, 23, 0, 0), -432_123, DateTime(1999, 7, 1, 22, 57, 57));
testDT(DateTime(1999, 7, 6, 12, 30, 0), 1, DateTime(1999, 7, 6, 12, 30, 1));
testDT(DateTime(1999, 7, 6, 12, 30, 0), 0, DateTime(1999, 7, 6, 12, 30, 0));
testDT(DateTime(1999, 7, 6, 12, 30, 0), -1, DateTime(1999, 7, 6, 12, 29, 59));
testDT(DateTime(1999, 7, 6, 12, 0, 0), 1, DateTime(1999, 7, 6, 12, 0, 1));
testDT(DateTime(1999, 7, 6, 12, 0, 0), 0, DateTime(1999, 7, 6, 12, 0, 0));
testDT(DateTime(1999, 7, 6, 12, 0, 0), -1, DateTime(1999, 7, 6, 11, 59, 59));
testDT(DateTime(1999, 7, 6, 0, 0, 0), 1, DateTime(1999, 7, 6, 0, 0, 1));
testDT(DateTime(1999, 7, 6, 0, 0, 0), 0, DateTime(1999, 7, 6, 0, 0, 0));
testDT(DateTime(1999, 7, 6, 0, 0, 0), -1, DateTime(1999, 7, 5, 23, 59, 59));
testDT(DateTime(1999, 7, 5, 23, 59, 59), 1, DateTime(1999, 7, 6, 0, 0, 0));
testDT(DateTime(1999, 7, 5, 23, 59, 59), 0, DateTime(1999, 7, 5, 23, 59, 59));
testDT(DateTime(1999, 7, 5, 23, 59, 59), -1, DateTime(1999, 7, 5, 23, 59, 58));
testDT(DateTime(1998, 12, 31, 23, 59, 59), 1, DateTime(1999, 1, 1, 0, 0, 0));
testDT(DateTime(1998, 12, 31, 23, 59, 59), 0, DateTime(1998, 12, 31, 23, 59, 59));
testDT(DateTime(1998, 12, 31, 23, 59, 59), -1, DateTime(1998, 12, 31, 23, 59, 58));
testDT(DateTime(1998, 1, 1, 0, 0, 0), 1, DateTime(1998, 1, 1, 0, 0, 1));
testDT(DateTime(1998, 1, 1, 0, 0, 0), 0, DateTime(1998, 1, 1, 0, 0, 0));
testDT(DateTime(1998, 1, 1, 0, 0, 0), -1, DateTime(1997, 12, 31, 23, 59, 59));
//Test B.C.
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 0, DateTime(-1999, 7, 6, 12, 30, 33));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 1, DateTime(-1999, 7, 6, 12, 30, 34));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 2, DateTime(-1999, 7, 6, 12, 30, 35));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 3, DateTime(-1999, 7, 6, 12, 30, 36));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 4, DateTime(-1999, 7, 6, 12, 30, 37));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 5, DateTime(-1999, 7, 6, 12, 30, 38));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 10, DateTime(-1999, 7, 6, 12, 30, 43));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 15, DateTime(-1999, 7, 6, 12, 30, 48));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 26, DateTime(-1999, 7, 6, 12, 30, 59));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 27, DateTime(-1999, 7, 6, 12, 31, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 30, DateTime(-1999, 7, 6, 12, 31, 3));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 59, DateTime(-1999, 7, 6, 12, 31, 32));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 60, DateTime(-1999, 7, 6, 12, 31, 33));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 61, DateTime(-1999, 7, 6, 12, 31, 34));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 1766, DateTime(-1999, 7, 6, 12, 59, 59));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 1767, DateTime(-1999, 7, 6, 13, 0, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 1768, DateTime(-1999, 7, 6, 13, 0, 1));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 2007, DateTime(-1999, 7, 6, 13, 4, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 3599, DateTime(-1999, 7, 6, 13, 30, 32));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 3600, DateTime(-1999, 7, 6, 13, 30, 33));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 3601, DateTime(-1999, 7, 6, 13, 30, 34));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), 7200, DateTime(-1999, 7, 6, 14, 30, 33));
testDT(DateTime(-1999, 7, 6, 23, 0, 0), 432_123, DateTime(-1999, 7, 11, 23, 2, 3));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -1, DateTime(-1999, 7, 6, 12, 30, 32));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -2, DateTime(-1999, 7, 6, 12, 30, 31));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -3, DateTime(-1999, 7, 6, 12, 30, 30));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -4, DateTime(-1999, 7, 6, 12, 30, 29));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -5, DateTime(-1999, 7, 6, 12, 30, 28));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -10, DateTime(-1999, 7, 6, 12, 30, 23));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -15, DateTime(-1999, 7, 6, 12, 30, 18));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -33, DateTime(-1999, 7, 6, 12, 30, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -34, DateTime(-1999, 7, 6, 12, 29, 59));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -35, DateTime(-1999, 7, 6, 12, 29, 58));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -59, DateTime(-1999, 7, 6, 12, 29, 34));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -60, DateTime(-1999, 7, 6, 12, 29, 33));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -61, DateTime(-1999, 7, 6, 12, 29, 32));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -1833, DateTime(-1999, 7, 6, 12, 0, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -1834, DateTime(-1999, 7, 6, 11, 59, 59));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -3600, DateTime(-1999, 7, 6, 11, 30, 33));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -3601, DateTime(-1999, 7, 6, 11, 30, 32));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -5134, DateTime(-1999, 7, 6, 11, 4, 59));
testDT(DateTime(-1999, 7, 6, 12, 30, 33), -7200, DateTime(-1999, 7, 6, 10, 30, 33));
testDT(DateTime(-1999, 7, 6, 23, 0, 0), -432_123, DateTime(-1999, 7, 1, 22, 57, 57));
testDT(DateTime(-1999, 7, 6, 12, 30, 0), 1, DateTime(-1999, 7, 6, 12, 30, 1));
testDT(DateTime(-1999, 7, 6, 12, 30, 0), 0, DateTime(-1999, 7, 6, 12, 30, 0));
testDT(DateTime(-1999, 7, 6, 12, 30, 0), -1, DateTime(-1999, 7, 6, 12, 29, 59));
testDT(DateTime(-1999, 7, 6, 12, 0, 0), 1, DateTime(-1999, 7, 6, 12, 0, 1));
testDT(DateTime(-1999, 7, 6, 12, 0, 0), 0, DateTime(-1999, 7, 6, 12, 0, 0));
testDT(DateTime(-1999, 7, 6, 12, 0, 0), -1, DateTime(-1999, 7, 6, 11, 59, 59));
testDT(DateTime(-1999, 7, 6, 0, 0, 0), 1, DateTime(-1999, 7, 6, 0, 0, 1));
testDT(DateTime(-1999, 7, 6, 0, 0, 0), 0, DateTime(-1999, 7, 6, 0, 0, 0));
testDT(DateTime(-1999, 7, 6, 0, 0, 0), -1, DateTime(-1999, 7, 5, 23, 59, 59));
testDT(DateTime(-1999, 7, 5, 23, 59, 59), 1, DateTime(-1999, 7, 6, 0, 0, 0));
testDT(DateTime(-1999, 7, 5, 23, 59, 59), 0, DateTime(-1999, 7, 5, 23, 59, 59));
testDT(DateTime(-1999, 7, 5, 23, 59, 59), -1, DateTime(-1999, 7, 5, 23, 59, 58));
testDT(DateTime(-2000, 12, 31, 23, 59, 59), 1, DateTime(-1999, 1, 1, 0, 0, 0));
testDT(DateTime(-2000, 12, 31, 23, 59, 59), 0, DateTime(-2000, 12, 31, 23, 59, 59));
testDT(DateTime(-2000, 12, 31, 23, 59, 59), -1, DateTime(-2000, 12, 31, 23, 59, 58));
testDT(DateTime(-2000, 1, 1, 0, 0, 0), 1, DateTime(-2000, 1, 1, 0, 0, 1));
testDT(DateTime(-2000, 1, 1, 0, 0, 0), 0, DateTime(-2000, 1, 1, 0, 0, 0));
testDT(DateTime(-2000, 1, 1, 0, 0, 0), -1, DateTime(-2001, 12, 31, 23, 59, 59));
//Test Both
testDT(DateTime(1, 1, 1, 0, 0, 0), -1, DateTime(0, 12, 31, 23, 59, 59));
testDT(DateTime(0, 12, 31, 23, 59, 59), 1, DateTime(1, 1, 1, 0, 0, 0));
testDT(DateTime(0, 1, 1, 0, 0, 0), -1, DateTime(-1, 12, 31, 23, 59, 59));
testDT(DateTime(-1, 12, 31, 23, 59, 59), 1, DateTime(0, 1, 1, 0, 0, 0));
testDT(DateTime(-1, 1, 1, 11, 30, 33), 63_165_600L, DateTime(1, 1, 1, 13, 30, 33));
testDT(DateTime(1, 1, 1, 13, 30, 33), -63_165_600L, DateTime(-1, 1, 1, 11, 30, 33));
testDT(DateTime(-1, 1, 1, 11, 30, 33), 63_165_617L, DateTime(1, 1, 1, 13, 30, 50));
testDT(DateTime(1, 1, 1, 13, 30, 50), -63_165_617L, DateTime(-1, 1, 1, 11, 30, 33));
const cdt = DateTime(1999, 7, 6, 12, 30, 33);
immutable idt = DateTime(1999, 7, 6, 12, 30, 33);
static assert(!__traits(compiles, cdt.addSeconds(4)));
static assert(!__traits(compiles, idt.addSeconds(4)));
}
}
Date _date;
TimeOfDay _tod;
}
//==============================================================================
// Section with intervals.
//==============================================================================
/++
Represents an interval of time.
An $(D Interval) has a starting point and an end point. The interval of time
is therefore the time starting at the starting point up to, but not
including, the end point. e.g.
$(BOOKTABLE,
$(TR $(TD [January 5th, 2010 - March 10th, 2010$(RPAREN)))
$(TR $(TD [05:00:30 - 12:00:00$(RPAREN)))
$(TR $(TD [1982-01-04T08:59:00 - 2010-07-04T12:00:00$(RPAREN)))
)
A range can be obtained from an $(D Interval), allowing iteration over
that interval, with the exact time points which are iterated over depending
on the function which generates the range.
+/
struct Interval(TP)
{
public:
/++
Params:
begin = The time point which begins the interval.
end = The time point which ends (but is not included in) the
interval.
Throws:
$(D DateTimeException) if $(D_PARAM end) is before $(D_PARAM begin).
Examples:
--------------------
Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
--------------------
+/
this(U)(in TP begin, in U end) pure
if(is(Unqual!TP == Unqual!U))
{
if(!_valid(begin, end))
throw new DateTimeException("Arguments would result in an invalid Interval.");
_begin = cast(TP)begin;
_end = cast(TP)end;
}
/++
Params:
begin = The time point which begins the interval.
duration = The duration from the starting point to the end point.
Throws:
$(D DateTimeException) if the resulting $(D end) is before
$(D begin).
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), dur!"years"(3)) ==
Interval!Date(Date(1996, 1, 2), Date(1999, 1, 2)));
--------------------
+/
this(D)(in TP begin, in D duration) pure
if(__traits(compiles, begin + duration))
{
_begin = cast(TP)begin;
_end = begin + duration;
if(!_valid(_begin, _end))
throw new DateTimeException("Arguments would result in an invalid Interval.");
}
/++
Params:
rhs = The $(D Interval) to assign to this one.
+/
/+ref+/ Interval opAssign(const ref Interval rhs) pure nothrow
{
_begin = cast(TP)rhs._begin;
_end = cast(TP)rhs._end;
return this;
}
/++
Params:
rhs = The $(D Interval) to assign to this one.
+/
/+ref+/ Interval opAssign(Interval rhs) pure nothrow
{
_begin = cast(TP)rhs._begin;
_end = cast(TP)rhs._end;
return this;
}
/++
The starting point of the interval. It is included in the interval.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).begin ==
Date(1996, 1, 2));
--------------------
+/
@property TP begin() const pure nothrow
{
return cast(TP)_begin;
}
/++
The starting point of the interval. It is included in the interval.
Params:
timePoint = The time point to set $(D begin) to.
Throws:
$(D DateTimeException) if the resulting interval would be invalid.
+/
@property void begin(TP timePoint) pure
{
if(!_valid(timePoint, _end))
throw new DateTimeException("Arguments would result in an invalid Interval.");
_begin = timePoint;
}
/++
The end point of the interval. It is excluded from the interval.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).end ==
Date(2012, 3, 1));
--------------------
+/
@property TP end() const pure nothrow
{
return cast(TP)_end;
}
/++
The end point of the interval. It is excluded from the interval.
Params:
timePoint = The time point to set end to.
Throws:
$(D DateTimeException) if the resulting interval would be invalid.
+/
@property void end(TP timePoint) pure
{
if(!_valid(_begin, timePoint))
throw new DateTimeException("Arguments would result in an invalid Interval.");
_end = timePoint;
}
/++
Returns the duration between $(D begin) and $(D end).
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).length ==
dur!"days"(5903));
--------------------
+/
@property typeof(end - begin) length() const pure nothrow
{
return _end - _begin;
}
/++
Whether the interval's length is 0, that is, whether $(D begin == end).
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(1996, 1, 2)).empty);
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).empty);
--------------------
+/
@property bool empty() const pure nothrow
{
return _begin == _end;
}
/++
Whether the given time point is within this interval.
Params:
timePoint = The time point to check for inclusion in this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Date(1994, 12, 24)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Date(2000, 1, 5)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Date(2012, 3, 1)));
--------------------
+/
bool contains(in TP timePoint) const pure
{
_enforceNotEmpty();
return timePoint >= _begin && timePoint < _end;
}
/++
Whether the given interval is completely within this interval.
Params:
interval = The interval to check for inclusion in this interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
--------------------
+/
bool contains(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
return interval._begin >= _begin &&
interval._begin < _end &&
interval._end <= _end;
}
/++
Whether the given interval is completely within this interval.
Always returns false (unless this interval is empty), because an
interval going to positive infinity can never be contained in a finite
interval.
Params:
interval = The interval to check for inclusion in this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
PosInfInterval!Date(Date(1999, 5, 4))));
--------------------
+/
bool contains(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return false;
}
/++
Whether the given interval is completely within this interval.
Always returns false (unless this interval is empty), because an
interval beginning at negative infinity can never be contained in a
finite interval.
Params:
interval = The interval to check for inclusion in this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
NegInfInterval!Date(Date(1996, 5, 4))));
--------------------
+/
bool contains(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return false;
}
/++
Whether this interval is before the given time point.
Params:
timePoint = The time point to check whether this interval is before
it.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Date(1994, 12, 24)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Date(2000, 1, 5)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Date(2012, 3, 1)));
--------------------
+/
bool isBefore(in TP timePoint) const pure
{
_enforceNotEmpty();
return _end <= timePoint;
}
/++
Whether this interval is before the given interval and does not
intersect with it.
Params:
interval = The interval to check for against this interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
Interval!Date(Date(2012, 3, 1), Date(2013, 5, 1))));
--------------------
+/
bool isBefore(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
return _end <= interval._begin;
}
/++
Whether this interval is before the given interval and does not
intersect with it.
Params:
interval = The interval to check for against this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
PosInfInterval!Date(Date(2013, 3, 7))));
--------------------
+/
bool isBefore(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _end <= interval._begin;
}
/++
Whether this interval is before the given interval and does not
intersect with it.
Always returns false (unless this interval is empty) because a finite
interval can never be before an interval beginning at negative infinity.
Params:
interval = The interval to check for against this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
NegInfInterval!Date(Date(1996, 5, 4))));
--------------------
+/
bool isBefore(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return false;
}
/++
Whether this interval is after the given time point.
Params:
timePoint = The time point to check whether this interval is after
it.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Date(1994, 12, 24)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Date(2000, 1, 5)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Date(2012, 3, 1)));
--------------------
+/
bool isAfter(in TP timePoint) const pure
{
_enforceNotEmpty();
return timePoint < _begin;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Params:
interval = The interval to check against this interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
--------------------
+/
bool isAfter(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
return _begin >= interval._end;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Always returns false (unless this interval is empty) because a finite
interval can never be after an interval going to positive infinity.
Params:
interval = The interval to check against this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
PosInfInterval!Date(Date(1999, 5, 4))));
--------------------
+/
bool isAfter(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return false;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Params:
interval = The interval to check against this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
NegInfInterval!Date(Date(1996, 1, 2))));
--------------------
+/
bool isAfter(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _begin >= interval._end;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
--------------------
+/
bool intersects(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
return interval._begin < _end && interval._end > _begin;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool intersects(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _end > interval._begin;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
NegInfInterval!Date(Date(1996, 1, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(
NegInfInterval!Date(Date(2000, 1, 2))));
--------------------
+/
bool intersects(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _begin < interval._end;
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect or if
either interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) ==
Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
--------------------
+/
Interval intersection(in Interval interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
auto begin = _begin > interval._begin ? _begin : interval._begin;
auto end = _end < interval._end ? _end : interval._end;
return Interval(begin, end);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect or if
this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
PosInfInterval!Date(Date(1990, 7, 6))) ==
Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
PosInfInterval!Date(Date(1999, 1, 12))) ==
Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
--------------------
+/
Interval intersection(in PosInfInterval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
return Interval(_begin > interval._begin ? _begin : interval._begin, _end);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect or if
this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
NegInfInterval!Date(Date(1999, 7, 6))) ==
Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(
NegInfInterval!Date(Date(2013, 1, 12))) ==
Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1)));
--------------------
+/
Interval intersection(in NegInfInterval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
return Interval(_begin, _end < interval._end ? _end : interval._end);
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(1990, 7, 6), Date(1996, 1, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(2012, 3, 1), Date(2013, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(1989, 3, 1), Date(2012, 3, 1))));
--------------------
+/
bool isAdjacent(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
return _begin == interval._end || _end == interval._begin;
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool isAdjacent(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _end == interval._begin;
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
NegInfInterval!Date(Date(1996, 1, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(
NegInfInterval!Date(Date(2000, 1, 2))));
--------------------
+/
bool isAdjacent(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return _begin == interval._end;
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect and are
not adjacent or if either interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) ==
Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
--------------------
+/
Interval merge(in Interval interval) const
{
enforce(this.isAdjacent(interval) || this.intersects(interval),
new DateTimeException(format("%s and %s are not adjacent and do not intersect.", this, interval)));
auto begin = _begin < interval._begin ? _begin : interval._begin;
auto end = _end > interval._end ? _end : interval._end;
return Interval(begin, end);
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect and are
not adjacent or if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
PosInfInterval!Date(Date(1990, 7, 6))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
PosInfInterval!Date(Date(2012, 3, 1))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval!TP merge(in PosInfInterval!TP interval) const
{
enforce(this.isAdjacent(interval) || this.intersects(interval),
new DateTimeException(format("%s and %s are not adjacent and do not intersect.", this, interval)));
return PosInfInterval!TP(_begin < interval._begin ? _begin : interval._begin);
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect and are not
adjacent or if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
NegInfInterval!Date(Date(1996, 1, 2))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(
NegInfInterval!Date(Date(2013, 1, 12))) ==
NegInfInterval!Date(Date(2013, 1 , 12)));
--------------------
+/
NegInfInterval!TP merge(in NegInfInterval!TP interval) const
{
enforce(this.isAdjacent(interval) || this.intersects(interval),
new DateTimeException(format("%s and %s are not adjacent and do not intersect.", this, interval)));
return NegInfInterval!TP(_end > interval._end ? _end : interval._end);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this interval.
Throws:
$(D DateTimeException) if either interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
Interval!Date(Date(1990, 7, 6), Date(1991, 1, 8))) ==
Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) ==
Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
--------------------
+/
Interval span(in Interval interval) const pure
{
_enforceNotEmpty();
interval._enforceNotEmpty();
auto begin = _begin < interval._begin ? _begin : interval._begin;
auto end = _end > interval._end ? _end : interval._end;
return Interval(begin, end);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
PosInfInterval!Date(Date(1990, 7, 6))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
PosInfInterval!Date(Date(2050, 1, 1))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval!TP span(in PosInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return PosInfInterval!TP(_begin < interval._begin ? _begin : interval._begin);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this interval.
Throws:
$(D DateTimeException) if this interval is empty.
Examples:
--------------------
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
NegInfInterval!Date(Date(1602, 5, 21))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(
NegInfInterval!Date(Date(2013, 1, 12))) ==
NegInfInterval!Date(Date(2013, 1 , 12)));
--------------------
+/
NegInfInterval!TP span(in NegInfInterval!TP interval) const pure
{
_enforceNotEmpty();
return NegInfInterval!TP(_end > interval._end ? _end : interval._end);
}
/++
Shifts the interval forward or backwards in time by the given duration
(a positive duration shifts the interval forward; a negative duration
shifts it backward). Effectively, it does $(D begin += duration) and
$(D end += duration).
Params:
duration = The duration to shift the interval by.
Throws:
$(D DateTimeException) this interval is empty or if the resulting
interval would be invalid.
Examples:
--------------------
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5));
interval1.shift(dur!"days"(50));
assert(interval1 == Interval!Date(Date(1996, 2, 21), Date(2012, 5, 25)));
interval2.shift(dur!"days"(-50));
assert(interval2 == Interval!Date(Date(1995, 11, 13), Date(2012, 2, 15)));
--------------------
+/
void shift(D)(D duration) pure
if(__traits(compiles, begin + duration))
{
_enforceNotEmpty();
auto begin = _begin + duration;
auto end = _end + duration;
if(!_valid(begin, end))
throw new DateTimeException("Argument would result in an invalid Interval.");
_begin = begin;
_end = end;
}
static if(__traits(compiles, begin.add!"months"(1)) &&
__traits(compiles, begin.add!"years"(1)))
{
/++
Shifts the interval forward or backwards in time by the given number
of years and/or months (a positive number of years and months shifts
the interval forward; a negative number shifts it backward).
It adds the years the given years and months to both begin and end.
It effectively calls $(D add!"years"()) and then $(D add!"months"())
on begin and end with the given number of years and months.
Params:
years = The number of years to shift the interval by.
months = The number of months to shift the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D begin) and $(D end), causing their month
to increment.
Throws:
$(D DateTimeException) if this interval is empty or if the
resulting interval would be invalid.
Examples:
--------------------
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.shift(2);
assert(interval1 == Interval!Date(Date(1998, 1, 2), Date(2014, 3, 1)));
interval2.shift(-2);
assert(interval2 == Interval!Date(Date(1994, 1, 2), Date(2010, 3, 1)));
--------------------
+/
void shift(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
if(isIntegral!T)
{
_enforceNotEmpty();
auto begin = _begin;
auto end = _end;
begin.add!"years"(years, allowOverflow);
begin.add!"months"(months, allowOverflow);
end.add!"years"(years, allowOverflow);
end.add!"months"(months, allowOverflow);
enforce(_valid(begin, end), new DateTimeException("Argument would result in an invalid Interval."));
_begin = begin;
_end = end;
}
}
/++
Expands the interval forwards and/or backwards in time. Effectively,
it does $(D begin -= duration) and/or $(D end += duration). Whether
it expands forwards and/or backwards in time is determined by
$(D_PARAM dir).
Params:
duration = The duration to expand the interval by.
dir = The direction in time to expand the interval.
Throws:
$(D DateTimeException) this interval is empty or if the resulting
interval would be invalid.
Examples:
--------------------
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.expand(2);
assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1)));
interval2.expand(-2);
assert(interval2 == Interval!Date(Date(1998, 1, 2), Date(2010, 3, 1)));
--------------------
+/
void expand(D)(D duration, Direction dir = Direction.both) pure
if(__traits(compiles, begin + duration))
{
_enforceNotEmpty();
switch(dir)
{
case Direction.both:
{
auto begin = _begin - duration;
auto end = _end + duration;
if(!_valid(begin, end))
throw new DateTimeException("Argument would result in an invalid Interval.");
_begin = begin;
_end = end;
return;
}
case Direction.fwd:
{
auto end = _end + duration;
if(!_valid(_begin, end))
throw new DateTimeException("Argument would result in an invalid Interval.");
_end = end;
return;
}
case Direction.bwd:
{
auto begin = _begin - duration;
if(!_valid(begin, _end))
throw new DateTimeException("Argument would result in an invalid Interval.");
_begin = begin;
return;
}
default:
assert(0, "Invalid Direction.");
}
}
static if(__traits(compiles, begin.add!"months"(1)) &&
__traits(compiles, begin.add!"years"(1)))
{
/++
Expands the interval forwards and/or backwards in time. Effectively,
it subtracts the given number of months/years from $(D begin) and
adds them to $(D end). Whether it expands forwards and/or backwards
in time is determined by $(D_PARAM dir).
Params:
years = The number of years to expand the interval by.
months = The number of months to expand the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D begin) and $(D end), causing their month
to increment.
Throws:
$(D DateTimeException) if this interval is empty or if the
resulting interval would be invalid.
Examples:
--------------------
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.expand(2);
assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1)));
interval2.expand(-2);
assert(interval2 == Interval!Date(Date(1998, 1, 2), Date(2010, 3, 1)));
--------------------
+/
void expand(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes, Direction dir = Direction.both)
if(isIntegral!T)
{
_enforceNotEmpty();
switch(dir)
{
case Direction.both:
{
auto begin = _begin;
auto end = _end;
begin.add!"years"(-years, allowOverflow);
begin.add!"months"(-months, allowOverflow);
end.add!"years"(years, allowOverflow);
end.add!"months"(months, allowOverflow);
enforce(_valid(begin, end), new DateTimeException("Argument would result in an invalid Interval."));
_begin = begin;
_end = end;
return;
}
case Direction.fwd:
{
auto end = _end;
end.add!"years"(years, allowOverflow);
end.add!"months"(months, allowOverflow);
enforce(_valid(_begin, end), new DateTimeException("Argument would result in an invalid Interval."));
_end = end;
return;
}
case Direction.bwd:
{
auto begin = _begin;
begin.add!"years"(-years, allowOverflow);
begin.add!"months"(-months, allowOverflow);
enforce(_valid(begin, _end), new DateTimeException("Argument would result in an invalid Interval."));
_begin = begin;
return;
}
default:
assert(0, "Invalid Direction.");
}
}
}
/++
Returns a range which iterates forward over the interval, starting
at $(D begin), using $(D_PARAM func) to generate each successive time
point.
The range's $(D front) is the interval's $(D begin). $(D_PARAM func) is
used to generate the next $(D front) when $(D popFront) is called. If
$(D_PARAM popFirst) is $(D PopFirst.yes), then $(D popFront) is called
before the range is returned (so that $(D front) is a time point which
$(D_PARAM func) would generate).
If $(D_PARAM func) ever generates a time point less than or equal to the
current $(D front) of the range, then a $(D DateTimeException) will be
thrown. The range will be empty and iteration complete when
$(D_PARAM func) generates a time point equal to or beyond the $(D end)
of the interval.
There are helper functions in this module which generate common
delegates to pass to $(D fwdRange). Their documentation starts with
"Range-generating function," making them easily searchable.
Params:
func = The function used to generate the time points of the
range over the interval.
popFirst = Whether $(D popFront) should be called on the range
before returning it.
Throws:
$(D DateTimeException) if this interval is empty.
Warning:
$(D_PARAM func) must be logically pure. Ideally, $(D_PARAM func)
would be a function pointer to a pure function, but forcing
$(D_PARAM func) to be pure is far too restrictive to be useful, and
in order to have the ease of use of having functions which generate
functions to pass to $(D fwdRange), $(D_PARAM func) must be a
delegate.
If $(D_PARAM func) retains state which changes as it is called, then
some algorithms will not work correctly, because the range's
$(D save) will have failed to have really saved the range's state.
To avoid such bugs, don't pass a delegate which is
not logically pure to $(D fwdRange). If $(D_PARAM func) is given the
same time point with two different calls, it must return the same
result both times.
Of course, none of the functions in this module have this problem,
so it's only relevant if when creating a custom delegate.
Examples:
--------------------
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9));
auto func = (in Date date) //For iterating over even-numbered days.
{
if((date.day & 1) == 0)
return date + dur!"days"(2);
return date + dur!"days"(1);
};
auto range = interval.fwdRange(func);
//An odd day. Using PopFirst.yes would have made this Date(2010, 9, 2).
assert(range.front == Date(2010, 9, 1));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.empty);
--------------------
+/
IntervalRange!(TP, Direction.fwd) fwdRange(TP delegate(in TP) func, PopFirst popFirst = PopFirst.no) const
{
_enforceNotEmpty();
auto range = IntervalRange!(TP, Direction.fwd)(this, func);
if(popFirst == PopFirst.yes)
range.popFront();
return range;
}
/++
Returns a range which iterates backwards over the interval, starting
at $(D end), using $(D_PARAM func) to generate each successive time
point.
The range's $(D front) is the interval's $(D end). $(D_PARAM func) is
used to generate the next $(D front) when $(D popFront) is called. If
$(D_PARAM popFirst) is $(D PopFirst.yes), then $(D popFront) is called
before the range is returned (so that $(D front) is a time point which
$(D_PARAM func) would generate).
If $(D_PARAM func) ever generates a time point greater than or equal to
the current $(D front) of the range, then a $(D DateTimeException) will
be thrown. The range will be empty and iteration complete when
$(D_PARAM func) generates a time point equal to or less than the
$(D begin) of the interval.
There are helper functions in this module which generate common
delegates to pass to $(D bwdRange). Their documentation starts with
"Range-generating function," making them easily searchable.
Params:
func = The function used to generate the time points of the
range over the interval.
popFirst = Whether $(D popFront) should be called on the range
before returning it.
Throws:
$(D DateTimeException) if this interval is empty.
Warning:
$(D_PARAM func) must be logically pure. Ideally, $(D_PARAM func)
would be a function pointer to a pure function, but forcing
$(D_PARAM func) to be pure is far too restrictive to be useful, and
in order to have the ease of use of having functions which generate
functions to pass to $(D fwdRange), $(D_PARAM func) must be a
delegate.
If $(D_PARAM func) retains state which changes as it is called, then
some algorithms will not work correctly, because the range's
$(D save) will have failed to have really saved the range's state.
To avoid such bugs, don't pass a delegate which is
not logically pure to $(D fwdRange). If $(D_PARAM func) is given the
same time point with two different calls, it must return the same
result both times.
Of course, none of the functions in this module have this problem,
so it's only relevant for custom delegates.
Examples:
--------------------
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9));
auto func = (in Date date) //For iterating over even-numbered days.
{
if((date.day & 1) == 0)
return date - dur!"days"(2);
return date - dur!"days"(1);
};
auto range = interval.bwdRange(func);
//An odd day. Using PopFirst.yes would have made this Date(2010, 9, 8).
assert(range.front == Date(2010, 9, 9));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.empty);
--------------------
+/
IntervalRange!(TP, Direction.bwd) bwdRange(TP delegate(in TP) func, PopFirst popFirst = PopFirst.no) const
{
_enforceNotEmpty();
auto range = IntervalRange!(TP, Direction.bwd)(this, func);
if(popFirst == PopFirst.yes)
range.popFront();
return range;
}
/+
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return _toStringImpl();
}
/++
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return _toStringImpl();
}
private:
/+
Since we have two versions of toString, we have _toStringImpl
so that they can share implementations.
+/
string _toStringImpl() const nothrow
{
try
return format("[%s - %s)", _begin, _end);
catch(Exception e)
assert(0, "format() threw.");
}
/+
Throws:
$(D DateTimeException) if this interval is empty.
+/
void _enforceNotEmpty(size_t line = __LINE__) const pure
{
if(empty)
throw new DateTimeException("Invalid operation for an empty Interval.", __FILE__, line);
}
/+
Whether the given values form a valid time interval.
Params:
begin = The starting point of the interval.
end = The end point of the interval.
+/
static bool _valid(in TP begin, in TP end) pure nothrow
{
return begin <= end;
}
pure invariant()
{
assert(_valid(_begin, _end), "Invariant Failure: begin is not before or equal to end.");
}
TP _begin;
TP _end;
}
//Test Interval's constructors.
unittest
{
version(testStdDateTime)
{
assertThrown!DateTimeException(Interval!Date(Date(2010, 1, 1), Date(1, 1, 1)));
Interval!Date(Date.init, Date.init);
Interval!TimeOfDay(TimeOfDay.init, TimeOfDay.init);
Interval!DateTime(DateTime.init, DateTime.init);
Interval!SysTime(SysTime(0), SysTime(0));
Interval!DateTime(DateTime.init, dur!"days"(7));
//Verify Examples.
Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
assert(Interval!Date(Date(1996, 1, 2), dur!"weeks"(3)) == Interval!Date(Date(1996, 1, 2), Date(1996, 1, 23)));
assert(Interval!Date(Date(1996, 1, 2), dur!"days"(3)) == Interval!Date(Date(1996, 1, 2), Date(1996, 1, 5)));
assert(Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), dur!"hours"(3)) == Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), DateTime(1996, 1, 2, 15, 0, 0)));
assert(Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), dur!"minutes"(3)) == Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), DateTime(1996, 1, 2, 12, 3, 0)));
assert(Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), dur!"seconds"(3)) == Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), DateTime(1996, 1, 2, 12, 0, 3)));
assert(Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), dur!"msecs"(3000)) == Interval!DateTime(DateTime(1996, 1, 2, 12, 0, 0), DateTime(1996, 1, 2, 12, 0, 3)));
}
}
//Test Interval's begin.
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Interval!Date(Date(1, 1, 1), Date(2010, 1, 1)).begin, Date(1, 1, 1));
_assertPred!"=="(Interval!Date(Date(2010, 1, 1), Date(2010, 1, 1)).begin, Date(2010, 1, 1));
_assertPred!"=="(Interval!Date(Date(1997, 12, 31), Date(1998, 1, 1)).begin, Date(1997, 12, 31));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.begin));
static assert(__traits(compiles, iInterval.begin));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).begin == Date(1996, 1, 2));
}
}
//Test Interval's end.
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Interval!Date(Date(1, 1, 1), Date(2010, 1, 1)).end, Date(2010, 1, 1));
_assertPred!"=="(Interval!Date(Date(2010, 1, 1), Date(2010, 1, 1)).end, Date(2010, 1, 1));
_assertPred!"=="(Interval!Date(Date(1997, 12, 31), Date(1998, 1, 1)).end, Date(1998, 1, 1));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.end));
static assert(__traits(compiles, iInterval.end));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).end == Date(2012, 3, 1));
}
}
//Test Interval's length.
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Interval!Date(Date(2010, 1, 1), Date(2010, 1, 1)).length, dur!"days"(0));
_assertPred!"=="(Interval!Date(Date(2010, 1, 1), Date(2010, 4, 1)).length, dur!"days"(90));
_assertPred!"=="(Interval!TimeOfDay(TimeOfDay(0, 30, 0), TimeOfDay(12, 22, 7)).length, dur!"seconds"(42_727));
_assertPred!"=="(Interval!DateTime(DateTime(2010, 1, 1, 0, 30, 0), DateTime(2010, 1, 2, 12, 22, 7)).length, dur!"seconds"(129_127));
_assertPred!"=="(Interval!SysTime(SysTime(DateTime(2010, 1, 1, 0, 30, 0)), SysTime(DateTime(2010, 1, 2, 12, 22, 7))).length, dur!"seconds"(129_127));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.length));
static assert(__traits(compiles, iInterval.length));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).length == dur!"days"(5903));
}
}
//Test Interval's empty.
unittest
{
version(testStdDateTime)
{
assert(Interval!Date(Date(2010, 1, 1), Date(2010, 1, 1)).empty);
assert(!Interval!Date(Date(2010, 1, 1), Date(2010, 4, 1)).empty);
assert(!Interval!TimeOfDay(TimeOfDay(0, 30, 0), TimeOfDay(12, 22, 7)).empty);
assert(!Interval!DateTime(DateTime(2010, 1, 1, 0, 30, 0), DateTime(2010, 1, 2, 12, 22, 7)).empty);
assert(!Interval!SysTime(SysTime(DateTime(2010, 1, 1, 0, 30, 0)), SysTime(DateTime(2010, 1, 2, 12, 22, 7))).empty);
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.empty));
static assert(__traits(compiles, iInterval.empty));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(1996, 1, 2)).empty);
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).empty);
}
}
//Test Interval's contains(time point).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).contains(Date(2010, 7, 4)));
assert(!interval.contains(Date(2009, 7, 4)));
assert(!interval.contains(Date(2010, 7, 3)));
assert(interval.contains(Date(2010, 7, 4)));
assert(interval.contains(Date(2010, 7, 5)));
assert(interval.contains(Date(2011, 7, 1)));
assert(interval.contains(Date(2012, 1, 6)));
assert(!interval.contains(Date(2012, 1, 7)));
assert(!interval.contains(Date(2012, 1, 8)));
assert(!interval.contains(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, interval.contains(cdate)));
static assert(__traits(compiles, cInterval.contains(cdate)));
static assert(__traits(compiles, iInterval.contains(cdate)));
//Verify Examples.
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Date(1994, 12, 24)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Date(2000, 1, 5)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Date(2012, 3, 1)));
}
}
//Test Interval's contains(Interval).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(interval.contains(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).contains(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).contains(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(interval.contains(interval));
assert(!interval.contains(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!interval.contains(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!interval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!interval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!interval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!interval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(interval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(interval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(interval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!interval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!interval.contains(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!interval.contains(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).contains(interval));
assert(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).contains(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).contains(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).contains(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).contains(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).contains(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).contains(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).contains(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).contains(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).contains(interval));
assert(!Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).contains(interval));
assert(!Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).contains(interval));
assert(!interval.contains(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.contains(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.contains(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.contains(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.contains(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.contains(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!interval.contains(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.contains(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.contains(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.contains(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.contains(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.contains(NegInfInterval!Date(Date(2012, 1, 8))));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.contains(interval)));
static assert(__traits(compiles, interval.contains(cInterval)));
static assert(__traits(compiles, interval.contains(iInterval)));
static assert(__traits(compiles, interval.contains(posInfInterval)));
static assert(__traits(compiles, interval.contains(cPosInfInterval)));
static assert(__traits(compiles, interval.contains(iPosInfInterval)));
static assert(__traits(compiles, interval.contains(negInfInterval)));
static assert(__traits(compiles, interval.contains(cNegInfInterval)));
static assert(__traits(compiles, interval.contains(iNegInfInterval)));
static assert(__traits(compiles, cInterval.contains(interval)));
static assert(__traits(compiles, cInterval.contains(cInterval)));
static assert(__traits(compiles, cInterval.contains(iInterval)));
static assert(__traits(compiles, cInterval.contains(posInfInterval)));
static assert(__traits(compiles, cInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, cInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, cInterval.contains(negInfInterval)));
static assert(__traits(compiles, cInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, cInterval.contains(iNegInfInterval)));
static assert(__traits(compiles, iInterval.contains(interval)));
static assert(__traits(compiles, iInterval.contains(cInterval)));
static assert(__traits(compiles, iInterval.contains(iInterval)));
static assert(__traits(compiles, iInterval.contains(posInfInterval)));
static assert(__traits(compiles, iInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, iInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, iInterval.contains(negInfInterval)));
static assert(__traits(compiles, iInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, iInterval.contains(iNegInfInterval)));
//Verify Examples.
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(NegInfInterval!Date(Date(1996, 5, 4))));
}
}
//Test Interval's isBefore(time point).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isBefore(Date(2010, 7, 4)));
assert(!interval.isBefore(Date(2009, 7, 3)));
assert(!interval.isBefore(Date(2010, 7, 3)));
assert(!interval.isBefore(Date(2010, 7, 4)));
assert(!interval.isBefore(Date(2010, 7, 5)));
assert(!interval.isBefore(Date(2011, 7, 1)));
assert(!interval.isBefore(Date(2012, 1, 6)));
assert(interval.isBefore(Date(2012, 1, 7)));
assert(interval.isBefore(Date(2012, 1, 8)));
assert(interval.isBefore(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, interval.isBefore(cdate)));
static assert(__traits(compiles, cInterval.isBefore(cdate)));
static assert(__traits(compiles, iInterval.isBefore(cdate)));
//Verify Examples.
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Date(1994, 12, 24)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Date(2000, 1, 5)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Date(2012, 3, 1)));
}
}
//Test Interval's isBefore(Interval).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(interval.isBefore(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isBefore(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isBefore(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!interval.isBefore(interval));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!interval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!interval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!interval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(interval.isBefore(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(interval.isBefore(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).isBefore(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).isBefore(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).isBefore(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).isBefore(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).isBefore(interval));
assert(!Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).isBefore(interval));
assert(!Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).isBefore(interval));
assert(!interval.isBefore(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.isBefore(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isBefore(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isBefore(PosInfInterval!Date(Date(2012, 1, 6))));
assert(interval.isBefore(PosInfInterval!Date(Date(2012, 1, 7))));
assert(interval.isBefore(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.isBefore(NegInfInterval!Date(Date(2012, 1, 8))));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.isBefore(interval)));
static assert(__traits(compiles, interval.isBefore(cInterval)));
static assert(__traits(compiles, interval.isBefore(iInterval)));
static assert(__traits(compiles, interval.isBefore(posInfInterval)));
static assert(__traits(compiles, interval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, interval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, interval.isBefore(negInfInterval)));
static assert(__traits(compiles, interval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, interval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(interval)));
static assert(__traits(compiles, cInterval.isBefore(cInterval)));
static assert(__traits(compiles, cInterval.isBefore(iInterval)));
static assert(__traits(compiles, cInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, cInterval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(interval)));
static assert(__traits(compiles, iInterval.isBefore(cInterval)));
static assert(__traits(compiles, iInterval.isBefore(iInterval)));
static assert(__traits(compiles, iInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, iInterval.isBefore(iNegInfInterval)));
//Verify Examples.
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(Interval!Date(Date(2012, 3, 1), Date(2013, 5, 1))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(PosInfInterval!Date(Date(1999, 5, 4))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(PosInfInterval!Date(Date(2013, 3, 7))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(NegInfInterval!Date(Date(1996, 5, 4))));
}
}
//Test Interval's isAfter(time point).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isAfter(Date(2010, 7, 4)));
assert(interval.isAfter(Date(2009, 7, 4)));
assert(interval.isAfter(Date(2010, 7, 3)));
assert(!interval.isAfter(Date(2010, 7, 4)));
assert(!interval.isAfter(Date(2010, 7, 5)));
assert(!interval.isAfter(Date(2011, 7, 1)));
assert(!interval.isAfter(Date(2012, 1, 6)));
assert(!interval.isAfter(Date(2012, 1, 7)));
assert(!interval.isAfter(Date(2012, 1, 8)));
assert(!interval.isAfter(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, interval.isAfter(cdate)));
static assert(__traits(compiles, cInterval.isAfter(cdate)));
static assert(__traits(compiles, iInterval.isAfter(cdate)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Date(1994, 12, 24)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Date(2000, 1, 5)));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Date(2012, 3, 1)));
}
}
//Test Interval's isAfter(Interval).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(interval.isAfter(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isAfter(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).isAfter(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!interval.isAfter(interval));
assert(interval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(interval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!interval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!interval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!interval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!interval.isAfter(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!interval.isAfter(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).isAfter(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).isAfter(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).isAfter(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).isAfter(interval));
assert(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).isAfter(interval));
assert(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).isAfter(interval));
assert(!interval.isAfter(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.isAfter(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isAfter(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isAfter(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.isAfter(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.isAfter(PosInfInterval!Date(Date(2012, 1, 8))));
assert(interval.isAfter(NegInfInterval!Date(Date(2010, 7, 3))));
assert(interval.isAfter(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isAfter(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isAfter(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.isAfter(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.isAfter(NegInfInterval!Date(Date(2012, 1, 8))));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.isAfter(interval)));
static assert(__traits(compiles, interval.isAfter(cInterval)));
static assert(__traits(compiles, interval.isAfter(iInterval)));
static assert(__traits(compiles, interval.isAfter(posInfInterval)));
static assert(__traits(compiles, interval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, interval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, interval.isAfter(negInfInterval)));
static assert(__traits(compiles, interval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, interval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(interval)));
static assert(__traits(compiles, cInterval.isAfter(cInterval)));
static assert(__traits(compiles, cInterval.isAfter(iInterval)));
static assert(__traits(compiles, cInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, cInterval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(interval)));
static assert(__traits(compiles, iInterval.isAfter(cInterval)));
static assert(__traits(compiles, iInterval.isAfter(iInterval)));
static assert(__traits(compiles, iInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, iInterval.isAfter(iNegInfInterval)));
//Verify Examples.
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(PosInfInterval!Date(Date(1999, 5, 4))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(NegInfInterval!Date(Date(1996, 1, 2))));
}
}
//Test Interval's intersects().
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(interval.intersects(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).intersects(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).intersects(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(interval.intersects(interval));
assert(!interval.intersects(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!interval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(interval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(interval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(interval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!interval.intersects(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!interval.intersects(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).intersects(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).intersects(interval));
assert(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).intersects(interval));
assert(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).intersects(interval));
assert(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).intersects(interval));
assert(!Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).intersects(interval));
assert(!Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).intersects(interval));
assert(interval.intersects(PosInfInterval!Date(Date(2010, 7, 3))));
assert(interval.intersects(PosInfInterval!Date(Date(2010, 7, 4))));
assert(interval.intersects(PosInfInterval!Date(Date(2010, 7, 5))));
assert(interval.intersects(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.intersects(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.intersects(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!interval.intersects(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.intersects(NegInfInterval!Date(Date(2010, 7, 4))));
assert(interval.intersects(NegInfInterval!Date(Date(2010, 7, 5))));
assert(interval.intersects(NegInfInterval!Date(Date(2012, 1, 6))));
assert(interval.intersects(NegInfInterval!Date(Date(2012, 1, 7))));
assert(interval.intersects(NegInfInterval!Date(Date(2012, 1, 8))));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.intersects(interval)));
static assert(__traits(compiles, interval.intersects(cInterval)));
static assert(__traits(compiles, interval.intersects(iInterval)));
static assert(__traits(compiles, interval.intersects(posInfInterval)));
static assert(__traits(compiles, interval.intersects(cPosInfInterval)));
static assert(__traits(compiles, interval.intersects(iPosInfInterval)));
static assert(__traits(compiles, interval.intersects(negInfInterval)));
static assert(__traits(compiles, interval.intersects(cNegInfInterval)));
static assert(__traits(compiles, interval.intersects(iNegInfInterval)));
static assert(__traits(compiles, cInterval.intersects(interval)));
static assert(__traits(compiles, cInterval.intersects(cInterval)));
static assert(__traits(compiles, cInterval.intersects(iInterval)));
static assert(__traits(compiles, cInterval.intersects(posInfInterval)));
static assert(__traits(compiles, cInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, cInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, cInterval.intersects(negInfInterval)));
static assert(__traits(compiles, cInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, cInterval.intersects(iNegInfInterval)));
static assert(__traits(compiles, iInterval.intersects(interval)));
static assert(__traits(compiles, iInterval.intersects(cInterval)));
static assert(__traits(compiles, iInterval.intersects(iInterval)));
static assert(__traits(compiles, iInterval.intersects(posInfInterval)));
static assert(__traits(compiles, iInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, iInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, iInterval.intersects(negInfInterval)));
static assert(__traits(compiles, iInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, iInterval.intersects(iNegInfInterval)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(PosInfInterval!Date(Date(2012, 3, 1))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(NegInfInterval!Date(Date(1996, 1, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects(NegInfInterval!Date(Date(2000, 1, 2))));
}
}
//Test Interval's intersection().
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
assertThrown!DateTimeException(interval.intersection(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).intersection(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 4), dur!"days"(0)).intersection(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(interval.intersection(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assertThrown!DateTimeException(interval.intersection(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assertThrown!DateTimeException(interval.intersection(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assertThrown!DateTimeException(interval.intersection(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).intersection(interval));
assertThrown!DateTimeException(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).intersection(interval));
assertThrown!DateTimeException(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).intersection(interval));
assertThrown!DateTimeException(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).intersection(interval));
assertThrown!DateTimeException(interval.intersection(PosInfInterval!Date(Date(2012, 1, 7))));
assertThrown!DateTimeException(interval.intersection(PosInfInterval!Date(Date(2012, 1, 8))));
assertThrown!DateTimeException(interval.intersection(NegInfInterval!Date(Date(2010, 7, 3))));
assertThrown!DateTimeException(interval.intersection(NegInfInterval!Date(Date(2010, 7, 4))));
_assertPred!"=="(interval.intersection(interval), interval);
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).intersection(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).intersection(interval),
Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).intersection(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).intersection(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).intersection(interval),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).intersection(interval),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).intersection(interval),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).intersection(interval),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(PosInfInterval!Date(Date(2010, 7, 3))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(PosInfInterval!Date(Date(2010, 7, 4))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(PosInfInterval!Date(Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(PosInfInterval!Date(Date(2012, 1, 6))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(NegInfInterval!Date(Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)));
_assertPred!"=="(interval.intersection(NegInfInterval!Date(Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 6)));
_assertPred!"=="(interval.intersection(NegInfInterval!Date(Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.intersection(NegInfInterval!Date(Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.intersection(interval)));
static assert(__traits(compiles, interval.intersection(cInterval)));
static assert(__traits(compiles, interval.intersection(iInterval)));
static assert(__traits(compiles, interval.intersection(posInfInterval)));
static assert(__traits(compiles, interval.intersection(cPosInfInterval)));
static assert(__traits(compiles, interval.intersection(iPosInfInterval)));
static assert(__traits(compiles, interval.intersection(negInfInterval)));
static assert(__traits(compiles, interval.intersection(cNegInfInterval)));
static assert(__traits(compiles, interval.intersection(iNegInfInterval)));
static assert(__traits(compiles, cInterval.intersection(interval)));
static assert(__traits(compiles, cInterval.intersection(cInterval)));
static assert(__traits(compiles, cInterval.intersection(iInterval)));
static assert(__traits(compiles, cInterval.intersection(posInfInterval)));
static assert(__traits(compiles, cInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, cInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, cInterval.intersection(negInfInterval)));
static assert(__traits(compiles, cInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, cInterval.intersection(iNegInfInterval)));
static assert(__traits(compiles, iInterval.intersection(interval)));
static assert(__traits(compiles, iInterval.intersection(cInterval)));
static assert(__traits(compiles, iInterval.intersection(iInterval)));
static assert(__traits(compiles, iInterval.intersection(posInfInterval)));
static assert(__traits(compiles, iInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, iInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, iInterval.intersection(negInfInterval)));
static assert(__traits(compiles, iInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, iInterval.intersection(iNegInfInterval)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(PosInfInterval!Date(Date(1990, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(PosInfInterval!Date(Date(1999, 1, 12))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(NegInfInterval!Date(Date(1999, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection(NegInfInterval!Date(Date(2013, 1, 12))) == Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1)));
}
}
//Test Interval's isAdjacent().
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static void testInterval(in Interval!Date interval1, in Interval!Date interval2)
{
interval1.isAdjacent(interval2);
}
assertThrown!DateTimeException(testInterval(interval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), interval));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!interval.isAdjacent(interval));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(interval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!interval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!interval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!interval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(interval.isAdjacent(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!interval.isAdjacent(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).isAdjacent(interval));
assert(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).isAdjacent(interval));
assert(!Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).isAdjacent(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).isAdjacent(interval));
assert(!Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).isAdjacent(interval));
assert(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).isAdjacent(interval));
assert(!Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).isAdjacent(interval));
assert(!interval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!interval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 6))));
assert(interval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!interval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 3))));
assert(interval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!interval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!interval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!interval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!interval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 8))));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.isAdjacent(interval)));
static assert(__traits(compiles, interval.isAdjacent(cInterval)));
static assert(__traits(compiles, interval.isAdjacent(iInterval)));
static assert(__traits(compiles, interval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, interval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, interval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, interval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, interval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, interval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(interval)));
static assert(__traits(compiles, cInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, cInterval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(interval)));
static assert(__traits(compiles, iInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, iInterval.isAdjacent(iNegInfInterval)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(1990, 7, 6), Date(1996, 1, 2))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(2012, 3, 1), Date(2013, 9, 17))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(1989, 3, 1), Date(2012, 3, 1))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(PosInfInterval!Date(Date(1999, 5, 4))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(PosInfInterval!Date(Date(2012, 3, 1))));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(NegInfInterval!Date(Date(1996, 1, 2))));
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent(NegInfInterval!Date(Date(2000, 1, 2))));
}
}
//Test Interval's merge().
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static void testInterval(I)(in Interval!Date interval1, in I interval2)
{
interval1.merge(interval2);
}
assertThrown!DateTimeException(testInterval(interval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), interval));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(interval, Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assertThrown!DateTimeException(testInterval(interval, Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)), interval));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)), interval));
assertThrown!DateTimeException(testInterval(interval, PosInfInterval!Date(Date(2012, 1, 8))));
assertThrown!DateTimeException(testInterval(interval, NegInfInterval!Date(Date(2010, 7, 3))));
_assertPred!"=="(interval.merge(interval), interval);
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(interval.merge(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).merge(interval),
Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).merge(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).merge(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).merge(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).merge(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).merge(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).merge(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).merge(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).merge(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).merge(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(interval.merge(PosInfInterval!Date(Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(interval.merge(PosInfInterval!Date(Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.merge(PosInfInterval!Date(Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.merge(PosInfInterval!Date(Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.merge(PosInfInterval!Date(Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.merge(NegInfInterval!Date(Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(NegInfInterval!Date(Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(NegInfInterval!Date(Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(NegInfInterval!Date(Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.merge(NegInfInterval!Date(Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.merge(interval)));
static assert(__traits(compiles, interval.merge(cInterval)));
static assert(__traits(compiles, interval.merge(iInterval)));
static assert(__traits(compiles, interval.merge(posInfInterval)));
static assert(__traits(compiles, interval.merge(cPosInfInterval)));
static assert(__traits(compiles, interval.merge(iPosInfInterval)));
static assert(__traits(compiles, interval.merge(negInfInterval)));
static assert(__traits(compiles, interval.merge(cNegInfInterval)));
static assert(__traits(compiles, interval.merge(iNegInfInterval)));
static assert(__traits(compiles, cInterval.merge(interval)));
static assert(__traits(compiles, cInterval.merge(cInterval)));
static assert(__traits(compiles, cInterval.merge(iInterval)));
static assert(__traits(compiles, cInterval.merge(posInfInterval)));
static assert(__traits(compiles, cInterval.merge(cPosInfInterval)));
static assert(__traits(compiles, cInterval.merge(iPosInfInterval)));
static assert(__traits(compiles, cInterval.merge(negInfInterval)));
static assert(__traits(compiles, cInterval.merge(cNegInfInterval)));
static assert(__traits(compiles, cInterval.merge(iNegInfInterval)));
static assert(__traits(compiles, iInterval.merge(interval)));
static assert(__traits(compiles, iInterval.merge(cInterval)));
static assert(__traits(compiles, iInterval.merge(iInterval)));
static assert(__traits(compiles, iInterval.merge(posInfInterval)));
static assert(__traits(compiles, iInterval.merge(cPosInfInterval)));
static assert(__traits(compiles, iInterval.merge(iPosInfInterval)));
static assert(__traits(compiles, iInterval.merge(negInfInterval)));
static assert(__traits(compiles, iInterval.merge(cNegInfInterval)));
static assert(__traits(compiles, iInterval.merge(iNegInfInterval)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(PosInfInterval!Date(Date(2012, 3, 1))) == PosInfInterval!Date(Date(1996, 1 , 2)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(NegInfInterval!Date(Date(1996, 1, 2))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge(NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
}
}
//Test Interval's span().
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static void testInterval(in Interval!Date interval1, in Interval!Date interval2)
{
interval1.span(interval2);
}
assertThrown!DateTimeException(testInterval(interval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), interval));
assertThrown!DateTimeException(testInterval(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
_assertPred!"=="(interval.span(interval), interval);
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))),
Interval!Date(Date(2010, 7, 1), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(interval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(interval.span(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(interval.span(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 9)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)).span(interval),
Interval!Date(Date(2010, 7, 1), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)).span(interval),
Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)).span(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)).span(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)).span(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)).span(interval),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)).span(interval),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 9)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.span(PosInfInterval!Date(Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2010, 7, 3))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(interval.span(NegInfInterval!Date(Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, interval.span(interval)));
static assert(__traits(compiles, interval.span(cInterval)));
static assert(__traits(compiles, interval.span(iInterval)));
static assert(__traits(compiles, interval.span(posInfInterval)));
static assert(__traits(compiles, interval.span(cPosInfInterval)));
static assert(__traits(compiles, interval.span(iPosInfInterval)));
static assert(__traits(compiles, interval.span(negInfInterval)));
static assert(__traits(compiles, interval.span(cNegInfInterval)));
static assert(__traits(compiles, interval.span(iNegInfInterval)));
static assert(__traits(compiles, cInterval.span(interval)));
static assert(__traits(compiles, cInterval.span(cInterval)));
static assert(__traits(compiles, cInterval.span(iInterval)));
static assert(__traits(compiles, cInterval.span(posInfInterval)));
static assert(__traits(compiles, cInterval.span(cPosInfInterval)));
static assert(__traits(compiles, cInterval.span(iPosInfInterval)));
static assert(__traits(compiles, cInterval.span(negInfInterval)));
static assert(__traits(compiles, cInterval.span(cNegInfInterval)));
static assert(__traits(compiles, cInterval.span(iNegInfInterval)));
static assert(__traits(compiles, iInterval.span(interval)));
static assert(__traits(compiles, iInterval.span(cInterval)));
static assert(__traits(compiles, iInterval.span(iInterval)));
static assert(__traits(compiles, iInterval.span(posInfInterval)));
static assert(__traits(compiles, iInterval.span(cPosInfInterval)));
static assert(__traits(compiles, iInterval.span(iPosInfInterval)));
static assert(__traits(compiles, iInterval.span(negInfInterval)));
static assert(__traits(compiles, iInterval.span(cNegInfInterval)));
static assert(__traits(compiles, iInterval.span(iNegInfInterval)));
//Verify Examples.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(Interval!Date(Date(1990, 7, 6), Date(1991, 1, 8))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(PosInfInterval!Date(Date(2050, 1, 1))) == PosInfInterval!Date(Date(1996, 1 , 2)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(NegInfInterval!Date(Date(1602, 5, 21))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span(NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
}
}
//Test Interval's shift(duration).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static void testIntervalFail(Interval!Date interval, in Duration duration)
{
interval.shift(duration);
}
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), dur!"days"(1)));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.shift(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), Interval!Date(Date(2010, 7, 26), Date(2012, 1, 29)));
testInterval(interval, dur!"days"(-22), Interval!Date(Date(2010, 6, 12), Date(2011, 12, 16)));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.shift(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.shift(dur!"days"(5))));
//Verify Examples.
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5));
interval1.shift(dur!"days"(50));
assert(interval1 == Interval!Date(Date(1996, 2, 21), Date(2012, 5, 25)));
interval2.shift(dur!"days"(-50));
assert(interval2 == Interval!Date(Date(1995, 11, 13), Date(2012, 2, 15)));
}
}
//Test Interval's shift(int, int, AllowDayOverflow).
unittest
{
version(testStdDateTime)
{
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static void testIntervalFail(Interval!Date interval, int years, int months)
{
interval.shift(years, months);
}
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), 1, 0));
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, in I expected, size_t line = __LINE__)
{
interval.shift(years, months, allow);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, Interval!Date(Date(2015, 7, 4), Date(2017, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, Interval!Date(Date(2005, 7, 4), Date(2007, 1, 7)));
auto interval2 = Interval!Date(Date(2000, 1, 29), Date(2010, 5, 31));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, Interval!Date(Date(2001, 3, 1), Date(2011, 7, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, Interval!Date(Date(2000, 12, 29), Date(2011, 5, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, Interval!Date(Date(1998, 12, 29), Date(2009, 5, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, Interval!Date(Date(1999, 3, 1), Date(2009, 7, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, Interval!Date(Date(2001, 2, 28), Date(2011, 6, 30)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, Interval!Date(Date(2000, 12, 29), Date(2011, 4, 30)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, Interval!Date(Date(1998, 12, 29), Date(2009, 4, 30)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, Interval!Date(Date(1999, 2, 28), Date(2009, 6, 30)));
}
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.shift(5)));
static assert(!__traits(compiles, iInterval.shift(5)));
//Verify Examples.
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.shift(2);
assert(interval1 == Interval!Date(Date(1998, 1, 2), Date(2014, 3, 1)));
interval2.shift(-2);
assert(interval2 == Interval!Date(Date(1994, 1, 2), Date(2010, 3, 1)));
}
}
//Test Interval's expand(Duration).
unittest
{
version(testStdDateTime)
{
auto interval = Interval!Date(Date(2000, 7, 4), Date(2012, 1, 7));
static void testIntervalFail(I)(I interval, in Duration duration)
{
interval.expand(duration);
}
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), dur!"days"(1)));
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)), dur!"days"(-5)));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.expand(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), Interval!Date(Date(2000, 6, 12), Date(2012, 1, 29)));
testInterval(interval, dur!"days"(-22), Interval!Date(Date(2000, 7, 26), Date(2011, 12, 16)));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.expand(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.expand(dur!"days"(5))));
//Verify Examples.
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.expand(dur!"days"(2));
assert(interval1 == Interval!Date(Date(1995, 12, 31), Date(2012, 3, 3)));
interval2.expand(dur!"days"(-2));
assert(interval2 == Interval!Date(Date(1996, 1, 4), Date(2012, 2, 28)));
}
}
//Test Interval's expand(int, int, AllowDayOverflow, Direction)
unittest
{
version(testStdDateTime)
{
{
auto interval = Interval!Date(Date(2000, 7, 4), Date(2012, 1, 7));
static void testIntervalFail(Interval!Date interval, int years, int months)
{
interval.expand(years, months);
}
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), dur!"days"(0)), 1, 0));
assertThrown!DateTimeException(testIntervalFail(Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)), -5, 0));
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, Direction dir, in I expected, size_t line = __LINE__)
{
interval.expand(years, months, allow, dir);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(1995, 7, 4), Date(2017, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(2005, 7, 4), Date(2007, 1, 7)));
testInterval(interval, 5, 0, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 7, 4), Date(2017, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 7, 4), Date(2007, 1, 7)));
testInterval(interval, 5, 0, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(1995, 7, 4), Date(2012, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(2005, 7, 4), Date(2012, 1, 7)));
auto interval2 = Interval!Date(Date(2000, 1, 29), Date(2010, 5, 31));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(1998, 12, 29), Date(2011, 7, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(1999, 3, 1), Date(2011, 5, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(2001, 3, 1), Date(2009, 5, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, Direction.both, Interval!Date(Date(2000, 12, 29), Date(2009, 7, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, Direction.both, Interval!Date(Date(1998, 12, 29), Date(2011, 6, 30)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, Direction.both, Interval!Date(Date(1999, 2, 28), Date(2011, 4, 30)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, Direction.both, Interval!Date(Date(2001, 2, 28), Date(2009, 4, 30)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, Direction.both, Interval!Date(Date(2000, 12, 29), Date(2009, 6, 30)));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2011, 7, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2011, 5, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2009, 5, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2009, 7, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2011, 6, 30)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2011, 4, 30)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2009, 4, 30)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, Direction.fwd, Interval!Date(Date(2000, 1, 29), Date(2009, 6, 30)));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(1998, 12, 29), Date(2010, 5, 31)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(1999, 3, 1), Date(2010, 5, 31)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(2001, 3, 1), Date(2010, 5, 31)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, Direction.bwd, Interval!Date(Date(2000, 12, 29), Date(2010, 5, 31)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, Direction.bwd, Interval!Date(Date(1998, 12, 29), Date(2010, 5, 31)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, Direction.bwd, Interval!Date(Date(1999, 2, 28), Date(2010, 5, 31)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, Direction.bwd, Interval!Date(Date(2001, 2, 28), Date(2010, 5, 31)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, Direction.bwd, Interval!Date(Date(2000, 12, 29), Date(2010, 5, 31)));
}
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.expand(5)));
static assert(!__traits(compiles, iInterval.expand(5)));
//Verify Examples.
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
interval1.expand(2);
assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1)));
interval2.expand(-2);
assert(interval2 == Interval!Date(Date(1998, 1, 2), Date(2010, 3, 1)));
}
}
//Test Interval's fwdRange.
unittest
{
version(testStdDateTime)
{
{
auto interval = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 21));
static void testInterval1(Interval!Date interval)
{
interval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
}
assertThrown!DateTimeException(testInterval1(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
static void testInterval2(Interval!Date interval)
{
interval.fwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri)).popFront();
}
assertThrown!DateTimeException(testInterval2(interval));
assert(!interval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri)).empty);
assert(interval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri), PopFirst.yes).empty);
_assertPred!"=="(Interval!Date(Date(2010, 9, 12), Date(2010, 10, 1)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri)).front,
Date(2010, 9, 12));
_assertPred!"=="(Interval!Date(Date(2010, 9, 12), Date(2010, 10, 1)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri), PopFirst.yes).front,
Date(2010, 9, 17));
}
//Verify Examples.
{
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9));
auto func = delegate (in Date date)
{
if((date.day & 1) == 0)
return date + dur!"days"(2);
return date + dur!"days"(1);
};
auto range = interval.fwdRange(func);
assert(range.front == Date(2010, 9, 1)); //An odd day. Using PopFirst.yes would have made this Date(2010, 9, 2).
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.empty);
}
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
static assert(__traits(compiles, iInterval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
}
}
//Test Interval's bwdRange.
unittest
{
version(testStdDateTime)
{
{
auto interval = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 21));
static void testInterval1(Interval!Date interval)
{
interval.bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
}
assertThrown!DateTimeException(testInterval1(Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
static void testInterval2(Interval!Date interval)
{
interval.bwdRange(everyDayOfWeek!(Date, Direction.fwd)(DayOfWeek.fri)).popFront();
}
assertThrown!DateTimeException(testInterval2(interval));
assert(!interval.bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri)).empty);
assert(interval.bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri), PopFirst.yes).empty);
_assertPred!"=="(Interval!Date(Date(2010, 9, 19), Date(2010, 10, 1)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri)).front,
Date(2010, 10, 1));
_assertPred!"=="(Interval!Date(Date(2010, 9, 19), Date(2010, 10, 1)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri), PopFirst.yes).front,
Date(2010, 9, 24));
}
//Verify Examples.
{
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9));
auto func = delegate (in Date date)
{
if((date.day & 1) == 0)
return date - dur!"days"(2);
return date - dur!"days"(1);
};
auto range = interval.bwdRange(func);
assert(range.front == Date(2010, 9, 9)); //An odd day. Using PopFirst.yes would have made this Date(2010, 9, 8).
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.empty);
}
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.bwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
static assert(__traits(compiles, iInterval.bwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
}
}
//Test Interval's toString().
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).toString(), "[2010-Jul-04 - 2012-Jan-07)");
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cInterval.toString()));
static assert(__traits(compiles, iInterval.toString()));
}
}
/++
Represents an interval of time which has positive infinity as its end point.
Any ranges which iterate over a $(D PosInfInterval) are infinite. So, the
main purpose of using $(D PosInfInterval) is to create an infinite range
which starts at a fixed point in time and goes to positive infinity.
+/
struct PosInfInterval(TP)
{
public:
/++
Params:
begin = The time point which begins the interval.
Examples:
--------------------
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
--------------------
+/
this(in TP begin) pure nothrow
{
_begin = cast(TP)begin;
}
/++
Params:
rhs = The $(D PosInfInterval) to assign to this one.
+/
/+ref+/ PosInfInterval opAssign(const ref PosInfInterval rhs) pure nothrow
{
_begin = cast(TP)rhs._begin;
return this;
}
/++
Params:
rhs = The $(D PosInfInterval) to assign to this one.
+/
/+ref+/ PosInfInterval opAssign(PosInfInterval rhs) pure nothrow
{
_begin = cast(TP)rhs._begin;
return this;
}
/++
The starting point of the interval. It is included in the interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).begin == Date(1996, 1, 2));
--------------------
+/
@property TP begin() const pure nothrow
{
return cast(TP)_begin;
}
/++
The starting point of the interval. It is included in the interval.
Params:
timePoint = The time point to set $(D begin) to.
+/
@property void begin(TP timePoint) pure nothrow
{
_begin = timePoint;
}
/++
Whether the interval's length is 0. Always returns false.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).empty);
--------------------
+/
@property bool empty() const pure nothrow
{
return false;
}
/++
Whether the given time point is within this interval.
Params:
timePoint = The time point to check for inclusion in this interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(1994, 12, 24)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(2000, 1, 5)));
--------------------
+/
bool contains(TP timePoint) const pure nothrow
{
return timePoint >= _begin;
}
/++
Whether the given interval is completely within this interval.
Params:
interval = The interval to check for inclusion in this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(
Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
--------------------
+/
bool contains(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return interval._begin >= _begin;
}
/++
Whether the given interval is completely within this interval.
Params:
interval = The interval to check for inclusion in this interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(
PosInfInterval!Date(Date(1995, 7, 2))));
--------------------
+/
bool contains(in PosInfInterval interval) const pure nothrow
{
return interval._begin >= _begin;
}
/++
Whether the given interval is completely within this interval.
Always returns false because an interval going to positive infinity
can never contain an interval beginning at negative infinity.
Params:
interval = The interval to check for inclusion in this interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(
NegInfInterval!Date(Date(1996, 5, 4))));
--------------------
+/
bool contains(in NegInfInterval!TP interval) const pure nothrow
{
return false;
}
/++
Whether this interval is before the given time point.
Always returns false because an interval going to positive infinity
can never be before any time point.
Params:
timePoint = The time point to check whether this interval is before
it.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(1994, 12, 24)));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(2000, 1, 5)));
--------------------
+/
bool isBefore(in TP timePoint) const pure nothrow
{
return false;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Always returns false (unless the given interval is empty) because an
interval going to positive infinity can never be before any other
interval.
Params:
interval = The interval to check for against this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
--------------------
+/
bool isBefore(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return false;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Always returns false because an interval going to positive infinity can
never be before any other interval.
Params:
interval = The interval to check for against this interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
PosInfInterval!Date(Date(1992, 5, 4))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
PosInfInterval!Date(Date(2013, 3, 7))));
--------------------
+/
bool isBefore(in PosInfInterval interval) const pure nothrow
{
return false;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Always returns false because an interval going to positive infinity can
never be before any other interval.
Params:
interval = The interval to check for against this interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
NegInfInterval!Date(Date(1996, 5, 4))));
--------------------
+/
bool isBefore(in NegInfInterval!TP interval) const pure nothrow
{
return false;
}
/++
Whether this interval is after the given time point.
Params:
timePoint = The time point to check whether this interval is after
it.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(1994, 12, 24)));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(2000, 1, 5)));
--------------------
+/
bool isAfter(in TP timePoint) const pure nothrow
{
return timePoint < _begin;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Params:
interval = The interval to check against this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
--------------------
+/
bool isAfter(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return _begin >= interval._end;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Always returns false because an interval going to positive infinity can
never be after another interval going to positive infinity.
Params:
interval = The interval to check against this interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
PosInfInterval!Date(Date(1990, 1, 7))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
PosInfInterval!Date(Date(1999, 5, 4))));
--------------------
+/
bool isAfter(in PosInfInterval interval) const pure nothrow
{
return false;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Params:
interval = The interval to check against this interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
NegInfInterval!Date(Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(
NegInfInterval!Date(Date(2000, 7, 1))));
--------------------
+/
bool isAfter(in NegInfInterval!TP interval) const pure nothrow
{
return _begin >= interval._end;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects(
Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
--------------------
+/
bool intersects(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return interval._end > _begin;
}
/++
Whether the given interval overlaps this interval.
Always returns true because two intervals going to positive infinity
always overlap.
Params:
interval = The interval to check for intersection with this
interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(
PosInfInterval!Date(Date(1990, 1, 7))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(
PosInfInterval!Date(Date(1999, 5, 4))));
--------------------
+/
bool intersects(in PosInfInterval interval) const pure nothrow
{
return true;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this
interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects(
NegInfInterval!Date(Date(1996, 1, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(
NegInfInterval!Date(Date(2000, 7, 1))));
--------------------
+/
bool intersects(in NegInfInterval!TP interval) const pure nothrow
{
return _begin < interval._end;
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect or if
the given interval is empty.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) ==
Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
--------------------
+/
Interval!TP intersection(in Interval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
auto begin = _begin > interval._begin ? _begin : interval._begin;
return Interval!TP(begin, interval._end);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
PosInfInterval!Date(Date(1990, 7, 6))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
PosInfInterval!Date(Date(1999, 1, 12))) ==
PosInfInterval!Date(Date(1999, 1 , 12)));
--------------------
+/
PosInfInterval intersection(in PosInfInterval interval) const pure nothrow
{
return PosInfInterval(_begin < interval._begin ? interval._begin : _begin);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
NegInfInterval!Date(Date(1999, 7, 6))) ==
Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(
NegInfInterval!Date(Date(2013, 1, 12))) ==
Interval!Date(Date(1996, 1 , 2), Date(2013, 1, 12)));
--------------------
+/
Interval!TP intersection(in NegInfInterval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
return Interval!TP(_begin, interval._end);
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(
Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1999, 1, 12)).isAdjacent(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
--------------------
+/
bool isAdjacent(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return _begin == interval._end;
}
/++
Whether the given interval is adjacent to this interval.
Always returns false because two intervals going to positive infinity
can never be adjacent to one another.
Params:
interval = The interval to check whether its adjecent to this
interval.
Examples:
--------------------
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(
PosInfInterval!Date(Date(1990, 1, 7))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(
PosInfInterval!Date(Date(1996, 1, 2))));
--------------------
+/
bool isAdjacent(in PosInfInterval interval) const pure nothrow
{
return false;
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(
NegInfInterval!Date(Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(
NegInfInterval!Date(Date(2000, 7, 1))));
--------------------
+/
bool isAdjacent(in NegInfInterval!TP interval) const pure nothrow
{
return _begin == interval._end;
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect and are
not adjacent or if the given interval is empty.
Note:
There is no overload for $(D merge) which takes a
$(D NegInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval merge(in Interval!TP interval) const
{
enforce(this.isAdjacent(interval) || this.intersects(interval),
new DateTimeException(format("%s and %s are not adjacent and do not intersect.", this, interval)));
return PosInfInterval(_begin < interval._begin ? _begin : interval._begin);
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Note:
There is no overload for $(D merge) which takes a
$(D NegInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(
PosInfInterval!Date(Date(1990, 7, 6))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(
PosInfInterval!Date(Date(1999, 1, 12))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval merge(in PosInfInterval interval) const pure nothrow
{
return PosInfInterval(_begin < interval._begin ? _begin : interval._begin);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this
interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Note:
There is no overload for $(D span) which takes a
$(D NegInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(
Interval!Date(Date(500, 8, 9), Date(1602, 1, 31))) ==
PosInfInterval!Date(Date(500, 8, 9)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval span(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return PosInfInterval(_begin < interval._begin ? _begin : interval._begin);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this
interval.
Note:
There is no overload for $(D span) which takes a
$(D NegInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(
PosInfInterval!Date(Date(1990, 7, 6))) ==
PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(
PosInfInterval!Date(Date(1999, 1, 12))) ==
PosInfInterval!Date(Date(1996, 1 , 2)));
--------------------
+/
PosInfInterval span(in PosInfInterval interval) const pure nothrow
{
return PosInfInterval(_begin < interval._begin ? _begin : interval._begin);
}
/++
Shifts the $(D begin) of this interval forward or backwards in time by
the given duration (a positive duration shifts the interval forward; a
negative duration shifts it backward). Effectively, it does
$(D begin += duration).
Params:
duration = The duration to shift the interval by.
Examples:
--------------------
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.shift(dur!"days"(50));
assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21)));
interval2.shift(dur!"days"(-50));
assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
--------------------
+/
void shift(D)(D duration) pure nothrow
if(__traits(compiles, begin + duration))
{
_begin += duration;
}
static if(__traits(compiles, begin.add!"months"(1)) &&
__traits(compiles, begin.add!"years"(1)))
{
/++
Shifts the $(D begin) of this interval forward or backwards in time
by the given number of years and/or months (a positive number of years
and months shifts the interval forward; a negative number shifts it
backward). It adds the years the given years and months to
$(D begin). It effectively calls $(D add!"years"()) and then
$(D add!"months"()) on $(D begin) with the given number of years and
months.
Params:
years = The number of years to shift the interval by.
months = The number of months to shift the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D begin), causing its month to increment.
Throws:
$(D DateTimeException) if this interval is empty or if the
resulting interval would be invalid.
Examples:
--------------------
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.shift(dur!"days"(50));
assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21)));
interval2.shift(dur!"days"(-50));
assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
--------------------
+/
void shift(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
if(isIntegral!T)
{
auto begin = _begin;
begin.add!"years"(years, allowOverflow);
begin.add!"months"(months, allowOverflow);
_begin = begin;
}
}
/++
Expands the interval backwards in time. Effectively, it does
$(D begin -= duration).
Params:
duration = The duration to expand the interval by.
dir = The direction in time to expand the interval.
Examples:
--------------------
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.expand(dur!"days"(2));
assert(interval1 == PosInfInterval!Date(Date(1995, 12, 31)));
interval2.expand(dur!"days"(-2));
assert(interval2 == PosInfInterval!Date(Date(1996, 1, 4)));
--------------------
+/
void expand(D)(D duration) pure nothrow
if(__traits(compiles, begin + duration))
{
_begin -= duration;
}
static if(__traits(compiles, begin.add!"months"(1)) &&
__traits(compiles, begin.add!"years"(1)))
{
/++
Expands the interval forwards and/or backwards in time. Effectively,
it subtracts the given number of months/years from $(D begin).
Params:
years = The number of years to expand the interval by.
months = The number of months to expand the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D begin), causing its month to increment.
Throws:
$(D DateTimeException) if this interval is empty or if the
resulting interval would be invalid.
Examples:
--------------------
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.expand(2);
assert(interval1 == PosInfInterval!Date(Date(1994, 1, 2)));
interval2.expand(-2);
assert(interval2 == PosInfInterval!Date(Date(1998, 1, 2)));
--------------------
+/
void expand(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
if(isIntegral!T)
{
auto begin = _begin;
begin.add!"years"(-years, allowOverflow);
begin.add!"months"(-months, allowOverflow);
_begin = begin;
return;
}
}
/++
Returns a range which iterates forward over the interval, starting
at $(D begin), using $(D_PARAM func) to generate each successive time
point.
The range's $(D front) is the interval's $(D begin). $(D_PARAM func) is
used to generate the next $(D front) when $(D popFront) is called. If
$(D_PARAM popFirst) is $(D PopFirst.yes), then $(D popFront) is called
before the range is returned (so that $(D front) is a time point which
$(D_PARAM func) would generate).
If $(D_PARAM func) ever generates a time point less than or equal to the
current $(D front) of the range, then a $(D DateTimeException) will be
thrown.
There are helper functions in this module which generate common
delegates to pass to $(D fwdRange). Their documentation starts with
"Range-generating function," to make them easily searchable.
Params:
func = The function used to generate the time points of the
range over the interval.
popFirst = Whether $(D popFront) should be called on the range
before returning it.
Throws:
$(D DateTimeException) if this interval is empty.
Warning:
$(D_PARAM func) must be logically pure. Ideally, $(D_PARAM func)
would be a function pointer to a pure function, but forcing
$(D_PARAM func) to be pure is far too restrictive to be useful, and
in order to have the ease of use of having functions which generate
functions to pass to $(D fwdRange), $(D_PARAM func) must be a
delegate.
If $(D_PARAM func) retains state which changes as it is called, then
some algorithms will not work correctly, because the range's
$(D save) will have failed to have really saved the range's state.
To avoid such bugs, don't pass a delegate which is
not logically pure to $(D fwdRange). If $(D_PARAM func) is given the
same time point with two different calls, it must return the same
result both times.
Of course, none of the functions in this module have this problem,
so it's only relevant for custom delegates.
Examples:
--------------------
auto interval = PosInfInterval!Date(Date(2010, 9, 1));
auto func = (in Date date) //For iterating over even-numbered days.
{
if((date.day & 1) == 0)
return date + dur!"days"(2);
return date + dur!"days"(1);
};
auto range = interval.fwdRange(func);
//An odd day. Using PopFirst.yes would have made this Date(2010, 9, 2).
assert(range.front == Date(2010, 9, 1));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(!range.empty);
--------------------
+/
PosInfIntervalRange!(TP) fwdRange(TP delegate(in TP) func, PopFirst popFirst = PopFirst.no) const
{
auto range = PosInfIntervalRange!(TP)(this, func);
if(popFirst == PopFirst.yes)
range.popFront();
return range;
}
/+
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return _toStringImpl();
}
/++
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return _toStringImpl();
}
private:
/+
Since we have two versions of toString(), we have _toStringImpl()
so that they can share implementations.
+/
string _toStringImpl() const nothrow
{
try
return format("[%s - ∞)", _begin);
catch(Exception e)
assert(0, "format() threw.");
}
TP _begin;
}
//Test PosInfInterval's constructor.
unittest
{
version(testStdDateTime)
{
PosInfInterval!Date(Date.init);
PosInfInterval!TimeOfDay(TimeOfDay.init);
PosInfInterval!DateTime(DateTime.init);
PosInfInterval!SysTime(SysTime(0));
//Verify Examples.
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
}
}
//Test PosInfInterval's begin.
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(PosInfInterval!Date(Date(1, 1, 1)).begin, Date(1, 1, 1));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 1, 1)).begin, Date(2010, 1, 1));
_assertPred!"=="(PosInfInterval!Date(Date(1997, 12, 31)).begin, Date(1997, 12, 31));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, cPosInfInterval.begin));
static assert(__traits(compiles, iPosInfInterval.begin));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).begin == Date(1996, 1, 2));
}
}
//Test PosInfInterval's empty.
unittest
{
version(testStdDateTime)
{
assert(!PosInfInterval!Date(Date(2010, 1, 1)).empty);
assert(!PosInfInterval!TimeOfDay(TimeOfDay(0, 30, 0)).empty);
assert(!PosInfInterval!DateTime(DateTime(2010, 1, 1, 0, 30, 0)).empty);
assert(!PosInfInterval!SysTime(SysTime(DateTime(2010, 1, 1, 0, 30, 0))).empty);
const cPosInfInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iPosInfInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
static assert(__traits(compiles, cPosInfInterval.empty));
static assert(__traits(compiles, iPosInfInterval.empty));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).empty);
}
}
//Test PosInfInterval's contains(time point).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
assert(!posInfInterval.contains(Date(2009, 7, 4)));
assert(!posInfInterval.contains(Date(2010, 7, 3)));
assert(posInfInterval.contains(Date(2010, 7, 4)));
assert(posInfInterval.contains(Date(2010, 7, 5)));
assert(posInfInterval.contains(Date(2011, 7, 1)));
assert(posInfInterval.contains(Date(2012, 1, 6)));
assert(posInfInterval.contains(Date(2012, 1, 7)));
assert(posInfInterval.contains(Date(2012, 1, 8)));
assert(posInfInterval.contains(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, posInfInterval.contains(cdate)));
static assert(__traits(compiles, cPosInfInterval.contains(cdate)));
static assert(__traits(compiles, iPosInfInterval.contains(cdate)));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(1994, 12, 24)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(2000, 1, 5)));
}
}
//Test PosInfInterval's contains(Interval).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.contains(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(posInfInterval.contains(posInfInterval));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!posInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(posInfInterval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(posInfInterval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(posInfInterval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(posInfInterval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(posInfInterval.contains(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(posInfInterval.contains(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!posInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 3))));
assert(posInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 4))));
assert(posInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 5))));
assert(posInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 6))));
assert(posInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 7))));
assert(posInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 8))));
assert(PosInfInterval!Date(Date(2010, 7, 3)).contains(posInfInterval));
assert(PosInfInterval!Date(Date(2010, 7, 4)).contains(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 5)).contains(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 6)).contains(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 7)).contains(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 8)).contains(posInfInterval));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.contains(interval)));
static assert(__traits(compiles, posInfInterval.contains(cInterval)));
static assert(__traits(compiles, posInfInterval.contains(iInterval)));
static assert(__traits(compiles, posInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, posInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, posInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.contains(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(interval)));
static assert(__traits(compiles, cPosInfInterval.contains(cInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(iInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.contains(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(interval)));
static assert(__traits(compiles, iPosInfInterval.contains(cInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(iInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.contains(iNegInfInterval)));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(PosInfInterval!Date(Date(1995, 7, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(NegInfInterval!Date(Date(1996, 5, 4))));
}
}
//Test PosInfInterval's isBefore(time point).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
assert(!posInfInterval.isBefore(Date(2009, 7, 3)));
assert(!posInfInterval.isBefore(Date(2010, 7, 3)));
assert(!posInfInterval.isBefore(Date(2010, 7, 4)));
assert(!posInfInterval.isBefore(Date(2010, 7, 5)));
assert(!posInfInterval.isBefore(Date(2011, 7, 1)));
assert(!posInfInterval.isBefore(Date(2012, 1, 6)));
assert(!posInfInterval.isBefore(Date(2012, 1, 7)));
assert(!posInfInterval.isBefore(Date(2012, 1, 8)));
assert(!posInfInterval.isBefore(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, posInfInterval.isBefore(cdate)));
static assert(__traits(compiles, cPosInfInterval.isBefore(cdate)));
static assert(__traits(compiles, iPosInfInterval.isBefore(cdate)));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(1994, 12, 24)));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(2000, 1, 5)));
}
}
//Test PosInfInterval's isBefore(Interval).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.isBefore(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!posInfInterval.isBefore(posInfInterval));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!posInfInterval.isBefore(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!PosInfInterval!Date(Date(2010, 7, 3)).isBefore(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 4)).isBefore(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 5)).isBefore(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 6)).isBefore(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 7)).isBefore(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 8)).isBefore(posInfInterval));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.isBefore(interval)));
static assert(__traits(compiles, posInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(interval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(interval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isBefore(iNegInfInterval)));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(PosInfInterval!Date(Date(1992, 5, 4))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(PosInfInterval!Date(Date(2013, 3, 7))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(NegInfInterval!Date(Date(1996, 5, 4))));
}
}
//Test PosInfInterval's isAfter(time point).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
assert(posInfInterval.isAfter(Date(2009, 7, 3)));
assert(posInfInterval.isAfter(Date(2010, 7, 3)));
assert(!posInfInterval.isAfter(Date(2010, 7, 4)));
assert(!posInfInterval.isAfter(Date(2010, 7, 5)));
assert(!posInfInterval.isAfter(Date(2011, 7, 1)));
assert(!posInfInterval.isAfter(Date(2012, 1, 6)));
assert(!posInfInterval.isAfter(Date(2012, 1, 7)));
assert(!posInfInterval.isAfter(Date(2012, 1, 8)));
assert(!posInfInterval.isAfter(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, posInfInterval.isAfter(cdate)));
static assert(__traits(compiles, cPosInfInterval.isAfter(cdate)));
static assert(__traits(compiles, iPosInfInterval.isAfter(cdate)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(1994, 12, 24)));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(2000, 1, 5)));
}
}
//Test PosInfInterval's isAfter(Interval).
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.isAfter(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!posInfInterval.isAfter(posInfInterval));
assert(posInfInterval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(posInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!posInfInterval.isAfter(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!PosInfInterval!Date(Date(2010, 7, 3)).isAfter(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 4)).isAfter(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 5)).isAfter(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 6)).isAfter(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 7)).isAfter(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 8)).isAfter(posInfInterval));
assert(posInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 3))));
assert(posInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.isAfter(interval)));
static assert(__traits(compiles, posInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(interval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(interval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAfter(iNegInfInterval)));
//Verify Examples.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(PosInfInterval!Date(Date(1990, 1, 7))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(PosInfInterval!Date(Date(1999, 5, 4))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(NegInfInterval!Date(Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(NegInfInterval!Date(Date(2000, 7, 1))));
}
}
//Test PosInfInterval's intersects().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.intersects(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(posInfInterval.intersects(posInfInterval));
assert(!posInfInterval.intersects(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!posInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(posInfInterval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(posInfInterval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(posInfInterval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(posInfInterval.intersects(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(posInfInterval.intersects(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 3))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 4))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 5))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 6))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 7))));
assert(posInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 8))));
assert(PosInfInterval!Date(Date(2010, 7, 3)).intersects(posInfInterval));
assert(PosInfInterval!Date(Date(2010, 7, 4)).intersects(posInfInterval));
assert(PosInfInterval!Date(Date(2010, 7, 5)).intersects(posInfInterval));
assert(PosInfInterval!Date(Date(2012, 1, 6)).intersects(posInfInterval));
assert(PosInfInterval!Date(Date(2012, 1, 7)).intersects(posInfInterval));
assert(PosInfInterval!Date(Date(2012, 1, 8)).intersects(posInfInterval));
assert(!posInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 4))));
assert(posInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 5))));
assert(posInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 6))));
assert(posInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 7))));
assert(posInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.intersects(interval)));
static assert(__traits(compiles, posInfInterval.intersects(cInterval)));
static assert(__traits(compiles, posInfInterval.intersects(iInterval)));
static assert(__traits(compiles, posInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, posInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, posInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.intersects(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(interval)));
static assert(__traits(compiles, cPosInfInterval.intersects(cInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(iInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersects(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(interval)));
static assert(__traits(compiles, iPosInfInterval.intersects(cInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(iInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersects(iNegInfInterval)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects(Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(PosInfInterval!Date(Date(1990, 1, 7))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects(NegInfInterval!Date(Date(1996, 1, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects(NegInfInterval!Date(Date(2000, 7, 1))));
}
}
//Test PosInfInterval's intersection().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(I, J)(in I interval1, in J interval2)
{
interval1.intersection(interval2);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assertThrown!DateTimeException(testInterval(posInfInterval, NegInfInterval!Date(Date(2010, 7, 3))));
assertThrown!DateTimeException(testInterval(posInfInterval, NegInfInterval!Date(Date(2010, 7, 4))));
_assertPred!"=="(posInfInterval.intersection(posInfInterval),
posInfInterval);
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
Interval!Date(Date(2010, 7, 4), Date(2013, 7, 3)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8)));
_assertPred!"=="(posInfInterval.intersection(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))),
Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 5)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2012, 1, 6))),
PosInfInterval!Date(Date(2012, 1, 6)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2012, 1, 7))),
PosInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(posInfInterval.intersection(PosInfInterval!Date(Date(2012, 1, 8))),
PosInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 3)).intersection(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 4)).intersection(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 5)).intersection(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 5)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 6)).intersection(posInfInterval),
PosInfInterval!Date(Date(2012, 1, 6)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 7)).intersection(posInfInterval),
PosInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 8)).intersection(posInfInterval),
PosInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(posInfInterval.intersection(NegInfInterval!Date(Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 4), Date(2010, 7, 5)));
_assertPred!"=="(posInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 6)));
_assertPred!"=="(posInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)));
_assertPred!"=="(posInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1, 8)));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.intersection(interval)));
static assert(__traits(compiles, posInfInterval.intersection(cInterval)));
static assert(__traits(compiles, posInfInterval.intersection(iInterval)));
static assert(__traits(compiles, posInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, posInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, posInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.intersection(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(interval)));
static assert(__traits(compiles, cPosInfInterval.intersection(cInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(iInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.intersection(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(interval)));
static assert(__traits(compiles, iPosInfInterval.intersection(cInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(iInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.intersection(iNegInfInterval)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1996, 1 , 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1999, 1 , 12)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(NegInfInterval!Date(Date(1999, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection(NegInfInterval!Date(Date(2013, 1, 12))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 1, 12)));
}
}
//Test PosInfInterval's isAdjacent().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.isAdjacent(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!posInfInterval.isAdjacent(posInfInterval));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!posInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 8))));
assert(!PosInfInterval!Date(Date(2010, 7, 3)).isAdjacent(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 4)).isAdjacent(posInfInterval));
assert(!PosInfInterval!Date(Date(2010, 7, 5)).isAdjacent(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 6)).isAdjacent(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 7)).isAdjacent(posInfInterval));
assert(!PosInfInterval!Date(Date(2012, 1, 8)).isAdjacent(posInfInterval));
assert(!posInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 3))));
assert(posInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!posInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!posInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!posInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!posInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, posInfInterval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.isAdjacent(iNegInfInterval)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1999, 1, 12)).isAdjacent(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(PosInfInterval!Date(Date(1990, 1, 7))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(PosInfInterval!Date(Date(1996, 1, 2))));
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(NegInfInterval!Date(Date(1996, 1, 2))));
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent(NegInfInterval!Date(Date(2000, 7, 1))));
}
}
//Test PosInfInterval's merge().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.merge(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
_assertPred!"=="(posInfInterval.merge(posInfInterval),
posInfInterval);
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 1)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 3)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 4)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 5)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 6)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 7)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 8)).merge(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 3)))));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 4)))));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 5)))));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 6)))));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 7)))));
static assert(!__traits(compiles, posInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 8)))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.merge(interval)));
static assert(__traits(compiles, posInfInterval.merge(cInterval)));
static assert(__traits(compiles, posInfInterval.merge(iInterval)));
static assert(__traits(compiles, posInfInterval.merge(posInfInterval)));
static assert(__traits(compiles, posInfInterval.merge(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.merge(iPosInfInterval)));
static assert(!__traits(compiles, posInfInterval.merge(negInfInterval)));
static assert(!__traits(compiles, posInfInterval.merge(cNegInfInterval)));
static assert(!__traits(compiles, posInfInterval.merge(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.merge(interval)));
static assert(__traits(compiles, cPosInfInterval.merge(cInterval)));
static assert(__traits(compiles, cPosInfInterval.merge(iInterval)));
static assert(__traits(compiles, cPosInfInterval.merge(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.merge(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.merge(iPosInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.merge(negInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.merge(cNegInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.merge(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.merge(interval)));
static assert(__traits(compiles, iPosInfInterval.merge(cInterval)));
static assert(__traits(compiles, iPosInfInterval.merge(iInterval)));
static assert(__traits(compiles, iPosInfInterval.merge(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.merge(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.merge(iPosInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.merge(negInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.merge(cNegInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.merge(iNegInfInterval)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == PosInfInterval!Date(Date(1996, 1 , 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge(PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1996, 1 , 2)));
}
}
//Test PosInfInterval's span().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(in PosInfInterval!Date posInfInterval, in Interval!Date interval)
{
posInfInterval.span(interval);
}
assertThrown!DateTimeException(testInterval(posInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
_assertPred!"=="(posInfInterval.span(posInfInterval),
posInfInterval);
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 1)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 1)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2010, 7, 3))),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2010, 7, 4))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2010, 7, 5))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2012, 1, 6))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2012, 1, 7))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(posInfInterval.span(PosInfInterval!Date(Date(2012, 1, 8))),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 3)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 4)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 5)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 6)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 7)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(PosInfInterval!Date(Date(2012, 1, 8)).span(posInfInterval),
PosInfInterval!Date(Date(2010, 7, 4)));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2010, 7, 3)))));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2010, 7, 4)))));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2010, 7, 5)))));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2012, 1, 6)))));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2012, 1, 7)))));
static assert(!__traits(compiles, posInfInterval.span(NegInfInterval!Date(Date(2012, 1, 8)))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, posInfInterval.span(interval)));
static assert(__traits(compiles, posInfInterval.span(cInterval)));
static assert(__traits(compiles, posInfInterval.span(iInterval)));
static assert(__traits(compiles, posInfInterval.span(posInfInterval)));
static assert(__traits(compiles, posInfInterval.span(cPosInfInterval)));
static assert(__traits(compiles, posInfInterval.span(iPosInfInterval)));
static assert(!__traits(compiles, posInfInterval.span(negInfInterval)));
static assert(!__traits(compiles, posInfInterval.span(cNegInfInterval)));
static assert(!__traits(compiles, posInfInterval.span(iNegInfInterval)));
static assert(__traits(compiles, cPosInfInterval.span(interval)));
static assert(__traits(compiles, cPosInfInterval.span(cInterval)));
static assert(__traits(compiles, cPosInfInterval.span(iInterval)));
static assert(__traits(compiles, cPosInfInterval.span(posInfInterval)));
static assert(__traits(compiles, cPosInfInterval.span(cPosInfInterval)));
static assert(__traits(compiles, cPosInfInterval.span(iPosInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.span(negInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.span(cNegInfInterval)));
static assert(!__traits(compiles, cPosInfInterval.span(iNegInfInterval)));
static assert(__traits(compiles, iPosInfInterval.span(interval)));
static assert(__traits(compiles, iPosInfInterval.span(cInterval)));
static assert(__traits(compiles, iPosInfInterval.span(iInterval)));
static assert(__traits(compiles, iPosInfInterval.span(posInfInterval)));
static assert(__traits(compiles, iPosInfInterval.span(cPosInfInterval)));
static assert(__traits(compiles, iPosInfInterval.span(iPosInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.span(negInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.span(cNegInfInterval)));
static assert(!__traits(compiles, iPosInfInterval.span(iNegInfInterval)));
//Verify Examples.
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(Interval!Date(Date(500, 8, 9), Date(1602, 1, 31))) == PosInfInterval!Date(Date(500, 8, 9)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == PosInfInterval!Date(Date(1996, 1 , 2)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6)));
assert(PosInfInterval!Date(Date(1996, 1, 2)).span(PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1996, 1 , 2)));
}
}
//Test PosInfInterval's shift().
unittest
{
version(testStdDateTime)
{
auto interval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.shift(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), PosInfInterval!Date(Date(2010, 7, 26)));
testInterval(interval, dur!"days"(-22), PosInfInterval!Date(Date(2010, 6, 12)));
const cInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(!__traits(compiles, cInterval.shift(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.shift(dur!"days"(5))));
//Verify Examples.
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.shift(dur!"days"(50));
assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21)));
interval2.shift(dur!"days"(-50));
assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
}
}
//Test PosInfInterval's shift(int, int, AllowDayOverflow).
unittest
{
version(testStdDateTime)
{
{
auto interval = PosInfInterval!Date(Date(2010, 7, 4));
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, in I expected, size_t line = __LINE__)
{
interval.shift(years, months, allow);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, PosInfInterval!Date(Date(2015, 7, 4)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, PosInfInterval!Date(Date(2005, 7, 4)));
auto interval2 = PosInfInterval!Date(Date(2000, 1, 29));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, PosInfInterval!Date(Date(2001, 3, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, PosInfInterval!Date(Date(2000, 12, 29)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, PosInfInterval!Date(Date(1998, 12, 29)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, PosInfInterval!Date(Date(1999, 3, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, PosInfInterval!Date(Date(2001, 2, 28)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, PosInfInterval!Date(Date(2000, 12, 29)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, PosInfInterval!Date(Date(1998, 12, 29)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, PosInfInterval!Date(Date(1999, 2, 28)));
}
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(!__traits(compiles, cPosInfInterval.shift(1)));
static assert(!__traits(compiles, iPosInfInterval.shift(1)));
//Verify Examples.
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.shift(2);
assert(interval1 == PosInfInterval!Date(Date(1998, 1, 2)));
interval2.shift(-2);
assert(interval2 == PosInfInterval!Date(Date(1994, 1, 2)));
}
}
//Test PosInfInterval's expand().
unittest
{
version(testStdDateTime)
{
auto interval = PosInfInterval!Date(Date(2000, 7, 4));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.expand(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), PosInfInterval!Date(Date(2000, 6, 12)));
testInterval(interval, dur!"days"(-22), PosInfInterval!Date(Date(2000, 7, 26)));
const cInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(!__traits(compiles, cInterval.expand(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.expand(dur!"days"(5))));
//Verify Examples.
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.expand(dur!"days"(2));
assert(interval1 == PosInfInterval!Date(Date(1995, 12, 31)));
interval2.expand(dur!"days"(-2));
assert(interval2 == PosInfInterval!Date(Date(1996, 1, 4)));
}
}
//Test PosInfInterval's expand(int, int, AllowDayOverflow).
unittest
{
version(testStdDateTime)
{
{
auto interval = PosInfInterval!Date(Date(2000, 7, 4));
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, in I expected, size_t line = __LINE__)
{
interval.expand(years, months, allow);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, PosInfInterval!Date(Date(1995, 7, 4)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, PosInfInterval!Date(Date(2005, 7, 4)));
auto interval2 = PosInfInterval!Date(Date(2000, 1, 29));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, PosInfInterval!Date(Date(1998, 12, 29)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, PosInfInterval!Date(Date(1999, 3, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, PosInfInterval!Date(Date(2001, 3, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, PosInfInterval!Date(Date(2000, 12, 29)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, PosInfInterval!Date(Date(1998, 12, 29)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, PosInfInterval!Date(Date(1999, 2, 28)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, PosInfInterval!Date(Date(2001, 2, 28)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, PosInfInterval!Date(Date(2000, 12, 29)));
}
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(!__traits(compiles, cPosInfInterval.expand(1)));
static assert(!__traits(compiles, iPosInfInterval.expand(1)));
//Verify Examples.
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1.expand(2);
assert(interval1 == PosInfInterval!Date(Date(1994, 1, 2)));
interval2.expand(-2);
assert(interval2 == PosInfInterval!Date(Date(1998, 1, 2)));
}
}
//Test PosInfInterval's fwdRange().
unittest
{
version(testStdDateTime)
{
auto posInfInterval = PosInfInterval!Date(Date(2010, 9, 19));
static void testInterval(PosInfInterval!Date posInfInterval)
{
posInfInterval.fwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri)).popFront();
}
assertThrown!DateTimeException(testInterval(posInfInterval));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 9, 12)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri)).front,
Date(2010, 9, 12));
_assertPred!"=="(PosInfInterval!Date(Date(2010, 9, 12)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri), PopFirst.yes).front,
Date(2010, 9, 17));
//Verify Examples.
auto interval = PosInfInterval!Date(Date(2010, 9, 1));
auto func = delegate (in Date date)
{
if((date.day & 1) == 0)
return date + dur!"days"(2);
return date + dur!"days"(1);
};
auto range = interval.fwdRange(func);
assert(range.front == Date(2010, 9, 1)); //An odd day. Using PopFirst.yes would have made this Date(2010, 9, 2).
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(!range.empty);
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, cPosInfInterval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
static assert(__traits(compiles, iPosInfInterval.fwdRange(everyDayOfWeek!Date(DayOfWeek.fri))));
}
}
//Test PosInfInterval's toString().
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(PosInfInterval!Date(Date(2010, 7, 4)).toString(), "[2010-Jul-04 - ∞)");
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
static assert(__traits(compiles, cPosInfInterval.toString()));
static assert(__traits(compiles, iPosInfInterval.toString()));
}
}
/++
Represents an interval of time which has negative infinity as its starting
point.
Any ranges which iterate over a $(D NegInfInterval) are infinite. So, the
main purpose of using $(D NegInfInterval) is to create an infinite range
which starts at negative infinity and goes to a fixed end point.
Iterate over it in reverse.
+/
struct NegInfInterval(TP)
{
public:
/++
Params:
begin = The time point which begins the interval.
Examples:
--------------------
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
--------------------
+/
this(in TP end) pure nothrow
{
_end = cast(TP)end;
}
/++
Params:
rhs = The $(D NegInfInterval) to assign to this one.
+/
/+ref+/ NegInfInterval opAssign(const ref NegInfInterval rhs) pure nothrow
{
_end = cast(TP)rhs._end;
return this;
}
/++
Params:
rhs = The $(D NegInfInterval) to assign to this one.
+/
/+ref+/ NegInfInterval opAssign(NegInfInterval rhs) pure nothrow
{
_end = cast(TP)rhs._end;
return this;
}
/++
The end point of the interval. It is excluded from the interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).end == Date(2012, 3, 1));
--------------------
+/
@property TP end() const pure nothrow
{
return cast(TP)_end;
}
/++
The end point of the interval. It is excluded from the interval.
Params:
timePoint = The time point to set end to.
+/
@property void end(TP timePoint) pure nothrow
{
_end = timePoint;
}
/++
Whether the interval's length is 0. Always returns false.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(1996, 1, 2)).empty);
--------------------
+/
@property bool empty() const pure nothrow
{
return false;
}
/++
Whether the given time point is within this interval.
Params:
timePoint = The time point to check for inclusion in this interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(1994, 12, 24)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2000, 1, 5)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2012, 3, 1)));
--------------------
+/
bool contains(TP timePoint) const pure nothrow
{
return timePoint < _end;
}
/++
Whether the given interval is completely within this interval.
Params:
interval = The interval to check for inclusion in this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(
Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
--------------------
+/
bool contains(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return interval._end <= _end;
}
/++
Whether the given interval is completely within this interval.
Always returns false because an interval beginning at negative
infinity can never contain an interval going to positive infinity.
Params:
interval = The interval to check for inclusion in this interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(
PosInfInterval!Date(Date(1999, 5, 4))));
--------------------
+/
bool contains(in PosInfInterval!TP interval) const pure nothrow
{
return false;
}
/++
Whether the given interval is completely within this interval.
Params:
interval = The interval to check for inclusion in this interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(
NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(
NegInfInterval!Date(Date(2013, 7, 9))));
--------------------
+/
bool contains(in NegInfInterval interval) const pure nothrow
{
return interval._end <= _end;
}
/++
Whether this interval is before the given time point.
Params:
timePoint = The time point to check whether this interval is
before it.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(1994, 12, 24)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2000, 1, 5)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2012, 3, 1)));
--------------------
+/
bool isBefore(in TP timePoint) const pure nothrow
{
return timePoint >= _end;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Params:
interval = The interval to check for against this interval.
Throws:
$(D DateTimeException) if the given interval is empty
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
--------------------
+/
bool isBefore(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return _end <= interval._begin;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Params:
interval = The interval to check for against this interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool isBefore(in PosInfInterval!TP interval) const pure nothrow
{
return _end <= interval._begin;
}
/++
Whether this interval is before the given interval and does not
intersect it.
Always returns false because an interval beginning at negative
infinity can never be before another interval beginning at negative
infinity.
Params:
interval = The interval to check for against this interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(
NegInfInterval!Date(Date(2013, 7, 9))));
--------------------
+/
bool isBefore(in NegInfInterval interval) const pure nothrow
{
return false;
}
/++
Whether this interval is after the given time point.
Always returns false because an interval beginning at negative infinity
can never be after any time point.
Params:
timePoint = The time point to check whether this interval is after
it.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(1994, 12, 24)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2000, 1, 5)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2012, 3, 1)));
--------------------
+/
bool isAfter(in TP timePoint) const pure nothrow
{
return false;
}
/++
Whether this interval is after the given interval and does not
intersect it.
Always returns false (unless the given interval is empty) because an
interval beginning at negative infinity can never be after any other
interval.
Params:
interval = The interval to check against this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
--------------------
+/
bool isAfter(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return false;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Always returns false because an interval beginning at negative infinity
can never be after any other interval.
Params:
interval = The interval to check against this interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool isAfter(in PosInfInterval!TP interval) const pure nothrow
{
return false;
}
/++
Whether this interval is after the given interval and does not intersect
it.
Always returns false because an interval beginning at negative infinity
can never be after any other interval.
Params:
interval = The interval to check against this interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(
NegInfInterval!Date(Date(2013, 7, 9))));
--------------------
+/
bool isAfter(in NegInfInterval interval) const pure nothrow
{
return false;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(
Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects(
Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
--------------------
+/
bool intersects(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return interval._begin < _end;
}
/++
Whether the given interval overlaps this interval.
Params:
interval = The interval to check for intersection with this
interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool intersects(in PosInfInterval!TP interval) const pure nothrow
{
return interval._begin < _end;
}
/++
Whether the given interval overlaps this interval.
Always returns true because two intervals beginning at negative infinity
always overlap.
Params:
interval = The interval to check for intersection with this interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(
NegInfInterval!Date(Date(1996, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(
NegInfInterval!Date(Date(2013, 7, 9))));
--------------------
+/
bool intersects(in NegInfInterval!TP interval) const pure nothrow
{
return true;
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect or if
the given interval is empty.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
Interval!Date(Date(1990, 7 , 6), Date(2000, 8, 2)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) ==
Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
--------------------
+/
Interval!TP intersection(in Interval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
auto end = _end < interval._end ? _end : interval._end;
return Interval!TP(interval._begin, end);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
PosInfInterval!Date(Date(1990, 7, 6))) ==
Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
PosInfInterval!Date(Date(1999, 1, 12))) ==
Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
--------------------
+/
Interval!TP intersection(in PosInfInterval!TP interval) const
{
enforce(this.intersects(interval), new DateTimeException(format("%s and %s do not intersect.", this, interval)));
return Interval!TP(interval._begin, _end);
}
/++
Returns the intersection of two intervals
Params:
interval = The interval to intersect with this interval.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
NegInfInterval!Date(Date(1999, 7, 6))) ==
NegInfInterval!Date(Date(1999, 7 , 6)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(
NegInfInterval!Date(Date(2013, 1, 12))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
--------------------
+/
NegInfInterval intersection(in NegInfInterval interval) const nothrow
{
return NegInfInterval(_end < interval._end ? _end : interval._end);
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(1999, 1, 12), Date(2012, 3, 1))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(2012, 3, 1), Date(2019, 2, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
--------------------
+/
bool isAdjacent(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return interval._begin == _end;
}
/++
Whether the given interval is adjacent to this interval.
Params:
interval = The interval to check whether its adjecent to this
interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
PosInfInterval!Date(Date(1999, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
PosInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool isAdjacent(in PosInfInterval!TP interval) const pure nothrow
{
return interval._begin == _end;
}
/++
Whether the given interval is adjacent to this interval.
Always returns false because two intervals beginning at negative
infinity can never be adjacent to one another.
Params:
interval = The interval to check whether its adjecent to this
interval.
Examples:
--------------------
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(
NegInfInterval!Date(Date(2012, 3, 1))));
--------------------
+/
bool isAdjacent(in NegInfInterval interval) const pure nothrow
{
return false;
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Throws:
$(D DateTimeException) if the two intervals do not intersect and are
not adjacent or if the given interval is empty.
Note:
There is no overload for $(D merge) which takes a
$(D PosInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(
Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) ==
NegInfInterval!Date(Date(2015, 9 , 2)));
--------------------
+/
NegInfInterval merge(in Interval!TP interval) const
{
enforce(this.isAdjacent(interval) || this.intersects(interval),
new DateTimeException(format("%s and %s are not adjacent and do not intersect.", this, interval)));
return NegInfInterval(_end > interval._end ? _end : interval._end);
}
/++
Returns the union of two intervals
Params:
interval = The interval to merge with this interval.
Note:
There is no overload for $(D merge) which takes a
$(D PosInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(
NegInfInterval!Date(Date(1999, 7, 6))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(
NegInfInterval!Date(Date(2013, 1, 12))) ==
NegInfInterval!Date(Date(2013, 1 , 12)));
--------------------
+/
NegInfInterval merge(in NegInfInterval interval) const pure nothrow
{
return NegInfInterval(_end > interval._end ? _end : interval._end);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this
interval.
Throws:
$(D DateTimeException) if the given interval is empty.
Note:
There is no overload for $(D span) which takes a
$(D PosInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(
Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(
Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) ==
NegInfInterval!Date(Date(2015, 9 , 2)));
assert(NegInfInterval!Date(Date(1600, 1, 7)).span(
Interval!Date(Date(2012, 3, 11), Date(2017, 7, 1))) ==
NegInfInterval!Date(Date(2017, 7 , 1)));
--------------------
+/
NegInfInterval span(in Interval!TP interval) const pure
{
interval._enforceNotEmpty();
return NegInfInterval(_end > interval._end ? _end : interval._end);
}
/++
Returns an interval that covers from the earliest time point of two
intervals up to (but not including) the latest time point of two
intervals.
Params:
interval = The interval to create a span together with this
interval.
Note:
There is no overload for $(D span) which takes a
$(D PosInfInterval), because an interval
going from negative infinity to positive infinity
is not possible.
Examples:
--------------------
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(
NegInfInterval!Date(Date(1999, 7, 6))) ==
NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(
NegInfInterval!Date(Date(2013, 1, 12))) ==
NegInfInterval!Date(Date(2013, 1 , 12)));
--------------------
+/
NegInfInterval span(in NegInfInterval interval) const pure nothrow
{
return NegInfInterval(_end > interval._end ? _end : interval._end);
}
/++
Shifts the $(D end) of this interval forward or backwards in time by the
given duration (a positive duration shifts the interval forward; a
negative duration shifts it backward). Effectively, it does
$(D end += duration).
Params:
duration = The duration to shift the interval by.
Examples:
--------------------
auto interval1 = NegInfInterval!Date(Date(2012, 4, 5));
auto interval2 = NegInfInterval!Date(Date(2012, 4, 5));
interval1.shift(dur!"days"(50));
assert(interval1 == NegInfInterval!Date(Date(2012, 5, 25)));
interval2.shift(dur!"days"(-50));
assert(interval2 == NegInfInterval!Date( Date(2012, 2, 15)));
--------------------
+/
void shift(D)(D duration) pure nothrow
if(__traits(compiles, end + duration))
{
_end += duration;
}
static if(__traits(compiles, end.add!"months"(1)) &&
__traits(compiles, end.add!"years"(1)))
{
/++
Shifts the $(D end) of this interval forward or backwards in time by
the given number of years and/or months (a positive number of years
and months shifts the interval forward; a negative number shifts it
backward). It adds the years the given years and months to end. It
effectively calls $(D add!"years"()) and then $(D add!"months"())
on end with the given number of years and months.
Params:
years = The number of years to shift the interval by.
months = The number of months to shift the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D end), causing its month to increment.
Throws:
$(D DateTimeException) if empty is true or if the resulting
interval would be invalid.
Examples:
--------------------
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.shift(2);
assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1)));
interval2.shift(-2);
assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
--------------------
+/
void shift(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
if(isIntegral!T)
{
auto end = _end;
end.add!"years"(years, allowOverflow);
end.add!"months"(months, allowOverflow);
_end = end;
}
}
/++
Expands the interval forwards in time. Effectively, it does
$(D end += duration).
Params:
duration = The duration to expand the interval by.
dir = The direction in time to expand the interval.
Examples:
--------------------
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.expand(dur!"days"(2));
assert(interval1 == NegInfInterval!Date(Date(2012, 3, 3)));
interval2.expand(dur!"days"(-2));
assert(interval2 == NegInfInterval!Date(Date(2012, 2, 28)));
--------------------
+/
void expand(D)(D duration) pure nothrow
if(__traits(compiles, end + duration))
{
_end += duration;
}
static if(__traits(compiles, end.add!"months"(1)) &&
__traits(compiles, end.add!"years"(1)))
{
/++
Expands the interval forwards and/or backwards in time. Effectively,
it adds the given number of months/years to end.
Params:
years = The number of years to expand the interval by.
months = The number of months to expand the interval by.
allowOverflow = Whether the days should be allowed to overflow
on $(D end), causing their month to increment.
Throws:
$(D DateTimeException) if empty is true or if the resulting
interval would be invalid.
Examples:
--------------------
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.expand(2);
assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1)));
interval2.expand(-2);
assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
--------------------
+/
void expand(T)(T years, T months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
if(isIntegral!T)
{
auto end = _end;
end.add!"years"(years, allowOverflow);
end.add!"months"(months, allowOverflow);
_end = end;
return;
}
}
/++
Returns a range which iterates backwards over the interval, starting
at $(D end), using $(D_PARAM func) to generate each successive time
point.
The range's $(D front) is the interval's $(D end). $(D_PARAM func) is
used to generate the next $(D front) when $(D popFront) is called. If
$(D_PARAM popFirst) is $(D PopFirst.yes), then $(D popFront) is called
before the range is returned (so that $(D front) is a time point which
$(D_PARAM func) would generate).
If $(D_PARAM func) ever generates a time point greater than or equal to
the current $(D front) of the range, then a $(D DateTimeException) will
be thrown.
There are helper functions in this module which generate common
delegates to pass to $(D bwdRange). Their documentation starts with
"Range-generating function," to make them easily searchable.
Params:
func = The function used to generate the time points of the
range over the interval.
popFirst = Whether $(D popFront) should be called on the range
before returning it.
Throws:
$(D DateTimeException) if this interval is empty.
Warning:
$(D_PARAM func) must be logically pure. Ideally, $(D_PARAM func)
would be a function pointer to a pure function, but forcing
$(D_PARAM func) to be pure is far too restrictive to be useful, and
in order to have the ease of use of having functions which generate
functions to pass to $(D fwdRange), $(D_PARAM func) must be a
delegate.
If $(D_PARAM func) retains state which changes as it is called, then
some algorithms will not work correctly, because the range's
$(D save) will have failed to have really saved the range's state.
To avoid such bugs, don't pass a delegate which is
not logically pure to $(D fwdRange). If $(D_PARAM func) is given the
same time point with two different calls, it must return the same
result both times.
Of course, none of the functions in this module have this problem,
so it's only relevant for custom delegates.
Examples:
--------------------
auto interval = NegInfInterval!Date(Date(2010, 9, 9));
auto func = (in Date date) //For iterating over even-numbered days.
{
if((date.day & 1) == 0)
return date - dur!"days"(2);
return date - dur!"days"(1);
};
auto range = interval.bwdRange(func);
assert(range.front == Date(2010, 9, 9)); //An odd day. Using PopFirst.yes would have made this Date(2010, 9, 8).
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(!range.empty);
--------------------
+/
NegInfIntervalRange!(TP) bwdRange(TP delegate(in TP) func, PopFirst popFirst = PopFirst.no) const
{
auto range = NegInfIntervalRange!(TP)(this, func);
if(popFirst == PopFirst.yes)
range.popFront();
return range;
}
/+
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString()
{
return _toStringImpl();
}
/++
Converts this interval to a string.
+/
//Due to bug http://d.puremagic.com/issues/show_bug.cgi?id=3715 , we can't
//have versions of toString() with extra modifiers, so we define one version
//with modifiers and one without.
string toString() const nothrow
{
return _toStringImpl();
}
private:
/+
Since we have two versions of toString(), we have _toStringImpl()
so that they can share implementations.
+/
string _toStringImpl() const nothrow
{
try
return format("[-∞ - %s)", _end);
catch(Exception e)
assert(0, "format() threw.");
}
TP _end;
}
//Test NegInfInterval's constructor.
unittest
{
version(testStdDateTime)
{
NegInfInterval!Date(Date.init);
NegInfInterval!TimeOfDay(TimeOfDay.init);
NegInfInterval!DateTime(DateTime.init);
NegInfInterval!SysTime(SysTime(0));
}
}
//Test NegInfInterval's end.
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(NegInfInterval!Date(Date(2010, 1, 1)).end, Date(2010, 1, 1));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 1, 1)).end, Date(2010, 1, 1));
_assertPred!"=="(NegInfInterval!Date(Date(1998, 1, 1)).end, Date(1998, 1, 1));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, cNegInfInterval.end));
static assert(__traits(compiles, iNegInfInterval.end));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).end == Date(2012, 3, 1));
}
}
//Test NegInfInterval's empty.
unittest
{
version(testStdDateTime)
{
assert(!NegInfInterval!Date(Date(2010, 1, 1)).empty);
assert(!NegInfInterval!TimeOfDay(TimeOfDay(0, 30, 0)).empty);
assert(!NegInfInterval!DateTime(DateTime(2010, 1, 1, 0, 30, 0)).empty);
assert(!NegInfInterval!SysTime(SysTime(DateTime(2010, 1, 1, 0, 30, 0))).empty);
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, cNegInfInterval.empty));
static assert(__traits(compiles, iNegInfInterval.empty));
//Verify Examples.
assert(!NegInfInterval!Date(Date(1996, 1, 2)).empty);
}
}
//Test NegInfInterval's contains(time point).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
assert(negInfInterval.contains(Date(2009, 7, 4)));
assert(negInfInterval.contains(Date(2010, 7, 3)));
assert(negInfInterval.contains(Date(2010, 7, 4)));
assert(negInfInterval.contains(Date(2010, 7, 5)));
assert(negInfInterval.contains(Date(2011, 7, 1)));
assert(negInfInterval.contains(Date(2012, 1, 6)));
assert(!negInfInterval.contains(Date(2012, 1, 7)));
assert(!negInfInterval.contains(Date(2012, 1, 8)));
assert(!negInfInterval.contains(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.contains(cdate)));
static assert(__traits(compiles, cNegInfInterval.contains(cdate)));
static assert(__traits(compiles, iNegInfInterval.contains(cdate)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(1994, 12, 24)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2000, 1, 5)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2012, 3, 1)));
}
}
//Test NegInfInterval's contains(Interval).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(in NegInfInterval!Date negInfInterval, in Interval!Date interval)
{
negInfInterval.contains(interval);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(negInfInterval.contains(negInfInterval));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!negInfInterval.contains(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!negInfInterval.contains(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(negInfInterval.contains(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(negInfInterval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!negInfInterval.contains(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!negInfInterval.contains(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!negInfInterval.contains(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(negInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 3))));
assert(negInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 4))));
assert(negInfInterval.contains(NegInfInterval!Date(Date(2010, 7, 5))));
assert(negInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 6))));
assert(negInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.contains(NegInfInterval!Date(Date(2012, 1, 8))));
assert(!NegInfInterval!Date(Date(2010, 7, 3)).contains(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 4)).contains(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 5)).contains(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 6)).contains(negInfInterval));
assert(NegInfInterval!Date(Date(2012, 1, 7)).contains(negInfInterval));
assert(NegInfInterval!Date(Date(2012, 1, 8)).contains(negInfInterval));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.contains(PosInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.contains(interval)));
static assert(__traits(compiles, negInfInterval.contains(cInterval)));
static assert(__traits(compiles, negInfInterval.contains(iInterval)));
static assert(__traits(compiles, negInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, negInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, negInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.contains(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(interval)));
static assert(__traits(compiles, cNegInfInterval.contains(cInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(iInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.contains(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(interval)));
static assert(__traits(compiles, iNegInfInterval.contains(cInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(iInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.contains(iNegInfInterval)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(PosInfInterval!Date(Date(1999, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(NegInfInterval!Date(Date(2013, 7, 9))));
}
}
//Test NegInfInterval's isBefore(time point).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
assert(!negInfInterval.isBefore(Date(2009, 7, 4)));
assert(!negInfInterval.isBefore(Date(2010, 7, 3)));
assert(!negInfInterval.isBefore(Date(2010, 7, 4)));
assert(!negInfInterval.isBefore(Date(2010, 7, 5)));
assert(!negInfInterval.isBefore(Date(2011, 7, 1)));
assert(!negInfInterval.isBefore(Date(2012, 1, 6)));
assert(negInfInterval.isBefore(Date(2012, 1, 7)));
assert(negInfInterval.isBefore(Date(2012, 1, 8)));
assert(negInfInterval.isBefore(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.isBefore(cdate)));
static assert(__traits(compiles, cNegInfInterval.isBefore(cdate)));
static assert(__traits(compiles, iNegInfInterval.isBefore(cdate)));
//Verify Examples.
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(1994, 12, 24)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2000, 1, 5)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2012, 3, 1)));
}
}
//Test NegInfInterval's isBefore(Interval).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(in NegInfInterval!Date negInfInterval, in Interval!Date interval)
{
negInfInterval.isBefore(interval);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!negInfInterval.isBefore(negInfInterval));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!negInfInterval.isBefore(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(negInfInterval.isBefore(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(negInfInterval.isBefore(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.isBefore(NegInfInterval!Date(Date(2012, 1, 8))));
assert(!NegInfInterval!Date(Date(2010, 7, 3)).isBefore(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 4)).isBefore(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 5)).isBefore(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 6)).isBefore(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 7)).isBefore(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 8)).isBefore(negInfInterval));
assert(!negInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isBefore(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 6))));
assert(negInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 7))));
assert(negInfInterval.isBefore(PosInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.isBefore(interval)));
static assert(__traits(compiles, negInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(interval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isBefore(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(interval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(cInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(iInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isBefore(iNegInfInterval)));
//Verify Examples.
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(PosInfInterval!Date(Date(1999, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(PosInfInterval!Date(Date(2012, 3, 1))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(NegInfInterval!Date(Date(2013, 7, 9))));
}
}
//Test NegInfInterval's isAfter(time point).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
assert(!negInfInterval.isAfter(Date(2009, 7, 4)));
assert(!negInfInterval.isAfter(Date(2010, 7, 3)));
assert(!negInfInterval.isAfter(Date(2010, 7, 4)));
assert(!negInfInterval.isAfter(Date(2010, 7, 5)));
assert(!negInfInterval.isAfter(Date(2011, 7, 1)));
assert(!negInfInterval.isAfter(Date(2012, 1, 6)));
assert(!negInfInterval.isAfter(Date(2012, 1, 7)));
assert(!negInfInterval.isAfter(Date(2012, 1, 8)));
assert(!negInfInterval.isAfter(Date(2013, 1, 7)));
const cdate = Date(2010, 7, 6);
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.isAfter(cdate)));
static assert(__traits(compiles, cNegInfInterval.isAfter(cdate)));
static assert(__traits(compiles, iNegInfInterval.isAfter(cdate)));
}
}
//Test NegInfInterval's isAfter(Interval).
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(in NegInfInterval!Date negInfInterval, in Interval!Date interval)
{
negInfInterval.isAfter(interval);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!negInfInterval.isAfter(negInfInterval));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!negInfInterval.isAfter(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.isAfter(NegInfInterval!Date(Date(2012, 1, 8))));
assert(!NegInfInterval!Date(Date(2010, 7, 3)).isAfter(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 4)).isAfter(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 5)).isAfter(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 6)).isAfter(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 7)).isAfter(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 8)).isAfter(negInfInterval));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.isAfter(PosInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.isAfter(interval)));
static assert(__traits(compiles, negInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(interval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAfter(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(interval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(cInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(iInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAfter(iNegInfInterval)));
//Verify Examples.
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(1994, 12, 24)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2000, 1, 5)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2012, 3, 1)));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(PosInfInterval!Date(Date(2012, 3, 1))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(NegInfInterval!Date(Date(2013, 7, 9))));
}
}
//Test NegInfInterval's intersects().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(in NegInfInterval!Date negInfInterval, in Interval!Date interval)
{
negInfInterval.intersects(interval);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(negInfInterval.intersects(negInfInterval));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(negInfInterval.intersects(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(negInfInterval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(negInfInterval.intersects(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(!negInfInterval.intersects(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!negInfInterval.intersects(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 3))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 4))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2010, 7, 5))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 6))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 7))));
assert(negInfInterval.intersects(NegInfInterval!Date(Date(2012, 1, 8))));
assert(NegInfInterval!Date(Date(2010, 7, 3)).intersects(negInfInterval));
assert(NegInfInterval!Date(Date(2010, 7, 4)).intersects(negInfInterval));
assert(NegInfInterval!Date(Date(2010, 7, 5)).intersects(negInfInterval));
assert(NegInfInterval!Date(Date(2012, 1, 6)).intersects(negInfInterval));
assert(NegInfInterval!Date(Date(2012, 1, 7)).intersects(negInfInterval));
assert(NegInfInterval!Date(Date(2012, 1, 8)).intersects(negInfInterval));
assert(negInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 3))));
assert(negInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 4))));
assert(negInfInterval.intersects(PosInfInterval!Date(Date(2010, 7, 5))));
assert(negInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.intersects(PosInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.intersects(interval)));
static assert(__traits(compiles, negInfInterval.intersects(cInterval)));
static assert(__traits(compiles, negInfInterval.intersects(iInterval)));
static assert(__traits(compiles, negInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, negInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, negInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.intersects(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(interval)));
static assert(__traits(compiles, cNegInfInterval.intersects(cInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(iInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersects(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(interval)));
static assert(__traits(compiles, iNegInfInterval.intersects(cInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(iInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersects(iNegInfInterval)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects(Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(PosInfInterval!Date(Date(1999, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects(PosInfInterval!Date(Date(2012, 3, 1))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(NegInfInterval!Date(Date(1996, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects(NegInfInterval!Date(Date(2013, 7, 9))));
}
}
//Test NegInfInterval's intersection().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I, J)(in I interval1, in J interval2)
{
interval1.intersection(interval2);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assertThrown!DateTimeException(testInterval(negInfInterval, PosInfInterval!Date(Date(2012, 1, 7))));
assertThrown!DateTimeException(testInterval(negInfInterval, PosInfInterval!Date(Date(2012, 1, 8))));
_assertPred!"=="(negInfInterval.intersection(negInfInterval),
negInfInterval);
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))),
Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
Interval!Date(Date(2010, 7, 1), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2010, 7, 3))),
NegInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2010, 7, 4))),
NegInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2010, 7, 5))),
NegInfInterval!Date(Date(2010, 7, 5)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 6)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(NegInfInterval!Date(Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 3)).intersection(negInfInterval),
NegInfInterval!Date(Date(2010, 7, 3)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 4)).intersection(negInfInterval),
NegInfInterval!Date(Date(2010, 7, 4)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 5)).intersection(negInfInterval),
NegInfInterval!Date(Date(2010, 7, 5)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 6)).intersection(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 6)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 7)).intersection(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 8)).intersection(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 3))),
Interval!Date(Date(2010, 7, 3), Date(2012, 1 ,7)));
_assertPred!"=="(negInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 4))),
Interval!Date(Date(2010, 7, 4), Date(2012, 1 ,7)));
_assertPred!"=="(negInfInterval.intersection(PosInfInterval!Date(Date(2010, 7, 5))),
Interval!Date(Date(2010, 7, 5), Date(2012, 1 ,7)));
_assertPred!"=="(negInfInterval.intersection(PosInfInterval!Date(Date(2012, 1, 6))),
Interval!Date(Date(2012, 1, 6), Date(2012, 1 ,7)));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.intersection(interval)));
static assert(__traits(compiles, negInfInterval.intersection(cInterval)));
static assert(__traits(compiles, negInfInterval.intersection(iInterval)));
static assert(__traits(compiles, negInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, negInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, negInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.intersection(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(interval)));
static assert(__traits(compiles, cNegInfInterval.intersection(cInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(iInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.intersection(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(interval)));
static assert(__traits(compiles, iNegInfInterval.intersection(cInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(iInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.intersection(iNegInfInterval)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1990, 7 , 6), Date(2000, 8, 2)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(PosInfInterval!Date(Date(1990, 7, 6))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(PosInfInterval!Date(Date(1999, 1, 12))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(1999, 7 , 6)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection(NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2012, 3 , 1)));
}
}
//Test NegInfInterval's isAdjacent().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(in NegInfInterval!Date negInfInterval, in Interval!Date interval)
{
negInfInterval.isAdjacent(interval);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assert(!negInfInterval.isAdjacent(negInfInterval));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))));
assert(negInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))));
assert(!negInfInterval.isAdjacent(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 6))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.isAdjacent(NegInfInterval!Date(Date(2012, 1, 8))));
assert(!NegInfInterval!Date(Date(2010, 7, 3)).isAdjacent(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 4)).isAdjacent(negInfInterval));
assert(!NegInfInterval!Date(Date(2010, 7, 5)).isAdjacent(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 6)).isAdjacent(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 7)).isAdjacent(negInfInterval));
assert(!NegInfInterval!Date(Date(2012, 1, 8)).isAdjacent(negInfInterval));
assert(!negInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 3))));
assert(!negInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 4))));
assert(!negInfInterval.isAdjacent(PosInfInterval!Date(Date(2010, 7, 5))));
assert(!negInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 6))));
assert(negInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 7))));
assert(!negInfInterval.isAdjacent(PosInfInterval!Date(Date(2012, 1, 8))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.isAdjacent(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(interval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(cInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(iInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(posInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(cPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.isAdjacent(iNegInfInterval)));
//Verify Examples.
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(1999, 1, 12), Date(2012, 3, 1))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(2012, 3, 1), Date(2019, 2, 2))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(PosInfInterval!Date(Date(1999, 5, 4))));
assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(PosInfInterval!Date(Date(2012, 3, 1))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(NegInfInterval!Date(Date(1996, 5, 4))));
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent(NegInfInterval!Date(Date(2012, 3, 1))));
}
}
//Test NegInfInterval's merge().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I, J)(in I interval1, in J interval2)
{
interval1.merge(interval2);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))));
_assertPred!"=="(negInfInterval.merge(negInfInterval),
negInfInterval);
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
NegInfInterval!Date(Date(2013, 7, 3)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.merge(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 3))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.merge(NegInfInterval!Date(Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 3)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 4)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 5)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 6)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 7)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 8)).merge(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 8)));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 3)))));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 4)))));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2010, 7, 5)))));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 6)))));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 7)))));
static assert(!__traits(compiles, negInfInterval.merge(PosInfInterval!Date(Date(2012, 1, 8)))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.merge(interval)));
static assert(__traits(compiles, negInfInterval.merge(cInterval)));
static assert(__traits(compiles, negInfInterval.merge(iInterval)));
static assert(!__traits(compiles, negInfInterval.merge(posInfInterval)));
static assert(!__traits(compiles, negInfInterval.merge(cPosInfInterval)));
static assert(!__traits(compiles, negInfInterval.merge(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.merge(negInfInterval)));
static assert(__traits(compiles, negInfInterval.merge(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.merge(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.merge(interval)));
static assert(__traits(compiles, cNegInfInterval.merge(cInterval)));
static assert(__traits(compiles, cNegInfInterval.merge(iInterval)));
static assert(!__traits(compiles, cNegInfInterval.merge(posInfInterval)));
static assert(!__traits(compiles, cNegInfInterval.merge(cPosInfInterval)));
static assert(!__traits(compiles, cNegInfInterval.merge(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.merge(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.merge(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.merge(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.merge(interval)));
static assert(__traits(compiles, iNegInfInterval.merge(cInterval)));
static assert(__traits(compiles, iNegInfInterval.merge(iInterval)));
static assert(!__traits(compiles, iNegInfInterval.merge(posInfInterval)));
static assert(!__traits(compiles, iNegInfInterval.merge(cPosInfInterval)));
static assert(!__traits(compiles, iNegInfInterval.merge(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.merge(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.merge(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.merge(iNegInfInterval)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == NegInfInterval!Date(Date(2015, 9 , 2)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge(NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
}
}
//Test NegInfInterval's span().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I, J)(in I interval1, in J interval2)
{
interval1.span(interval2);
}
assertThrown!DateTimeException(testInterval(negInfInterval, Interval!Date(Date(2010, 7, 4), dur!"days"(0))));
_assertPred!"=="(negInfInterval.span(negInfInterval),
negInfInterval);
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 1), Date(2010, 7, 3))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 1), Date(2013, 7, 3))),
NegInfInterval!Date(Date(2013, 7, 3)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 3), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2010, 7, 5), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2012, 1, 6), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2012, 1, 7), Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(negInfInterval.span(Interval!Date(Date(2012, 1, 8), Date(2012, 1, 9))),
NegInfInterval!Date(Date(2012, 1, 9)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2010, 7, 3))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2010, 7, 4))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2010, 7, 5))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2012, 1, 6))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2012, 1, 7))),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(negInfInterval.span(NegInfInterval!Date(Date(2012, 1, 8))),
NegInfInterval!Date(Date(2012, 1, 8)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 3)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 4)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 7, 5)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 6)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 7)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 7)));
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 8)).span(negInfInterval),
NegInfInterval!Date(Date(2012, 1, 8)));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2010, 7, 3)))));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2010, 7, 4)))));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2010, 7, 5)))));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2012, 1, 6)))));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2012, 1, 7)))));
static assert(!__traits(compiles, negInfInterval.span(PosInfInterval!Date(Date(2012, 1, 8)))));
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
const cInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
immutable iInterval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
immutable iPosInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, negInfInterval.span(interval)));
static assert(__traits(compiles, negInfInterval.span(cInterval)));
static assert(__traits(compiles, negInfInterval.span(iInterval)));
static assert(!__traits(compiles, negInfInterval.span(posInfInterval)));
static assert(!__traits(compiles, negInfInterval.span(cPosInfInterval)));
static assert(!__traits(compiles, negInfInterval.span(iPosInfInterval)));
static assert(__traits(compiles, negInfInterval.span(negInfInterval)));
static assert(__traits(compiles, negInfInterval.span(cNegInfInterval)));
static assert(__traits(compiles, negInfInterval.span(iNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.span(interval)));
static assert(__traits(compiles, cNegInfInterval.span(cInterval)));
static assert(__traits(compiles, cNegInfInterval.span(iInterval)));
static assert(!__traits(compiles, cNegInfInterval.span(posInfInterval)));
static assert(!__traits(compiles, cNegInfInterval.span(cPosInfInterval)));
static assert(!__traits(compiles, cNegInfInterval.span(iPosInfInterval)));
static assert(__traits(compiles, cNegInfInterval.span(negInfInterval)));
static assert(__traits(compiles, cNegInfInterval.span(cNegInfInterval)));
static assert(__traits(compiles, cNegInfInterval.span(iNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.span(interval)));
static assert(__traits(compiles, iNegInfInterval.span(cInterval)));
static assert(__traits(compiles, iNegInfInterval.span(iInterval)));
static assert(!__traits(compiles, iNegInfInterval.span(posInfInterval)));
static assert(!__traits(compiles, iNegInfInterval.span(cPosInfInterval)));
static assert(!__traits(compiles, iNegInfInterval.span(iPosInfInterval)));
static assert(__traits(compiles, iNegInfInterval.span(negInfInterval)));
static assert(__traits(compiles, iNegInfInterval.span(cNegInfInterval)));
static assert(__traits(compiles, iNegInfInterval.span(iNegInfInterval)));
//Verify Examples.
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == NegInfInterval!Date(Date(2015, 9 , 2)));
assert(NegInfInterval!Date(Date(1600, 1, 7)).span(Interval!Date(Date(2012, 3, 11), Date(2017, 7, 1))) == NegInfInterval!Date(Date(2017, 7 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(2012, 3 , 1)));
assert(NegInfInterval!Date(Date(2012, 3, 1)).span(NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
}
}
//Test NegInfInterval's shift().
unittest
{
version(testStdDateTime)
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.shift(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), NegInfInterval!Date(Date(2012, 1, 29)));
testInterval(interval, dur!"days"(-22), NegInfInterval!Date(Date(2011, 12, 16)));
const cInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.shift(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.shift(dur!"days"(5))));
//Verify Examples.
auto interval1 = NegInfInterval!Date(Date(2012, 4, 5));
auto interval2 = NegInfInterval!Date(Date(2012, 4, 5));
interval1.shift(dur!"days"(50));
assert(interval1 == NegInfInterval!Date(Date(2012, 5, 25)));
interval2.shift(dur!"days"(-50));
assert(interval2 == NegInfInterval!Date( Date(2012, 2, 15)));
}
}
//Test NegInfInterval's shift(int, int, AllowDayOverflow).
unittest
{
version(testStdDateTime)
{
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
static void testIntervalFail(I)(I interval, int years, int months)
{
interval.shift(years, months);
}
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, in I expected, size_t line = __LINE__)
{
interval.shift(years, months, allow);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, NegInfInterval!Date(Date(2017, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, NegInfInterval!Date(Date(2007, 1, 7)));
auto interval2 = NegInfInterval!Date(Date(2010, 5, 31));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2011, 7, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2011, 5, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2009, 5, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2009, 7, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, NegInfInterval!Date(Date(2011, 6, 30)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, NegInfInterval!Date(Date(2011, 4, 30)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, NegInfInterval!Date(Date(2009, 4, 30)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, NegInfInterval!Date(Date(2009, 6, 30)));
}
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(!__traits(compiles, cNegInfInterval.shift(1)));
static assert(!__traits(compiles, iNegInfInterval.shift(1)));
//Verify Examples.
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.shift(2);
assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1)));
interval2.shift(-2);
assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
}
}
//Test NegInfInterval's expand().
unittest
{
version(testStdDateTime)
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I)(I interval, in Duration duration, in I expected, size_t line = __LINE__)
{
interval.expand(duration);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, dur!"days"(22), NegInfInterval!Date(Date(2012, 1, 29)));
testInterval(interval, dur!"days"(-22), NegInfInterval!Date(Date(2011, 12, 16)));
const cInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(!__traits(compiles, cInterval.expand(dur!"days"(5))));
static assert(!__traits(compiles, iInterval.expand(dur!"days"(5))));
//Verify Examples.
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.expand(dur!"days"(2));
assert(interval1 == NegInfInterval!Date(Date(2012, 3, 3)));
interval2.expand(dur!"days"(-2));
assert(interval2 == NegInfInterval!Date(Date(2012, 2, 28)));
}
}
//Test NegInfInterval's expand(int, int, AllowDayOverflow).
unittest
{
version(testStdDateTime)
{
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(I)(I interval, int years, int months, AllowDayOverflow allow, in I expected, size_t line = __LINE__)
{
interval.expand(years, months, allow);
_assertPred!"=="(interval, expected, "", __FILE__, line);
}
testInterval(interval, 5, 0, AllowDayOverflow.yes, NegInfInterval!Date(Date(2017, 1, 7)));
testInterval(interval, -5, 0, AllowDayOverflow.yes, NegInfInterval!Date(Date(2007, 1, 7)));
auto interval2 = NegInfInterval!Date(Date(2010, 5, 31));
testInterval(interval2, 1, 1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2011, 7, 1)));
testInterval(interval2, 1, -1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2011, 5, 1)));
testInterval(interval2, -1, -1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2009, 5, 1)));
testInterval(interval2, -1, 1, AllowDayOverflow.yes, NegInfInterval!Date(Date(2009, 7, 1)));
testInterval(interval2, 1, 1, AllowDayOverflow.no, NegInfInterval!Date(Date(2011, 6, 30)));
testInterval(interval2, 1, -1, AllowDayOverflow.no, NegInfInterval!Date(Date(2011, 4, 30)));
testInterval(interval2, -1, -1, AllowDayOverflow.no, NegInfInterval!Date(Date(2009, 4, 30)));
testInterval(interval2, -1, 1, AllowDayOverflow.no, NegInfInterval!Date( Date(2009, 6, 30)));
}
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(!__traits(compiles, cNegInfInterval.expand(1)));
static assert(!__traits(compiles, iNegInfInterval.expand(1)));
//Verify Examples.
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1));
auto interval2 = NegInfInterval!Date(Date(2012, 3, 1));
interval1.expand(2);
assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1)));
interval2.expand(-2);
assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
}
}
//Test NegInfInterval's bwdRange().
unittest
{
version(testStdDateTime)
{
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static void testInterval(NegInfInterval!Date negInfInterval)
{
negInfInterval.bwdRange(everyDayOfWeek!(Date, Direction.fwd)(DayOfWeek.fri)).popFront();
}
assertThrown!DateTimeException(testInterval(negInfInterval));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 10, 1)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri)).front,
Date(2010, 10, 1));
_assertPred!"=="(NegInfInterval!Date(Date(2010, 10, 1)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri), PopFirst.yes).front,
Date(2010, 9, 24));
//Verify Examples.
auto interval = NegInfInterval!Date(Date(2010, 9, 9));
auto func = delegate (in Date date)
{
if((date.day & 1) == 0)
return date - dur!"days"(2);
return date - dur!"days"(1);
};
auto range = interval.bwdRange(func);
//An odd day. Using PopFirst.yes would have made this Date(2010, 9, 8).
assert(range.front == Date(2010, 9, 9));
range.popFront();
assert(range.front == Date(2010, 9, 8));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 4));
range.popFront();
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(!range.empty);
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, cNegInfInterval.bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri))));
static assert(__traits(compiles, iNegInfInterval.bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri))));
}
}
//Test NegInfInterval's toString().
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(NegInfInterval!Date(Date(2012, 1, 7)).toString(), "[-∞ - 2012-Jan-07)");
const cNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
immutable iNegInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
static assert(__traits(compiles, cNegInfInterval.toString()));
static assert(__traits(compiles, iNegInfInterval.toString()));
}
}
/++
Range-generating function.
Returns a delegate which returns the next time point with the given
$(D DayOfWeek) in a range.
Using this delegate allows iteration over successive time points which
are all the same day of the week. e.g. passing $(D DayOfWeek.mon) to
$(D everyDayOfWeek) would result in a delegate which could be used to
iterate over all of the Mondays in a range.
Params:
dir = The direction to iterate in. If passing the return value to
$(D fwdRange), use $(D Direction.fwd). If passing it to
$(D bwdRange), use $(D Direction.bwd).
dayOfWeek = The week that each time point in the range will be.
Examples:
--------------------
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = everyDayOfWeek!Date(DayOfWeek.mon);
auto range = interval.fwdRange(func);
//A Thursday. Using PopFirst.yes would have made this Date(2010, 9, 6).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 13));
range.popFront();
assert(range.front == Date(2010, 9, 20));
range.popFront();
assert(range.empty);
--------------------
+/
static TP delegate(in TP) everyDayOfWeek(TP, Direction dir = Direction.fwd)(DayOfWeek dayOfWeek) nothrow
if(isTimePoint!TP &&
(dir == Direction.fwd || dir == Direction.bwd) &&
__traits(hasMember, TP, "dayOfWeek") &&
!__traits(isStaticFunction, TP.dayOfWeek) &&
is(ReturnType!(TP.dayOfWeek) == DayOfWeek) &&
(functionAttributes!(TP.dayOfWeek) & FunctionAttribute.property) &&
(functionAttributes!(TP.dayOfWeek) & FunctionAttribute.nothrow_))
{
TP func(in TP tp)
{
TP retval = cast(TP)tp;
immutable days = daysToDayOfWeek(retval.dayOfWeek, dayOfWeek);
static if(dir == Direction.fwd)
immutable adjustedDays = days == 0 ? 7 : days;
else
immutable adjustedDays = days == 0 ? -7 : days - 7;
return retval += dur!"days"(adjustedDays);
}
return &func;
}
unittest
{
version(testStdDateTime)
{
auto funcFwd = everyDayOfWeek!Date(DayOfWeek.mon);
auto funcBwd = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.mon);
_assertPred!"=="(funcFwd(Date(2010, 8, 28)), Date(2010, 8, 30));
_assertPred!"=="(funcFwd(Date(2010, 8, 29)), Date(2010, 8, 30));
_assertPred!"=="(funcFwd(Date(2010, 8, 30)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 8, 31)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 1)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 2)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 3)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 4)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 5)), Date(2010, 9, 6));
_assertPred!"=="(funcFwd(Date(2010, 9, 6)), Date(2010, 9, 13));
_assertPred!"=="(funcFwd(Date(2010, 9, 7)), Date(2010, 9, 13));
_assertPred!"=="(funcBwd(Date(2010, 8, 28)), Date(2010, 8, 23));
_assertPred!"=="(funcBwd(Date(2010, 8, 29)), Date(2010, 8, 23));
_assertPred!"=="(funcBwd(Date(2010, 8, 30)), Date(2010, 8, 23));
_assertPred!"=="(funcBwd(Date(2010, 8, 31)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 1)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 2)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 3)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 4)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 5)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 6)), Date(2010, 8, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 7)), Date(2010, 9, 6));
static assert(!__traits(compiles, everyDayOfWeek!(TimeOfDay)(DayOfWeek.mon)));
static assert(__traits(compiles, everyDayOfWeek!(DateTime)(DayOfWeek.mon)));
static assert(__traits(compiles, everyDayOfWeek!(SysTime)(DayOfWeek.mon)));
//Verify Examples.
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = everyDayOfWeek!Date(DayOfWeek.mon);
auto range = interval.fwdRange(func);
//A Thursday. Using PopFirst.yes would have made this Date(2010, 9, 6).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 6));
range.popFront();
assert(range.front == Date(2010, 9, 13));
range.popFront();
assert(range.front == Date(2010, 9, 20));
range.popFront();
assert(range.empty);
}
}
/++
Range-generating function.
Returns a delegate which returns the next time point with the given month
which would be reached by adding months to the given time point.
So, using this delegate allows iteration over successive time points
which are in the same month but different years. For example,
iterate over each successive December 25th in an interval by starting with a
date which had the 25th as its day and passed $(D Month.dec) to
$(D everyMonth) to create the delegate.
Since it wouldn't really make sense to be iterating over a specific month
and end up with some of the time points in the succeeding month or two years
after the previous time point, $(D AllowDayOverflow.no) is always used when
calculating the next time point.
Params:
dir = The direction to iterate in. If passing the return value to
$(D fwdRange), use $(D Direction.fwd). If passing it to
$(D bwdRange), use $(D Direction.bwd).
month = The month that each time point in the range will be in.
Examples:
--------------------
auto interval = Interval!Date(Date(2000, 1, 30), Date(2004, 8, 5));
auto func = everyMonth!(Date)(Month.feb);
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2010, 2, 29).
assert(range.front == Date(2000, 1, 30));
range.popFront();
assert(range.front == Date(2000, 2, 29));
range.popFront();
assert(range.front == Date(2001, 2, 28));
range.popFront();
assert(range.front == Date(2002, 2, 28));
range.popFront();
assert(range.front == Date(2003, 2, 28));
range.popFront();
assert(range.front == Date(2004, 2, 28));
range.popFront();
assert(range.empty);
--------------------
+/
static TP delegate(in TP) everyMonth(TP, Direction dir = Direction.fwd)(int month)
if(isTimePoint!TP &&
(dir == Direction.fwd || dir == Direction.bwd) &&
__traits(hasMember, TP, "month") &&
!__traits(isStaticFunction, TP.month) &&
is(ReturnType!(TP.month) == Month) &&
(functionAttributes!(TP.month) & FunctionAttribute.property) &&
(functionAttributes!(TP.month) & FunctionAttribute.nothrow_))
{
enforceValid!"months"(month);
TP func(in TP tp)
{
TP retval = cast(TP)tp;
immutable months = monthsToMonth(retval.month, month);
static if(dir == Direction.fwd)
immutable adjustedMonths = months == 0 ? 12 : months;
else
immutable adjustedMonths = months == 0 ? -12 : months - 12;
retval.add!"months"(adjustedMonths, AllowDayOverflow.no);
if(retval.month != month)
{
retval.add!"months"(-1);
assert(retval.month == month);
}
return retval;
}
return &func;
}
unittest
{
version(testStdDateTime)
{
auto funcFwd = everyMonth!Date(Month.jun);
auto funcBwd = everyMonth!(Date, Direction.bwd)(Month.jun);
_assertPred!"=="(funcFwd(Date(2010, 5, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 6, 30)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 7, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 8, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 9, 30)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 10, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 11, 30)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2010, 12, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 1, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 2, 28)), Date(2011, 6, 28));
_assertPred!"=="(funcFwd(Date(2011, 3, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 4, 30)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 5, 31)), Date(2011, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 6, 30)), Date(2012, 6, 30));
_assertPred!"=="(funcFwd(Date(2011, 7, 31)), Date(2012, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 5, 31)), Date(2009, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 6, 30)), Date(2009, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 7, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 8, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 9, 30)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 10, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 11, 30)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2010, 12, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 1, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 2, 28)), Date(2010, 6, 28));
_assertPred!"=="(funcBwd(Date(2011, 3, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 4, 30)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 5, 31)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 6, 30)), Date(2010, 6, 30));
_assertPred!"=="(funcBwd(Date(2011, 7, 30)), Date(2011, 6, 30));
static assert(!__traits(compiles, everyMonth!(TimeOfDay)(Month.jan)));
static assert(__traits(compiles, everyMonth!(DateTime)(Month.jan)));
static assert(__traits(compiles, everyMonth!(SysTime)(Month.jan)));
//Verify Examples.
auto interval = Interval!Date(Date(2000, 1, 30), Date(2004, 8, 5));
auto func = everyMonth!(Date)(Month.feb);
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2010, 2, 29).
assert(range.front == Date(2000, 1, 30));
range.popFront();
assert(range.front == Date(2000, 2, 29));
range.popFront();
assert(range.front == Date(2001, 2, 28));
range.popFront();
assert(range.front == Date(2002, 2, 28));
range.popFront();
assert(range.front == Date(2003, 2, 28));
range.popFront();
assert(range.front == Date(2004, 2, 28));
range.popFront();
assert(range.empty);
}
}
/++
Range-generating function.
Returns a delegate which returns the next time point which is the given
duration later.
Using this delegate allows iteration over successive time points which
are apart by the given duration e.g. passing $(D dur!"days"(3)) to
$(D everyDuration) would result in a delegate which could be used to iterate
over a range of days which are each 3 days apart.
Params:
dir = The direction to iterate in. If passing the return value to
$(D fwdRange), use $(D Direction.fwd). If passing it to
$(D bwdRange), use $(D Direction.bwd).
duration = The duration which separates each successive time point in
the range.
Examples:
--------------------
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = everyDuration!Date(dur!"days"(8));
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2010, 9, 10).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 10));
range.popFront();
assert(range.front == Date(2010, 9, 18));
range.popFront();
assert(range.front == Date(2010, 9, 26));
range.popFront();
assert(range.empty);
--------------------
+/
static TP delegate(in TP) everyDuration(TP, Direction dir = Direction.fwd, D)
(D duration) nothrow
if(isTimePoint!TP &&
__traits(compiles, TP.init + duration) &&
(dir == Direction.fwd || dir == Direction.bwd))
{
TP func(in TP tp)
{
static if(dir == Direction.fwd)
return tp + duration;
else
return tp - duration;
}
return &func;
}
unittest
{
version(testStdDateTime)
{
auto funcFwd = everyDuration!Date(dur!"days"(27));
auto funcBwd = everyDuration!(Date, Direction.bwd)(dur!"days"(27));
_assertPred!"=="(funcFwd(Date(2009, 12, 25)), Date(2010, 1, 21));
_assertPred!"=="(funcFwd(Date(2009, 12, 26)), Date(2010, 1, 22));
_assertPred!"=="(funcFwd(Date(2009, 12, 27)), Date(2010, 1, 23));
_assertPred!"=="(funcFwd(Date(2009, 12, 28)), Date(2010, 1, 24));
_assertPred!"=="(funcBwd(Date(2010, 1, 21)), Date(2009, 12, 25));
_assertPred!"=="(funcBwd(Date(2010, 1, 22)), Date(2009, 12, 26));
_assertPred!"=="(funcBwd(Date(2010, 1, 23)), Date(2009, 12, 27));
_assertPred!"=="(funcBwd(Date(2010, 1, 24)), Date(2009, 12, 28));
static assert(__traits(compiles, everyDuration!Date(dur!"hnsecs"(1))));
static assert(__traits(compiles, everyDuration!TimeOfDay(dur!"hnsecs"(1))));
static assert(__traits(compiles, everyDuration!DateTime(dur!"hnsecs"(1))));
static assert(__traits(compiles, everyDuration!SysTime(dur!"hnsecs"(1))));
//Verify Examples.
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = everyDuration!Date(dur!"days"(8));
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2010, 9, 10).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2010, 9, 10));
range.popFront();
assert(range.front == Date(2010, 9, 18));
range.popFront();
assert(range.front == Date(2010, 9, 26));
range.popFront();
assert(range.empty);
}
}
/++
Range-generating function.
Returns a delegate which returns the next time point which is the given
number of years, month, and duration later.
The difference between this version of $(D everyDuration) and the version
which just takes a $(D Duration) is that this one also takes the number of
years and months (along with an $(D AllowDayOverflow) to indicate whether
adding years and months should allow the days to overflow).
Note that if iterating forward, $(D add!"years"()) is called on the given
time point, then $(D add!"months"()), and finally the duration is added
to it. However, if iterating backwards, the duration is added first, then
$(D add!"months"()) is called, and finally $(D add!"years"()) is called.
That way, going backwards generates close to the same time points that
iterating forward does, but since adding years and months is not entirely
reversible (due to possible day overflow, regardless of whether
$(D AllowDayOverflow.yes) or $(D AllowDayOverflow.no) is used), it can't be
guaranteed that iterating backwards will give the same time points as
iterating forward would have (even assuming that the end of the range is a
time point which would be returned by the delegate when iterating forward
from $(D begin)).
Params:
dir = The direction to iterate in. If passing the return
value to $(D fwdRange), use $(D Direction.fwd). If
passing it to $(D bwdRange), use $(D Direction.bwd).
years = The number of years to add to the time point passed to
the delegate.
months = The number of months to add to the time point passed to
the delegate.
allowOverflow = Whether the days should be allowed to overflow on
$(D begin) and $(D end), causing their month to
increment.
duration = The duration to add to the time point passed to the
delegate.
Examples:
--------------------
auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27));
auto func = everyDuration!Date(4, 1, AllowDayOverflow.yes, dur!"days"(2));
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2014, 10, 12).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2014, 10, 4));
range.popFront();
assert(range.front == Date(2018, 11, 6));
range.popFront();
assert(range.front == Date(2022, 12, 8));
range.popFront();
assert(range.empty);
--------------------
+/
static TP delegate(in TP) everyDuration(TP, Direction dir = Direction.fwd, D)
(int years,
int months = 0,
AllowDayOverflow allowOverflow = AllowDayOverflow.yes,
D duration = dur!"days"(0)) nothrow
if(isTimePoint!TP &&
__traits(compiles, TP.init + duration) &&
__traits(compiles, TP.init.add!"years"(years)) &&
__traits(compiles, TP.init.add!"months"(months)) &&
(dir == Direction.fwd || dir == Direction.bwd))
{
TP func(in TP tp)
{
static if(dir == Direction.fwd)
{
TP retval = cast(TP)tp;
retval.add!"years"(years, allowOverflow);
retval.add!"months"(months, allowOverflow);
return retval + duration;
}
else
{
TP retval = tp - duration;
retval.add!"months"(-months, allowOverflow);
retval.add!"years"(-years, allowOverflow);
return retval;
}
}
return &func;
}
unittest
{
version(testStdDateTime)
{
{
auto funcFwd = everyDuration!Date(1, 2, AllowDayOverflow.yes, dur!"days"(3));
auto funcBwd = everyDuration!(Date, Direction.bwd)(1, 2, AllowDayOverflow.yes, dur!"days"(3));
_assertPred!"=="(funcFwd(Date(2009, 12, 25)), Date(2011, 2, 28));
_assertPred!"=="(funcFwd(Date(2009, 12, 26)), Date(2011, 3, 1));
_assertPred!"=="(funcFwd(Date(2009, 12, 27)), Date(2011, 3, 2));
_assertPred!"=="(funcFwd(Date(2009, 12, 28)), Date(2011, 3, 3));
_assertPred!"=="(funcFwd(Date(2009, 12, 29)), Date(2011, 3, 4));
_assertPred!"=="(funcBwd(Date(2011, 2, 28)), Date(2009, 12, 25));
_assertPred!"=="(funcBwd(Date(2011, 3, 1)), Date(2009, 12, 26));
_assertPred!"=="(funcBwd(Date(2011, 3, 2)), Date(2009, 12, 27));
_assertPred!"=="(funcBwd(Date(2011, 3, 3)), Date(2009, 12, 28));
_assertPred!"=="(funcBwd(Date(2011, 3, 4)), Date(2010, 1, 1));
}
{
auto funcFwd = everyDuration!Date(1, 2, AllowDayOverflow.no, dur!"days"(3));
auto funcBwd = everyDuration!(Date, Direction.bwd)(1, 2, AllowDayOverflow.yes, dur!"days"(3));
_assertPred!"=="(funcFwd(Date(2009, 12, 25)), Date(2011, 2, 28));
_assertPred!"=="(funcFwd(Date(2009, 12, 26)), Date(2011, 3, 1));
_assertPred!"=="(funcFwd(Date(2009, 12, 27)), Date(2011, 3, 2));
_assertPred!"=="(funcFwd(Date(2009, 12, 28)), Date(2011, 3, 3));
_assertPred!"=="(funcFwd(Date(2009, 12, 29)), Date(2011, 3, 3));
_assertPred!"=="(funcBwd(Date(2011, 2, 28)), Date(2009, 12, 25));
_assertPred!"=="(funcBwd(Date(2011, 3, 1)), Date(2009, 12, 26));
_assertPred!"=="(funcBwd(Date(2011, 3, 2)), Date(2009, 12, 27));
_assertPred!"=="(funcBwd(Date(2011, 3, 3)), Date(2009, 12, 28));
_assertPred!"=="(funcBwd(Date(2011, 3, 4)), Date(2010, 1, 1));
}
static assert(__traits(compiles, everyDuration!Date(1, 2, AllowDayOverflow.yes, dur!"hnsecs"(1))));
static assert(!__traits(compiles, everyDuration!TimeOfDay(1, 2, AllowDayOverflow.yes, dur!"hnsecs"(1))));
static assert(__traits(compiles, everyDuration!DateTime(1, 2, AllowDayOverflow.yes, dur!"hnsecs"(1))));
static assert(__traits(compiles, everyDuration!SysTime(1, 2, AllowDayOverflow.yes, dur!"hnsecs"(1))));
//Verify Examples.
auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27));
auto func = everyDuration!Date(4, 1, AllowDayOverflow.yes, dur!"days"(2));
auto range = interval.fwdRange(func);
//Using PopFirst.yes would have made this Date(2014, 10, 12).
assert(range.front == Date(2010, 9, 2));
range.popFront();
assert(range.front == Date(2014, 10, 4));
range.popFront();
assert(range.front == Date(2018, 11, 6));
range.popFront();
assert(range.front == Date(2022, 12, 8));
range.popFront();
assert(range.empty);
}
}
//TODO Add function to create a range generating function based on a date recurrence pattern string.
// This may or may not involve creating a date recurrence pattern class of some sort - probably
// yes if we want to make it easy to build them. However, there is a standard recurrence
// pattern string format which we'd want to support with a range generator (though if we have
// the class/struct, we'd probably want a version of the range generating function which took
// that rather than a string).
//==============================================================================
// Section with ranges.
//==============================================================================
/++
A range over an $(D Interval).
$(D IntervalRange) is only ever constructed by $(D Interval). However, when
it is constructed, it is given a function, $(D func), which is used to
generate the time points which are iterated over. $(D func) takes a time
point and returns a time point of the same type. For instance,
to iterate over all of the days in
the interval $(D Interval!Date), pass a function to $(D Interval)'s $(D fwdRange)
where that function took a $(D Date) and returned a $(D Date) which was one
day later. That function would then be used by $(D IntervalRange)'s
$(D popFront) to iterate over the $(D Date)s in the interval.
If $(D dir == Direction.fwd), then a range iterates forward in time, whereas
if $(D dir == Direction.bwd), then it iterates backwards in time. So, if
$(D dir == Direction.fwd) then $(D front == interval.begin), whereas if
$(D dir == Direction.bwd) then $(D front == interval.end). $(D func) must
generate a time point going in the proper direction of iteration, or a
$(D DateTimeException) will be thrown. So, to iterate forward in
time, the time point that $(D func) generates must be later in time than the
one passed to it. If it's either identical or earlier in time, then a
$(D DateTimeException) will be thrown. To iterate backwards, then
the generated time point must be before the time point which was passed in.
If the generated time point is ever passed the edge of the range in the
proper direction, then the edge of that range will be used instead. So, if
iterating forward, and the generated time point is past the interval's
$(D end), then $(D front) becomes $(D end). If iterating backwards, and the
generated time point is before $(D begin), then $(D front) becomes
$(D begin). In either case, the range would then be empty.
Also note that while normally the $(D begin) of an interval is included in
it and its $(D end) is excluded from it, if $(D dir == Direction.bwd), then
$(D begin) is treated as excluded and $(D end) is treated as included. This
allows for the same behavior in both directions. This works because none of
$(D Interval)'s functions which care about whether $(D begin) or $(D end) is
included or excluded are ever called by $(D IntervalRange). $(D interval)
returns a normal interval, regardless of whether $(D dir == Direction.fwd)
or if $(D dir == Direction.bwd), so any $(D Interval) functions which are
called on it which care about whether $(D begin) or $(D end) are included or
excluded will treat $(D begin) as included and $(D end) as excluded.
+/
struct IntervalRange(TP, Direction dir)
if(isTimePoint!TP && dir != Direction.both)
{
public:
/++
Params:
rhs = The $(D IntervalRange) to assign to this one.
+/
/+ref+/ IntervalRange opAssign(ref IntervalRange rhs) pure nothrow
{
_interval = rhs._interval;
_func = rhs._func;
return this;
}
/++
Whether this $(D IntervalRange) is empty.
+/
@property bool empty() const pure nothrow
{
return _interval.empty;
}
/++
The first time point in the range.
Throws:
$(D DateTimeException) if the range is empty.
+/
@property TP front() const pure
{
_enforceNotEmpty();
static if(dir == Direction.fwd)
return _interval.begin;
else
return _interval.end;
}
/++
Pops $(D front) from the range, using $(D func) to generate the next
time point in the range. If the generated time point is beyond the edge
of the range, then $(D front) is set to that edge, and the range is then
empty. So, if iterating forwards, and the generated time point is
greater than the interval's $(D end), then $(D front) is set to
$(D end). If iterating backwards, and the generated time point is less
than the interval's $(D begin), then $(D front) is set to $(D begin).
Throws:
$(D DateTimeException) if the range is empty or if the generated
time point is in the wrong direction (i.e. if iterating
forward and the generated time point is before $(D front), or if
iterating backwards and the generated time point is after
$(D front)).
+/
void popFront()
{
_enforceNotEmpty();
static if(dir == Direction.fwd)
{
auto begin = _func(_interval.begin);
if(begin > _interval.end)
begin = _interval.end;
_enforceCorrectDirection(begin);
_interval.begin = begin;
}
else
{
auto end = _func(_interval.end);
if(end < _interval.begin)
end = _interval.begin;
_enforceCorrectDirection(end);
_interval.end = end;
}
}
/++
Returns a copy of $(D this).
+/
@property IntervalRange save() pure nothrow
{
return this;
}
/++
The interval that this $(D IntervalRange) currently covers.
+/
@property Interval!TP interval() const pure nothrow
{
return cast(Interval!TP)_interval;
}
/++
The function used to generate the next time point in the range.
+/
TP delegate(in TP) func() pure nothrow @property
{
return _func;
}
/++
The $(D Direction) that this range iterates in.
+/
@property Direction direction() const pure nothrow
{
return dir;
}
private:
/+
Params:
interval = The interval that this range covers.
func = The function used to generate the time points which are
iterated over.
+/
this(in Interval!TP interval, TP delegate(in TP) func) pure nothrow
{
_func = func;
_interval = interval;
}
/+
Throws:
$(D DateTimeException) if this interval is empty.
+/
void _enforceNotEmpty(size_t line = __LINE__) const pure
{
if(empty)
throw new DateTimeException("Invalid operation for an empty IntervalRange.", __FILE__, line);
}
/+
Throws:
$(D DateTimeException) if $(D_PARAM newTP) is in the wrong
direction.
+/
void _enforceCorrectDirection(in TP newTP, size_t line = __LINE__) const
{
static if(dir == Direction.fwd)
{
enforce(newTP > _interval._begin,
new DateTimeException(format("Generated time point is before previous begin: prev [%s] new [%s]",
interval._begin,
newTP),
__FILE__,
line));
}
else
{
enforce(newTP < _interval._end,
new DateTimeException(format("Generated time point is after previous end: prev [%s] new [%s]",
interval._end,
newTP),
__FILE__,
line));
}
}
Interval!TP _interval;
TP delegate(in TP) _func;
}
//Test that IntervalRange satisfies the range predicates that it's supposed to satisfy.
unittest
{
version(testStdDateTime)
{
static assert(isInputRange!(IntervalRange!(Date, Direction.fwd)));
static assert(isForwardRange!(IntervalRange!(Date, Direction.fwd)));
//Commented out due to bug http://d.puremagic.com/issues/show_bug.cgi?id=4895
//static assert(!isOutputRange!(IntervalRange!(Date, Direction.fwd), Date));
static assert(!isBidirectionalRange!(IntervalRange!(Date, Direction.fwd)));
static assert(!isRandomAccessRange!(IntervalRange!(Date, Direction.fwd)));
static assert(!hasSwappableElements!(IntervalRange!(Date, Direction.fwd)));
static assert(!hasAssignableElements!(IntervalRange!(Date, Direction.fwd)));
static assert(!hasLength!(IntervalRange!(Date, Direction.fwd)));
static assert(!isInfinite!(IntervalRange!(Date, Direction.fwd)));
static assert(!hasSlicing!(IntervalRange!(Date, Direction.fwd)));
static assert(is(ElementType!(IntervalRange!(Date, Direction.fwd)) == Date));
static assert(is(ElementType!(IntervalRange!(TimeOfDay, Direction.fwd)) == TimeOfDay));
static assert(is(ElementType!(IntervalRange!(DateTime, Direction.fwd)) == DateTime));
static assert(is(ElementType!(IntervalRange!(SysTime, Direction.fwd)) == SysTime));
}
}
//Test construction of IntervalRange.
unittest
{
version(testStdDateTime)
{
{
Date dateFunc(in Date date)
{
return date;
}
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto ir = IntervalRange!(Date, Direction.fwd)(interval, &dateFunc);
}
{
TimeOfDay todFunc(in TimeOfDay tod)
{
return tod;
}
auto interval = Interval!TimeOfDay(TimeOfDay(12, 1, 7), TimeOfDay(14, 0, 0));
auto ir = IntervalRange!(TimeOfDay, Direction.fwd)(interval, &todFunc);
}
{
DateTime dtFunc(in DateTime dt)
{
return dt;
}
auto interval = Interval!DateTime(DateTime(2010, 7, 4, 12, 1, 7), DateTime(2012, 1, 7, 14, 0, 0));
auto ir = IntervalRange!(DateTime, Direction.fwd)(interval, &dtFunc);
}
{
SysTime stFunc(in SysTime st)
{
return cast(SysTime)st;
}
auto interval = Interval!SysTime(SysTime(DateTime(2010, 7, 4, 12, 1, 7)), SysTime(DateTime(2012, 1, 7, 14, 0, 0)));
auto ir = IntervalRange!(SysTime, Direction.fwd)(interval, &stFunc);
}
}
}
//Test IntervalRange's empty().
unittest
{
version(testStdDateTime)
{
//fwd
{
auto range = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 21)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
assert(!range.empty);
range.popFront();
assert(range.empty);
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
static assert(__traits(compiles, cRange.empty));
//Apparently, creating an immutable IntervalRange!Date doesn't work, so we can't test if
//empty works with it. However, since an immutable range is pretty useless, it's no great loss.
}
//bwd
{
auto range = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 21)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
assert(!range.empty);
range.popFront();
assert(range.empty);
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
static assert(__traits(compiles, cRange.empty));
//Apparently, creating an immutable IntervalRange!Date doesn't work, so we can't test if
//empty works with it. However, since an immutable range is pretty useless, it's no great loss.
}
}
}
//Test IntervalRange's front.
unittest
{
version(testStdDateTime)
{
//fwd
{
auto emptyRange = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 20)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
assertThrown!DateTimeException((in IntervalRange!(Date, Direction.fwd) range){range.front;}(emptyRange));
auto range = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed));
_assertPred!"=="(range.front, Date(2010, 7, 4));
auto poppedRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
_assertPred!"=="(poppedRange.front, Date(2010, 7, 7));
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
static assert(__traits(compiles, cRange.front));
}
//bwd
{
auto emptyRange = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 20)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
assertThrown!DateTimeException((in IntervalRange!(Date, Direction.bwd) range){range.front;}(emptyRange));
auto range = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed));
_assertPred!"=="(range.front, Date(2012, 1, 7));
auto poppedRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
_assertPred!"=="(poppedRange.front, Date(2012, 1, 4));
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
static assert(__traits(compiles, cRange.front));
}
}
}
//Test IntervalRange's popFront().
unittest
{
version(testStdDateTime)
{
//fwd
{
auto emptyRange = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 20)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
assertThrown!DateTimeException((IntervalRange!(Date, Direction.fwd) range){range.popFront();}(emptyRange));
auto range = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
auto expected = range.front;
foreach(date; range)
{
_assertPred!"=="(date, expected);
expected += dur!"days"(7);
}
_assertPred!"=="(walkLength(range), 79);
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
static assert(__traits(compiles, cRange.front));
}
//bwd
{
auto emptyRange = Interval!Date(Date(2010, 9, 19), Date(2010, 9, 20)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
assertThrown!DateTimeException((IntervalRange!(Date, Direction.bwd) range){range.popFront();}(emptyRange));
auto range = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
auto expected = range.front;
foreach(date; range)
{
_assertPred!"=="(date, expected);
expected += dur!"days"(-7);
}
_assertPred!"=="(walkLength(range), 79);
const cRange = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
static assert(!__traits(compiles, cRange.popFront()));
}
}
}
//Test IntervalRange's save.
unittest
{
version(testStdDateTime)
{
//fwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.save == range);
}
//bwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.save == range);
}
}
}
//Test IntervalRange's interval.
unittest
{
version(testStdDateTime)
{
//fwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.interval == interval);
const cRange = range;
static assert(__traits(compiles, cRange.interval));
}
//bwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.interval == interval);
const cRange = range;
static assert(__traits(compiles, cRange.interval));
}
}
}
//Test IntervalRange's func.
unittest
{
version(testStdDateTime)
{
//fwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.func == func);
}
//bwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.func == func);
}
}
}
//Test IntervalRange's direction.
unittest
{
version(testStdDateTime)
{
//fwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.direction == Direction.fwd);
const cRange = range;
static assert(__traits(compiles, cRange.direction));
}
//bwd
{
auto interval = Interval!Date(Date(2010, 7, 4), Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.direction == Direction.bwd);
const cRange = range;
static assert(__traits(compiles, cRange.direction));
}
}
}
/++
A range over a $(D PosInfInterval). It is an infinite range.
$(D PosInfIntervalRange) is only ever constructed by $(D PosInfInterval).
However, when it is constructed, it is given a function, $(D func), which
is used to generate the time points which are iterated over. $(D func)
takes a time point and returns a time point of the same type. For
instance, to iterate
over all of the days in the interval $(D PosInfInterval!Date), pass a function to
$(D PosInfInterval)'s $(D fwdRange) where that function took a $(D Date) and
returned a $(D Date) which was one day later. That function would then be
used by $(D PosInfIntervalRange)'s $(D popFront) to iterate over the
$(D Date)s in the interval - though obviously, since the range is infinite,
use a function such as $(D std.range.take) with it rather than
iterating over $(I all) of the dates.
As the interval goes to positive infinity, the range is always iterated over
forwards, never backwards. $(D func) must generate a time point going in
the proper direction of iteration, or a $(D DateTimeException) will be
thrown. So, the time points that $(D func) generates must be later in time
than the one passed to it. If it's either identical or earlier in time, then
a $(D DateTimeException) will be thrown.
+/
struct PosInfIntervalRange(TP)
if(isTimePoint!TP)
{
public:
/++
Params:
rhs = The $(D PosInfIntervalRange) to assign to this one.
+/
/+ref+/ PosInfIntervalRange opAssign(ref PosInfIntervalRange rhs) pure nothrow
{
_interval = rhs._interval;
_func = rhs._func;
return this;
}
/++
This is an infinite range, so it is never empty.
+/
enum bool empty = false;
/++
The first time point in the range.
+/
@property TP front() const pure nothrow
{
return _interval.begin;
}
/++
Pops $(D front) from the range, using $(D func) to generate the next
time point in the range.
Throws:
$(D DateTimeException) if the generated time point is less than
$(D front).
+/
void popFront()
{
auto begin = _func(_interval.begin);
_enforceCorrectDirection(begin);
_interval.begin = begin;
}
/++
Returns a copy of $(D this).
+/
@property PosInfIntervalRange save() pure nothrow
{
return this;
}
/++
The interval that this range currently covers.
+/
@property PosInfInterval!TP interval() const pure nothrow
{
return cast(PosInfInterval!TP)_interval;
}
/++
The function used to generate the next time point in the range.
+/
TP delegate(in TP) func() pure nothrow @property
{
return _func;
}
private:
/+
Params:
interval = The interval that this range covers.
func = The function used to generate the time points which are
iterated over.
+/
this(in PosInfInterval!TP interval, TP delegate(in TP) func) pure nothrow
{
_func = func;
_interval = interval;
}
/+
Throws:
$(D DateTimeException) if $(D_PARAME newTP) is in the wrong
direction.
+/
void _enforceCorrectDirection(in TP newTP, size_t line = __LINE__) const
{
enforce(newTP > _interval._begin,
new DateTimeException(format("Generated time point is before previous begin: prev [%s] new [%s]",
interval._begin,
newTP),
__FILE__,
line));
}
PosInfInterval!TP _interval;
TP delegate(in TP) _func;
}
//Test that PosInfIntervalRange satisfies the range predicates that it's supposed to satisfy.
unittest
{
version(testStdDateTime)
{
static assert(isInputRange!(PosInfIntervalRange!Date));
static assert(isForwardRange!(PosInfIntervalRange!Date));
static assert(isInfinite!(PosInfIntervalRange!Date));
//Commented out due to bug http://d.puremagic.com/issues/show_bug.cgi?id=4895
//static assert(!isOutputRange!(PosInfIntervalRange!Date, Date));
static assert(!isBidirectionalRange!(PosInfIntervalRange!Date));
static assert(!isRandomAccessRange!(PosInfIntervalRange!Date));
static assert(!hasSwappableElements!(PosInfIntervalRange!Date));
static assert(!hasAssignableElements!(PosInfIntervalRange!Date));
static assert(!hasLength!(PosInfIntervalRange!Date));
static assert(!hasSlicing!(PosInfIntervalRange!Date));
static assert(is(ElementType!(PosInfIntervalRange!Date) == Date));
static assert(is(ElementType!(PosInfIntervalRange!TimeOfDay) == TimeOfDay));
static assert(is(ElementType!(PosInfIntervalRange!DateTime) == DateTime));
static assert(is(ElementType!(PosInfIntervalRange!SysTime) == SysTime));
}
}
//Test construction of PosInfIntervalRange.
unittest
{
version(testStdDateTime)
{
{
Date dateFunc(in Date date)
{
return date;
}
auto posInfInterval = PosInfInterval!Date(Date(2010, 7, 4));
auto ir = PosInfIntervalRange!Date(posInfInterval, &dateFunc);
}
{
TimeOfDay todFunc(in TimeOfDay tod)
{
return tod;
}
auto posInfInterval = PosInfInterval!TimeOfDay(TimeOfDay(12, 1, 7));
auto ir = PosInfIntervalRange!(TimeOfDay)(posInfInterval, &todFunc);
}
{
DateTime dtFunc(in DateTime dt)
{
return dt;
}
auto posInfInterval = PosInfInterval!DateTime(DateTime(2010, 7, 4, 12, 1, 7));
auto ir = PosInfIntervalRange!(DateTime)(posInfInterval, &dtFunc);
}
{
SysTime stFunc(in SysTime st)
{
return cast(SysTime)st;
}
auto posInfInterval = PosInfInterval!SysTime(SysTime(DateTime(2010, 7, 4, 12, 1, 7)));
auto ir = PosInfIntervalRange!(SysTime)(posInfInterval, &stFunc);
}
}
}
//Test PosInfIntervalRange's front.
unittest
{
version(testStdDateTime)
{
auto range = PosInfInterval!Date(Date(2010, 7, 4)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed));
_assertPred!"=="(range.front, Date(2010, 7, 4));
auto poppedRange = PosInfInterval!Date(Date(2010, 7, 4)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
_assertPred!"=="(poppedRange.front, Date(2010, 7, 7));
const cRange = PosInfInterval!Date(Date(2010, 7, 4)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
static assert(__traits(compiles, cRange.front));
}
}
//Test PosInfIntervalRange's popFront().
unittest
{
version(testStdDateTime)
{
auto range = PosInfInterval!Date(Date(2010, 7, 4)).fwdRange(everyDayOfWeek!Date(DayOfWeek.wed), PopFirst.yes);
auto expected = range.front;
foreach(date; take(range, 79))
{
_assertPred!"=="(date, expected);
expected += dur!"days"(7);
}
const cRange = PosInfInterval!Date(Date(2010, 7, 4)).fwdRange(everyDayOfWeek!Date(DayOfWeek.fri));
static assert(!__traits(compiles, cRange.popFront()));
}
}
//Test PosInfIntervalRange's save.
unittest
{
version(testStdDateTime)
{
auto interval = PosInfInterval!Date(Date(2010, 7, 4));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.save == range);
}
}
//Test PosInfIntervalRange's interval.
unittest
{
version(testStdDateTime)
{
auto interval = PosInfInterval!Date(Date(2010, 7, 4));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.interval == interval);
const cRange = range;
static assert(__traits(compiles, cRange.interval));
}
}
//Test PosInfIntervalRange's func.
unittest
{
version(testStdDateTime)
{
auto interval = PosInfInterval!Date(Date(2010, 7, 4));
auto func = everyDayOfWeek!Date(DayOfWeek.fri);
auto range = interval.fwdRange(func);
assert(range.func == func);
}
}
/++
A range over a $(D NegInfInterval). It is an infinite range.
$(D NegInfIntervalRange) is only ever constructed by $(D NegInfInterval).
However, when it is constructed, it is given a function, $(D func), which
is used to generate the time points which are iterated over. $(D func)
takes a time point and returns a time point of the same type. For
instance, to iterate
over all of the days in the interval $(D NegInfInterval!Date), pass a function to
$(D NegInfInterval)'s $(D bwdRange) where that function took a $(D Date) and
returned a $(D Date) which was one day earlier. That function would then be
used by $(D NegInfIntervalRange)'s $(D popFront) to iterate over the
$(D Date)s in the interval - though obviously, since the range is infinite,
use a function such as $(D std.range.take) with it rather than
iterating over $(I all) of the dates.
As the interval goes to negative infinity, the range is always iterated over
backwards, never forwards. $(D func) must generate a time point going in
the proper direction of iteration, or a $(D DateTimeException) will be
thrown. So, the time points that $(D func) generates must be earlier in time
than the one passed to it. If it's either identical or later in time, then a
$(D DateTimeException) will be thrown.
Also note that while normally the $(D end) of an interval is excluded from
it, $(D NegInfIntervalRange) treats it as if it were included. This allows
for the same behavior as with $(D PosInfIntervalRange). This works
because none of $(D NegInfInterval)'s functions which care about whether
$(D end) is included or excluded are ever called by
$(D NegInfIntervalRange). $(D interval) returns a normal interval, so any
$(D NegInfInterval) functions which are called on it which care about
whether $(D end) is included or excluded will treat $(D end) as excluded.
+/
struct NegInfIntervalRange(TP)
if(isTimePoint!TP)
{
public:
/++
Params:
rhs = The $(D NegInfIntervalRange) to assign to this one.
+/
/+ref+/ NegInfIntervalRange opAssign(ref NegInfIntervalRange rhs) pure nothrow
{
_interval = rhs._interval;
_func = rhs._func;
return this;
}
/++
This is an infinite range, so it is never empty.
+/
enum bool empty = false;
/++
The first time point in the range.
+/
@property TP front() const pure nothrow
{
return _interval.end;
}
/++
Pops $(D front) from the range, using $(D func) to generate the next
time point in the range.
Throws:
$(D DateTimeException) if the generated time point is greater than
$(D front).
+/
void popFront()
{
auto end = _func(_interval.end);
_enforceCorrectDirection(end);
_interval.end = end;
}
/++
Returns a copy of $(D this).
+/
@property NegInfIntervalRange save() pure nothrow
{
return this;
}
/++
The interval that this range currently covers.
+/
@property NegInfInterval!TP interval() const pure nothrow
{
return cast(NegInfInterval!TP)_interval;
}
/++
The function used to generate the next time point in the range.
+/
TP delegate(in TP) func() pure nothrow @property
{
return _func;
}
private:
/+
Params:
interval = The interval that this range covers.
func = The function used to generate the time points which are
iterated over.
+/
this(in NegInfInterval!TP interval, TP delegate(in TP) func) pure nothrow
{
_func = func;
_interval = interval;
}
/+
Throws:
$(D DateTimeException) if $(D_PARAM newTP) is in the wrong
direction.
+/
void _enforceCorrectDirection(in TP newTP, size_t line = __LINE__) const
{
enforce(newTP < _interval._end,
new DateTimeException(format("Generated time point is before previous end: prev [%s] new [%s]",
interval._end,
newTP),
__FILE__,
line));
}
NegInfInterval!TP _interval;
TP delegate(in TP) _func;
}
//Test that NegInfIntervalRange satisfies the range predicates that it's supposed to satisfy.
unittest
{
version(testStdDateTime)
{
static assert(isInputRange!(NegInfIntervalRange!Date));
static assert(isForwardRange!(NegInfIntervalRange!Date));
static assert(isInfinite!(NegInfIntervalRange!Date));
//Commented out due to bug http://d.puremagic.com/issues/show_bug.cgi?id=4895
//static assert(!isOutputRange!(NegInfIntervalRange!Date, Date));
static assert(!isBidirectionalRange!(NegInfIntervalRange!Date));
static assert(!isRandomAccessRange!(NegInfIntervalRange!Date));
static assert(!hasSwappableElements!(NegInfIntervalRange!Date));
static assert(!hasAssignableElements!(NegInfIntervalRange!Date));
static assert(!hasLength!(NegInfIntervalRange!Date));
static assert(!hasSlicing!(NegInfIntervalRange!Date));
static assert(is(ElementType!(NegInfIntervalRange!Date) == Date));
static assert(is(ElementType!(NegInfIntervalRange!TimeOfDay) == TimeOfDay));
static assert(is(ElementType!(NegInfIntervalRange!DateTime) == DateTime));
}
}
//Test construction of NegInfIntervalRange.
unittest
{
version(testStdDateTime)
{
{
Date dateFunc(in Date date)
{
return date;
}
auto negInfInterval = NegInfInterval!Date(Date(2012, 1, 7));
auto ir = NegInfIntervalRange!Date(negInfInterval, &dateFunc);
}
{
TimeOfDay todFunc(in TimeOfDay tod)
{
return tod;
}
auto negInfInterval = NegInfInterval!TimeOfDay(TimeOfDay(14, 0, 0));
auto ir = NegInfIntervalRange!(TimeOfDay)(negInfInterval, &todFunc);
}
{
DateTime dtFunc(in DateTime dt)
{
return dt;
}
auto negInfInterval = NegInfInterval!DateTime(DateTime(2012, 1, 7, 14, 0, 0));
auto ir = NegInfIntervalRange!(DateTime)(negInfInterval, &dtFunc);
}
{
SysTime stFunc(in SysTime st)
{
return cast(SysTime)(st);
}
auto negInfInterval = NegInfInterval!SysTime(SysTime(DateTime(2012, 1, 7, 14, 0, 0)));
auto ir = NegInfIntervalRange!(SysTime)(negInfInterval, &stFunc);
}
}
}
//Test NegInfIntervalRange's front.
unittest
{
version(testStdDateTime)
{
auto range = NegInfInterval!Date(Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed));
_assertPred!"=="(range.front, Date(2012, 1, 7));
auto poppedRange = NegInfInterval!Date(Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
_assertPred!"=="(poppedRange.front, Date(2012, 1, 4));
const cRange = NegInfInterval!Date(Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
static assert(__traits(compiles, cRange.front));
}
}
//Test NegInfIntervalRange's popFront().
unittest
{
version(testStdDateTime)
{
auto range = NegInfInterval!Date(Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.wed), PopFirst.yes);
auto expected = range.front;
foreach(date; take(range, 79))
{
_assertPred!"=="(date, expected);
expected += dur!"days"(-7);
}
const cRange = NegInfInterval!Date(Date(2012, 1, 7)).bwdRange(everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri));
static assert(!__traits(compiles, cRange.popFront()));
}
}
//Test NegInfIntervalRange's save.
unittest
{
version(testStdDateTime)
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.save == range);
}
}
//Test NegInfIntervalRange's interval.
unittest
{
version(testStdDateTime)
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.interval == interval);
const cRange = range;
static assert(__traits(compiles, cRange.interval));
}
}
//Test NegInfIntervalRange's func.
unittest
{
version(testStdDateTime)
{
auto interval = NegInfInterval!Date(Date(2012, 1, 7));
auto func = everyDayOfWeek!(Date, Direction.bwd)(DayOfWeek.fri);
auto range = interval.bwdRange(func);
assert(range.func == func);
}
}
//==============================================================================
// Section with time zones.
//==============================================================================
/++
Represents a time zone. It is used with $(D SysTime) to indicate the time
zone of a $(D SysTime).
+/
abstract class TimeZone
{
public:
/++
The name of the time zone per the TZ Database. This is the name used to
get a $(D TimeZone) by name with $(D TimeZone.getTimeZone).
See_Also:
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ
Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List of
Time Zones)
+/
@property string name() const nothrow
{
return _name;
}
/++
Typically, the abbreviation (generally 3 or 4 letters) for the time zone
when DST is $(I not) in effect (e.g. PST). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific
Standard Time). Regardless, it is not the same as name.
+/
@property string stdName() const nothrow
{
return _stdName;
}
/++
Typically, the abbreviation (generally 3 or 4 letters) for the time zone
when DST $(I is) in effect (e.g. PDT). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific
Daylight Time). Regardless, it is not the same as name.
+/
@property string dstName() const nothrow
{
return _dstName;
}
/++
Whether this time zone has Daylight Savings Time at any point in time.
Note that for some time zone types it may not have DST for current dates
but will still return true for $(D hasDST) because the time zone did at
some point have DST.
+/
@property abstract bool hasDST() const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and returns whether DST is effect in this
time zone at the given point in time.
Params:
stdTime = The UTC time that needs to be checked for DST in this time
zone.
+/
abstract bool dstInEffect(long stdTime) const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and converts it to this time zone's time.
Params:
stdTime = The UTC time that needs to be adjusted to this time zone's
time.
+/
abstract long utcToTZ(long stdTime) const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in this time zone's time and converts it to UTC (i.e. std time).
Params:
adjTime = The time in this time zone that needs to be adjusted to
UTC time.
+/
abstract long tzToUTC(long adjTime) const nothrow;
/++
Returns what the offset from UTC is at the given std time.
It includes the DST offset in effect at that time (if any).
Params:
stdTime = The UTC time for which to get the offset from UTC for this
time zone.
+/
Duration utcOffsetAt(long stdTime) const nothrow
{
return dur!"hnsecs"(utcToTZ(stdTime) - stdTime);
}
/++
Returns a $(D TimeZone) with the give name per the TZ Database.
This returns a $(D PosixTimeZone) on Posix systems and a
$(D WindowsTimeZone) on Windows systems. For
$(D PosixTimeZone) on Windows, call $(D PosixTimeZone.getTimeZone)
directly and give it the location of the TZ Database time zone files on
disk.
On Windows, the given TZ Database name is converted to the corresponding
time zone name on Windows prior to calling
$(D WindowsTimeZone.getTimeZone). This function allows for
the same time zone names on both Windows and Posix systems.
See_Also:
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ
Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List of
Time Zones)<br>
$(WEB unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html,
Windows <-> TZ Database Name Conversion Table)
Params:
name = The TZ Database name of the desired time zone
Throws:
$(D DateTimeException) if the given time zone could not be found.
Examples:
--------------------
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
--------------------
+/
static immutable(TimeZone) getTimeZone(string name)
{
version(Posix)
return PosixTimeZone.getTimeZone(name);
else version(Windows)
return WindowsTimeZone.getTimeZone(tzDatabaseNameToWindowsTZName(name));
}
//Since reading in the time zone files could be expensive, most unit tests
//are consolidated into this one unittest block which minimizes how often it
//reads a time zone file.
version(testStdDateTime) unittest
{
version(Posix) scope(exit) clearTZEnvVar();
static immutable(TimeZone) testTZ(string tzName,
string stdName,
string dstName,
Duration utcOffset,
Duration dstOffset,
bool north = true)
{
scope(failure) writefln("Failed time zone: %s", tzName);
immutable tz = TimeZone.getTimeZone(tzName);
immutable hasDST = dstOffset != dur!"hnsecs"(0);
version(Posix)
_assertPred!"=="(tz.name, tzName);
else version(Windows)
_assertPred!"=="(tz.name, stdName);
//_assertPred!"=="(tz.stdName, stdName); //Locale-dependent
//_assertPred!"=="(tz.dstName, dstName); //Locale-dependent
_assertPred!"=="(tz.hasDST, hasDST);
immutable stdDate = DateTime(2010, north ? 1 : 7, 1, 6, 0, 0);
immutable dstDate = DateTime(2010, north ? 7 : 1, 1, 6, 0, 0);
auto std = SysTime(stdDate, tz);
auto dst = SysTime(dstDate, tz);
auto stdUTC = SysTime(stdDate - utcOffset, UTC());
auto dstUTC = SysTime(stdDate - utcOffset + dstOffset, UTC());
assert(!std.dstInEffect);
_assertPred!"=="(dst.dstInEffect, hasDST);
_assertPred!"=="(tz.utcOffsetAt(std.stdTime), utcOffset);
_assertPred!"=="(tz.utcOffsetAt(dst.stdTime), utcOffset + dstOffset);
_assertPred!"=="(cast(DateTime)std, stdDate);
_assertPred!"=="(cast(DateTime)dst, dstDate);
_assertPred!"=="(std, stdUTC);
version(Posix)
{
setTZEnvVar(tzName);
static void testTM(in SysTime st)
{
time_t unixTime = st.toUnixTime();
tm* osTimeInfo = localtime(&unixTime);
tm ourTimeInfo = st.toTM();
_assertPred!"=="(ourTimeInfo.tm_sec, osTimeInfo.tm_sec);
_assertPred!"=="(ourTimeInfo.tm_min, osTimeInfo.tm_min);
_assertPred!"=="(ourTimeInfo.tm_hour, osTimeInfo.tm_hour);
_assertPred!"=="(ourTimeInfo.tm_mday, osTimeInfo.tm_mday);
_assertPred!"=="(ourTimeInfo.tm_mon, osTimeInfo.tm_mon);
_assertPred!"=="(ourTimeInfo.tm_year, osTimeInfo.tm_year);
_assertPred!"=="(ourTimeInfo.tm_wday, osTimeInfo.tm_wday);
_assertPred!"=="(ourTimeInfo.tm_yday, osTimeInfo.tm_yday);
_assertPred!"=="(ourTimeInfo.tm_isdst, osTimeInfo.tm_isdst);
_assertPred!"=="(ourTimeInfo.tm_gmtoff, osTimeInfo.tm_gmtoff);
_assertPred!"=="(to!string(ourTimeInfo.tm_zone),
to!string(osTimeInfo.tm_zone));
}
testTM(std);
testTM(dst);
//Apparently, right/ does not exist on Mac OS X. I don't know
//whether or not it exists on FreeBSD. It's rather pointless
//normally, since the Posix standard requires that leap seconds
//be ignored, so it does make some sense that right/ wouldn't
//be there, but since PosixTimeZone _does_ use leap seconds if
//the time zone file does, we'll test that functionality if the
//appropriate files exist.
if((PosixTimeZone.defaultTZDatabaseDir ~ "right/" ~ tzName).exists())
{
auto leapTZ = PosixTimeZone.getTimeZone("right/" ~ tzName);
assert(leapTZ.name == "right/" ~ tzName);
//assert(leapTZ.stdName == stdName); //Locale-dependent
//assert(leapTZ.dstName == dstName); //Locale-dependent
assert(leapTZ.hasDST == hasDST);
auto leapSTD = SysTime(std.stdTime, leapTZ);
auto leapDST = SysTime(dst.stdTime, leapTZ);
assert(!leapSTD.dstInEffect);
assert(leapDST.dstInEffect == hasDST);
_assertPred!"=="(leapSTD.stdTime, std.stdTime);
_assertPred!"=="(leapDST.stdTime, dst.stdTime);
//Whenever a leap second is added/removed,
//this will have to be adjusted.
//enum leapDiff = convert!("seconds", "hnsecs")(25);
//_assertPred!"=="(leapSTD.adjTime - leapDiff, std.adjTime);
//_assertPred!"=="(leapDST.adjTime - leapDiff, dst.adjTime);
}
}
return tz;
}
auto dstSwitches = [/+America/Los_Angeles+/ tuple(DateTime(2012, 3, 11), DateTime(2012, 11, 4), 2, 2),
/+America/New_York+/ tuple(DateTime(2012, 3, 11), DateTime(2012, 11, 4), 2, 2),
///+America/Santiago+/ tuple(DateTime(2011, 8, 21), DateTime(2011, 5, 8), 0, 0),
/+Europe/London+/ tuple(DateTime(2012, 3, 25), DateTime(2012, 10, 28), 1, 2),
/+Europe/Paris+/ tuple(DateTime(2012, 3, 25), DateTime(2012, 10, 28), 2, 3),
/+Australia/Adelaide+/ tuple(DateTime(2012, 10, 7), DateTime(2012, 4, 1), 2, 3)];
version(Posix)
{
version(FreeBSD) enum utcZone = "Etc/UTC";
version(linux) enum utcZone = "UTC";
version(OSX) enum utcZone = "UTC";
auto tzs = [testTZ("America/Los_Angeles", "PST", "PDT", dur!"hours"(-8), dur!"hours"(1)),
testTZ("America/New_York", "EST", "EDT", dur!"hours"(-5), dur!"hours"(1)),
//testTZ("America/Santiago", "CLT", "CLST", dur!"hours"(-4), dur!"hours"(1), false),
testTZ("Europe/London", "GMT", "BST", dur!"hours"(0), dur!"hours"(1)),
testTZ("Europe/Paris", "CET", "CEST", dur!"hours"(1), dur!"hours"(1)),
//Per www.timeanddate.com, it should be "CST" and "CDT",
//but the OS insists that it's "CST" for both. We should
//probably figure out how to report an error in the TZ
//database and report it.
testTZ("Australia/Adelaide", "CST", "CST",
dur!"hours"(9) + dur!"minutes"(30), dur!"hours"(1), false)];
testTZ(utcZone, "UTC", "UTC", dur!"hours"(0), dur!"hours"(0));
assertThrown!DateTimeException(PosixTimeZone.getTimeZone("hello_world"));
}
else version(Windows)
{
auto tzs = [testTZ("America/Los_Angeles", "Pacific Standard Time",
"Pacific Daylight Time", dur!"hours"(-8), dur!"hours"(1)),
testTZ("America/New_York", "Eastern Standard Time",
"Eastern Daylight Time", dur!"hours"(-5), dur!"hours"(1)),
//testTZ("America/Santiago", "Pacific SA Standard Time",
//"Pacific SA Daylight Time", dur!"hours"(-4), dur!"hours"(1), false),
testTZ("Europe/London", "GMT Standard Time",
"GMT Daylight Time", dur!"hours"(0), dur!"hours"(1)),
testTZ("Europe/Paris", "Romance Standard Time",
"Romance Daylight Time", dur!"hours"(1), dur!"hours"(1)),
testTZ("Australia/Adelaide", "Cen. Australia Standard Time",
"Cen. Australia Daylight Time",
dur!"hours"(9) + dur!"minutes"(30), dur!"hours"(1), false)];
testTZ("Atlantic/Reykjavik", "Greenwich Standard Time",
"Greenwich Daylight Time", dur!"hours"(0), dur!"hours"(0));
assertThrown!DateTimeException(WindowsTimeZone.getTimeZone("hello_world"));
}
else
assert(0, "OS not supported.");
foreach(i; 0 .. tzs.length)
{
auto tz = tzs[i];
immutable spring = dstSwitches[i][2];
immutable fall = dstSwitches[i][3];
auto stdOffset = SysTime(dstSwitches[i][0] + dur!"days"(-1), tz).utcOffset;
auto dstOffset = stdOffset + dur!"hours"(1);
//Verify that creating a SysTime in the given time zone results
//in a SysTime with the correct std time during and surrounding
//a DST switch.
foreach(hour; -12 .. 13)
{
auto st = SysTime(dstSwitches[i][0] + dur!"hours"(hour), tz);
immutable targetHour = hour < 0 ? hour + 24 : hour;
static void testHour(SysTime st, int hour, string tzName, size_t line = __LINE__)
{
enforce(st.hour == hour,
new AssertError(format("[%s] [%s]: [%s] [%s]", st, tzName, st.hour, hour),
__FILE__, line));
}
void testOffset1(Duration offset, bool dstInEffect, size_t line = __LINE__)
{
AssertError msg(string tag)
{
return new AssertError(format("%s [%s] [%s]: [%s] [%s] [%s]",
tag, st, tz.name, st.utcOffset, stdOffset, dstOffset),
__FILE__, line);
}
enforce(st.dstInEffect == dstInEffect, msg("1"));
enforce(st.utcOffset == offset, msg("2"));
enforce((st + dur!"minutes"(1)).utcOffset == offset, msg("3"));
}
if(hour == spring)
{
testHour(st, spring + 1, tz.name);
testHour(st + dur!"minutes"(1), spring + 1, tz.name);
}
else
{
testHour(st, targetHour, tz.name);
testHour(st + dur!"minutes"(1), targetHour, tz.name);
}
if(hour < spring)
testOffset1(stdOffset, false);
else
testOffset1(dstOffset, true);
st = SysTime(dstSwitches[i][1] + dur!"hours"(hour), tz);
testHour(st, targetHour, tz.name);
//Verify that 01:00 is the first 01:00 (or whatever hour before the switch is).
if(hour == fall - 1)
testHour(st + dur!"hours"(1), targetHour, tz.name);
if(hour < fall)
testOffset1(dstOffset, true);
else
testOffset1(stdOffset, false);
}
//Verify that converting a time in UTC to a time in another
//time zone results in the correct time during and surrounding
//a DST switch.
bool first = true;
auto springSwitch = SysTime(dstSwitches[i][0] + dur!"hours"(spring), UTC()) - stdOffset;
auto fallSwitch = SysTime(dstSwitches[i][1] + dur!"hours"(fall), UTC()) - dstOffset;
//@@@BUG@@@ 3659 makes this necessary.
auto fallSwitchMinus1 = fallSwitch - dur!"hours"(1);
foreach(hour; -24 .. 25)
{
auto utc = SysTime(dstSwitches[i][0] + dur!"hours"(hour), UTC());
auto local = utc.toOtherTZ(tz);
void testOffset2(Duration offset, size_t line = __LINE__)
{
AssertError msg(string tag)
{
return new AssertError(format("%s [%s] [%s]: [%s] [%s]", tag, hour, tz.name, utc, local),
__FILE__, line);
}
enforce((utc + offset).hour == local.hour, msg("1"));
enforce((utc + offset + dur!"minutes"(1)).hour == local.hour, msg("2"));
}
if(utc < springSwitch)
testOffset2(stdOffset);
else
testOffset2(dstOffset);
utc = SysTime(dstSwitches[i][1] + dur!"hours"(hour), UTC());
local = utc.toOtherTZ(tz);
if(utc == fallSwitch || utc == fallSwitchMinus1)
{
if(first)
{
testOffset2(dstOffset);
first = false;
}
else
testOffset2(stdOffset);
}
else if(utc > fallSwitch)
testOffset2(stdOffset);
else
testOffset2(dstOffset);
}
}
}
/++
Returns a list of the names of the time zones installed on the system.
Providing a sub-name narrows down the list of time zones (which
can number in the thousands). For example,
passing in "America" as the sub-name returns only the time zones which
begin with "America".
On Windows, this function will convert the Windows time zone names to
the corresponding TZ Database names with
$(D windowsTZNameToTZDatabaseName). To get the actual Windows time
zone names, use $(D WindowsTimeZone.getInstalledTZNames) directly.
Params:
subName = The first part of the time zones desired.
Throws:
$(D FileException) on Posix systems if it fails to read from disk.
$(D DateTimeException) on Windows systems if it fails to read the
registry.
+/
static string[] getInstalledTZNames(string subName = "")
{
version(Posix)
return PosixTimeZone.getInstalledTZNames(subName);
else version(Windows)
{
auto windowsNames = WindowsTimeZone.getInstalledTZNames();
auto retval = appender!(string[])();
foreach(winName; windowsNames)
{
auto tzName = windowsTZNameToTZDatabaseName(winName);
if(tzName.startsWith(subName))
retval.put(tzName);
}
sort(retval.data);
return retval.data;
}
}
unittest
{
version(testStdDateTime)
{
static void testPZSuccess(string tzName)
{
scope(failure) writefln("TZName which threw: %s", tzName);
TimeZone.getTimeZone(tzName);
}
auto tzNames = getInstalledTZNames();
foreach(tzName; tzNames)
assertNotThrown!DateTimeException(testPZSuccess(tzName));
}
}
private:
/+
Params:
name = The TZ Database name for the time zone.
stdName = The abbreviation for the time zone during std time.
dstName = The abbreviation for the time zone during DST.
+/
this(string name, string stdName, string dstName) immutable pure
{
_name = name;
_stdName = stdName;
_dstName = dstName;
}
immutable string _name;
immutable string _stdName;
immutable string _dstName;
}
/++
A TimeZone which represents the current local time zone on
the system running your program.
This uses the underlying C calls to adjust the time rather than using
specific D code based off of system settings to calculate the time such as
$(D PosixTimeZone) and $(D WindowsTimeZone) do. That also means that it will
use whatever the current time zone is on the system, even if the system's
time zone changes while the program is running.
+/
final class LocalTime : TimeZone
{
public:
/++
$(D LocalTime) is a singleton class. $(D LocalTime) returns its only
instance.
+/
static immutable(LocalTime) opCall() pure nothrow
{
alias pure nothrow immutable(LocalTime) function() FuncType;
return (cast(FuncType)&singleton)();
}
version(StdDdoc)
{
/++
The name of the time zone per the TZ Database. This is the name used to
get a $(D TimeZone) by name with $(D TimeZone.getTimeZone).
Note that this always returns the empty string. This is because time
zones cannot be uniquely identified by the attributes given by the
OS (such as the $(D stdName) and $(D dstName)), and neither Posix
systems nor Windows systems provide an easy way to get the TZ
Database name of the local time zone.
See_Also:
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ
Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List
of Time Zones)
+/
@property override string name() const nothrow;
}
/++
Typically, the abbreviation (generally 3 or 4 letters) for the time zone
when DST is $(I not) in effect (e.g. PST). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific
Standard Time). Regardless, it is not the same as name.
This property is overridden because the local time of the system could
change while the program is running and we need to determine it
dynamically rather than it being fixed like it would be with most time
zones.
+/
@property override string stdName() const nothrow
{
version(Posix)
{
try
return to!string(tzname[0]);
catch(Exception e)
assert(0, "to!string(tzname[0]) failed.");
}
else version(Windows)
{
try
{
TIME_ZONE_INFORMATION tzInfo;
GetTimeZoneInformation(&tzInfo);
//Cannot use to!string() like this should, probably due to bug http://d.puremagic.com/issues/show_bug.cgi?id=5016
//return to!string(tzInfo.StandardName);
wchar[32] str;
foreach(i, ref wchar c; str)
c = tzInfo.StandardName[i];
string retval;
foreach(dchar c; str)
{
if(c == '\0')
break;
retval ~= c;
}
return retval;
}
catch(Exception e)
assert(0, "GetTimeZoneInformation() threw.");
}
}
unittest
{
version(testStdDateTime)
{
assert(LocalTime().stdName !is null);
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("America/Los_Angeles");
_assertPred!"=="(LocalTime().stdName, "PST");
setTZEnvVar("America/New_York");
_assertPred!"=="(LocalTime().stdName, "EST");
}
}
}
/++
Typically, the abbreviation (generally 3 or 4 letters) for the time zone
when DST $(I is) in effect (e.g. PDT). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific
Daylight Time). Regardless, it is not the same as name.
This property is overridden because the local time of the system could
change while the program is running and we need to determine it
dynamically rather than it being fixed like it would be with most time
zones.
+/
@property override string dstName() const nothrow
{
version(Posix)
{
try
return to!string(tzname[1]);
catch(Exception e)
assert(0, "to!string(tzname[1]) failed.");
}
else version(Windows)
{
try
{
TIME_ZONE_INFORMATION tzInfo;
GetTimeZoneInformation(&tzInfo);
//Cannot use to!string() like this should, probably due to bug http://d.puremagic.com/issues/show_bug.cgi?id=5016
//return to!string(tzInfo.DaylightName);
wchar[32] str;
foreach(i, ref wchar c; str)
c = tzInfo.DaylightName[i];
string retval;
foreach(dchar c; str)
{
if(c == '\0')
break;
retval ~= c;
}
return retval;
}
catch(Exception e)
assert(0, "GetTimeZoneInformation() threw.");
}
}
unittest
{
version(testStdDateTime)
{
assert(LocalTime().dstName !is null);
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("America/Los_Angeles");
_assertPred!"=="(LocalTime().dstName, "PDT");
setTZEnvVar("America/New_York");
_assertPred!"=="(LocalTime().dstName, "EDT");
}
}
}
/++
Whether this time zone has Daylight Savings Time at any point in time.
Note that for some time zone types it may not have DST for current
dates but will still return true for $(D hasDST) because the time zone
did at some point have DST.
+/
@property override bool hasDST() const nothrow
{
version(Posix)
{
static if(is(typeof(daylight)))
return cast(bool)(daylight);
else
{
try
{
auto currYear = (cast(Date)Clock.currTime()).year;
auto janOffset = SysTime(Date(currYear, 1, 4), this).stdTime -
SysTime(Date(currYear, 1, 4), UTC()).stdTime;
auto julyOffset = SysTime(Date(currYear, 7, 4), this).stdTime -
SysTime(Date(currYear, 7, 4), UTC()).stdTime;
return janOffset != julyOffset;
}
catch(Exception e)
assert(0, "Clock.currTime() threw.");
}
}
else version(Windows)
{
try
{
TIME_ZONE_INFORMATION tzInfo;
GetTimeZoneInformation(&tzInfo);
return tzInfo.DaylightDate.wMonth != 0;
}
catch(Exception e)
assert(0, "GetTimeZoneInformation() threw.");
}
}
unittest
{
version(testStdDateTime)
{
LocalTime().hasDST;
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("America/Los_Angeles");
assert(LocalTime().hasDST);
setTZEnvVar("America/New_York");
assert(LocalTime().hasDST);
setTZEnvVar("UTC");
assert(!LocalTime().hasDST);
}
}
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and returns whether DST is in effect in this
time zone at the given point in time.
Params:
stdTime = The UTC time that needs to be checked for DST in this time
zone.
+/
override bool dstInEffect(long stdTime) const nothrow
{
time_t unixTime = stdTimeToUnixTime(stdTime);
version(Posix)
{
tm* timeInfo = localtime(&unixTime);
return cast(bool)(timeInfo.tm_isdst);
}
else version(Windows)
{
//Apparently Windows isn't smart enough to deal with negative time_t.
if(unixTime >= 0)
{
tm* timeInfo = localtime(&unixTime);
if(timeInfo)
return cast(bool)(timeInfo.tm_isdst);
}
TIME_ZONE_INFORMATION tzInfo;
try
GetTimeZoneInformation(&tzInfo);
catch(Exception e)
assert(0, "The impossible happened. GetTimeZoneInformation() threw.");
return WindowsTimeZone._dstInEffect(&tzInfo, stdTime);
}
}
unittest
{
version(testStdDateTime)
{
auto currTime = Clock.currStdTime;
LocalTime().dstInEffect(currTime);
}
}
/++
Returns hnsecs in the local time zone using the standard C function
calls on Posix systems and the standard Windows system calls on Windows
systems to adjust the time to the appropriate time zone from std time.
Params:
stdTime = The UTC time that needs to be adjusted to this time zone's
time.
See_Also:
$(D TimeZone.utcToTZ)
+/
override long utcToTZ(long stdTime) const nothrow
{
version(Posix)
{
time_t unixTime = stdTimeToUnixTime(stdTime);
tm* timeInfo = localtime(&unixTime);
return stdTime + convert!("seconds", "hnsecs")(timeInfo.tm_gmtoff);
}
else version(Windows)
{
TIME_ZONE_INFORMATION tzInfo;
try
GetTimeZoneInformation(&tzInfo);
catch(Exception e)
assert(0, "GetTimeZoneInformation() threw.");
return WindowsTimeZone._utcToTZ(&tzInfo, stdTime, hasDST);
}
}
unittest
{
version(testStdDateTime)
{
LocalTime().utcToTZ(0);
}
}
/++
Returns std time using the standard C function calls on Posix systems
and the standard Windows system calls on Windows systems to adjust the
time to UTC from the appropriate time zone.
See_Also:
$(D TimeZone.tzToUTC)
Params:
adjTime = The time in this time zone that needs to be adjusted to
UTC time.
+/
override long tzToUTC(long adjTime) const nothrow
{
version(Posix)
{
time_t unixTime = stdTimeToUnixTime(adjTime);
immutable past = unixTime - cast(time_t)convert!("days", "seconds")(1);
tm* timeInfo = localtime(past < unixTime ? &past : &unixTime);
immutable pastOffset = timeInfo.tm_gmtoff;
immutable future = unixTime + cast(time_t)convert!("days", "seconds")(1);
timeInfo = localtime(future > unixTime ? &future : &unixTime);
immutable futureOffset = timeInfo.tm_gmtoff;
if(pastOffset == futureOffset)
return adjTime - convert!("seconds", "hnsecs")(pastOffset);
if(pastOffset < futureOffset)
unixTime -= cast(time_t)convert!("hours", "seconds")(1);
unixTime -= pastOffset;
timeInfo = localtime(&unixTime);
return adjTime - convert!("seconds", "hnsecs")(timeInfo.tm_gmtoff);
}
else version(Windows)
{
TIME_ZONE_INFORMATION tzInfo;
try
GetTimeZoneInformation(&tzInfo);
catch(Exception e)
assert(0, "GetTimeZoneInformation() threw.");
return WindowsTimeZone._tzToUTC(&tzInfo, adjTime, hasDST);
}
}
unittest
{
version(testStdDateTime)
{
assert(LocalTime().tzToUTC(LocalTime().utcToTZ(0)) == 0);
assert(LocalTime().utcToTZ(LocalTime().tzToUTC(0)) == 0);
_assertPred!"=="(LocalTime().tzToUTC(LocalTime().utcToTZ(0)), 0);
_assertPred!"=="(LocalTime().utcToTZ(LocalTime().tzToUTC(0)), 0);
version(Posix)
{
scope(exit) clearTZEnvVar();
auto tzInfos = [tuple("America/Los_Angeles", DateTime(2012, 3, 11), DateTime(2012, 11, 4), 2, 2),
tuple("America/New_York", DateTime(2012, 3, 11), DateTime(2012, 11, 4), 2, 2),
//tuple("America/Santiago", DateTime(2011, 8, 21), DateTime(2011, 5, 8), 0, 0),
tuple("Atlantic/Azores", DateTime(2011, 3, 27), DateTime(2011, 10, 30), 0, 1),
tuple("Europe/London", DateTime(2012, 3, 25), DateTime(2012, 10, 28), 1, 2),
tuple("Europe/Paris", DateTime(2012, 3, 25), DateTime(2012, 10, 28), 2, 3),
tuple("Australia/Adelaide", DateTime(2012, 10, 7), DateTime(2012, 4, 1), 2, 3)];
foreach(i; 0 .. tzInfos.length)
{
auto tzName = tzInfos[i][0];
setTZEnvVar(tzName);
immutable spring = tzInfos[i][3];
immutable fall = tzInfos[i][4];
auto stdOffset = SysTime(tzInfos[i][1] + dur!"hours"(-12)).utcOffset;
auto dstOffset = stdOffset + dur!"hours"(1);
//Verify that creating a SysTime in the given time zone results
//in a SysTime with the correct std time during and surrounding
//a DST switch.
foreach(hour; -12 .. 13)
{
auto st = SysTime(tzInfos[i][1] + dur!"hours"(hour));
immutable targetHour = hour < 0 ? hour + 24 : hour;
static void testHour(SysTime st, int hour, string tzName, size_t line = __LINE__)
{
enforce(st.hour == hour,
new AssertError(format("[%s] [%s]: [%s] [%s]", st, tzName, st.hour, hour),
__FILE__, line));
}
void testOffset1(Duration offset, bool dstInEffect, size_t line = __LINE__)
{
AssertError msg(string tag)
{
return new AssertError(format("%s [%s] [%s]: [%s] [%s] [%s]",
tag, st, tzName, st.utcOffset, stdOffset, dstOffset),
__FILE__, line);
}
enforce(st.dstInEffect == dstInEffect, msg("1"));
enforce(st.utcOffset == offset, msg("2"));
enforce((st + dur!"minutes"(1)).utcOffset == offset, msg("3"));
}
if(hour == spring)
{
testHour(st, spring + 1, tzName);
testHour(st + dur!"minutes"(1), spring + 1, tzName);
}
else
{
testHour(st, targetHour, tzName);
testHour(st + dur!"minutes"(1), targetHour, tzName);
}
if(hour < spring)
testOffset1(stdOffset, false);
else
testOffset1(dstOffset, true);
st = SysTime(tzInfos[i][2] + dur!"hours"(hour));
testHour(st, targetHour, tzName);
//Verify that 01:00 is the first 01:00 (or whatever hour before the switch is).
if(hour == fall - 1)
testHour(st + dur!"hours"(1), targetHour, tzName);
if(hour < fall)
testOffset1(dstOffset, true);
else
testOffset1(stdOffset, false);
}
//Verify that converting a time in UTC to a time in another
//time zone results in the correct time during and surrounding
//a DST switch.
bool first = true;
auto springSwitch = SysTime(tzInfos[i][1] + dur!"hours"(spring), UTC()) - stdOffset;
auto fallSwitch = SysTime(tzInfos[i][2] + dur!"hours"(fall), UTC()) - dstOffset;
//@@@BUG@@@ 3659 makes this necessary.
auto fallSwitchMinus1 = fallSwitch - dur!"hours"(1);
foreach(hour; -24 .. 25)
{
auto utc = SysTime(tzInfos[i][1] + dur!"hours"(hour), UTC());
auto local = utc.toLocalTime();
void testOffset2(Duration offset, size_t line = __LINE__)
{
AssertError msg(string tag)
{
return new AssertError(format("%s [%s] [%s]: [%s] [%s]", tag, hour, tzName, utc, local),
__FILE__, line);
}
enforce((utc + offset).hour == local.hour, msg("1"));
enforce((utc + offset + dur!"minutes"(1)).hour == local.hour, msg("2"));
}
if(utc < springSwitch)
testOffset2(stdOffset);
else
testOffset2(dstOffset);
utc = SysTime(tzInfos[i][2] + dur!"hours"(hour), UTC());
local = utc.toLocalTime();
if(utc == fallSwitch || utc == fallSwitchMinus1)
{
if(first)
{
testOffset2(dstOffset);
first = false;
}
else
testOffset2(stdOffset);
}
else if(utc > fallSwitch)
testOffset2(stdOffset);
else
testOffset2(dstOffset);
}
}
}
}
}
private:
this() immutable
{
super("", "", "");
tzset();
}
static shared LocalTime _localTime;
static bool _initialized;
static immutable(LocalTime) singleton()
{
//TODO Make this use double-checked locking once shared has been fixed
//to use memory fences properly.
if(!_initialized)
{
synchronized
{
if(!_localTime)
_localTime = cast(shared LocalTime)new immutable(LocalTime)();
}
_initialized = true;
}
return cast(immutable LocalTime)_localTime;
}
}
/++
A $(D TimeZone) which represents UTC.
+/
final class UTC : TimeZone
{
public:
/++
$(D UTC) is a singleton class. $(D UTC) returns its only instance.
+/
static immutable(UTC) opCall() pure nothrow
{
alias pure nothrow immutable(UTC) function() FuncType;
return (cast(FuncType)&singleton)();
}
/++
Always returns false.
+/
@property override bool hasDST() const nothrow
{
return false;
}
/++
Always returns false.
+/
override bool dstInEffect(long stdTime) const nothrow
{
return false;
}
/++
Returns the given hnsecs without changing them at all.
Params:
stdTime = The UTC time that needs to be adjusted to this time zone's
time.
See_Also:
$(D TimeZone.utcToTZ)
+/
override long utcToTZ(long stdTime) const nothrow
{
return stdTime;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(UTC().utcToTZ(0), 0);
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("UTC");
auto std = SysTime(Date(2010, 1, 1));
auto dst = SysTime(Date(2010, 7, 1));
_assertPred!"=="(UTC().utcToTZ(std.stdTime), std.stdTime);
_assertPred!"=="(UTC().utcToTZ(dst.stdTime), dst.stdTime);
}
}
}
/++
Returns the given hnsecs without changing them at all.
See_Also:
$(D TimeZone.tzToUTC)
Params:
adjTime = The time in this time zone that needs to be adjusted to
UTC time.
+/
override long tzToUTC(long adjTime) const nothrow
{
return adjTime;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(UTC().tzToUTC(0), 0);
version(Posix)
{
scope(exit) clearTZEnvVar();
setTZEnvVar("UTC");
auto std = SysTime(Date(2010, 1, 1));
auto dst = SysTime(Date(2010, 7, 1));
_assertPred!"=="(UTC().tzToUTC(std.stdTime), std.stdTime);
_assertPred!"=="(UTC().tzToUTC(dst.stdTime), dst.stdTime);
}
}
}
/++
Returns a $(CXREF time, Duration) of 0.
Params:
stdTime = The UTC time for which to get the offset from UTC for this
time zone.
+/
override Duration utcOffsetAt(long stdTime) const nothrow
{
return dur!"hnsecs"(0);
}
private:
this() immutable pure
{
super("UTC", "UTC", "UTC");
}
static shared UTC _utc;
static bool _initialized;
static immutable(UTC) singleton()
{
//TODO Make this use double-checked locking once shared has been fixed
//to use memory fences properly.
if(!_initialized)
{
synchronized
{
if(!_utc)
_utc = cast(shared UTC)new immutable(UTC)();
}
_initialized = true;
}
return cast(immutable UTC)_utc;
}
}
/++
Represents a time zone with an offset (in minutes, west is negative) from
UTC but no DST.
It's primarily used as the time zone in the result of $(D SysTime)'s
$(D fromISOString), $(D fromISOExtString), and $(D fromSimpleString).
$(D name) and $(D dstName) are always the empty string since this time zone
has no DST, and while it may be meant to represent a time zone which is in
the TZ Database, obviously it's not likely to be following the exact rules
of any of the time zones in the TZ Database, so it makes no sense to set it.
+/
final class SimpleTimeZone : TimeZone
{
public:
/++
Always returns false.
+/
@property override bool hasDST() const nothrow
{
return false;
}
/++
Always returns false.
+/
override bool dstInEffect(long stdTime) const nothrow
{
return false;
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and converts it to this time zone's time.
Params:
stdTime = The UTC time that needs to be adjusted to this time zone's
time.
+/
override long utcToTZ(long stdTime) const nothrow
{
return stdTime + _utcOffset.total!"hnsecs";
}
version(testStdDateTime) unittest
{
auto west = new SimpleTimeZone(dur!"hours"(-8));
auto east = new SimpleTimeZone(dur!"hours"(8));
assert(west.utcToTZ(0) == -288_000_000_000L);
assert(east.utcToTZ(0) == 288_000_000_000L);
assert(west.utcToTZ(54_321_234_567_890L) == 54_033_234_567_890L);
const cstz = west;
static assert(__traits(compiles, west.utcToTZ(50002)));
static assert(__traits(compiles, cstz.utcToTZ(50002)));
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in this time zone's time and converts it to UTC (i.e. std time).
Params:
adjTime = The time in this time zone that needs to be adjusted to
UTC time.
+/
override long tzToUTC(long adjTime) const nothrow
{
return adjTime - _utcOffset.total!"hnsecs";
}
version(testStdDateTime) unittest
{
auto west = new SimpleTimeZone(dur!"hours"(-8));
auto east = new SimpleTimeZone(dur!"hours"(8));
assert(west.tzToUTC(-288_000_000_000L) == 0);
assert(east.tzToUTC(288_000_000_000L) == 0);
assert(west.tzToUTC(54_033_234_567_890L) == 54_321_234_567_890L);
const cstz = west;
static assert(__traits(compiles, west.tzToUTC(20005)));
static assert(__traits(compiles, cstz.tzToUTC(20005)));
}
/++
Returns utcOffset as a $(CXREF time, Duration).
Params:
stdTime = The UTC time for which to get the offset from UTC for this
time zone.
+/
override Duration utcOffsetAt(long stdTime) const nothrow
{
return _utcOffset;
}
/++
Params:
utcOffset = This time zone's offset from UTC in minutes with west of
UTC being negative (it is added to UTC to get the
adjusted time).
stdName = The $(D stdName) for this time zone.
+/
this(Duration utcOffset, string stdName = "") immutable
{
//FIXME This probably needs to be changed to something like (-12 - 13).
enforceEx!DateTimeException(abs(utcOffset) < dur!"minutes"(1440),
"Offset from UTC must be within range (-24:00 - 24:00).");
super("", stdName, "");
this._utcOffset = utcOffset;
}
/++ Ditto +/
this(int utcOffset, string stdName = "") immutable
{
this(dur!"minutes"(utcOffset), stdName);
}
version(testStdDateTime) unittest
{
foreach(stz; [new SimpleTimeZone(dur!"hours"(-8), "PST"),
new SimpleTimeZone(-8 * 60, "PST")])
{
assert(stz.name == "");
assert(stz.stdName == "PST");
assert(stz.dstName == "");
assert(stz.utcOffset == -8 * 60);
}
}
/++
The number of minutes the offset from UTC is (negative is west of UTC,
positive is east).
+/
@property int utcOffset() @safe const pure nothrow
{
return cast(int)_utcOffset.total!"minutes";
}
private:
/+
Returns a time zone as a string with an offset from UTC.
Time zone offsets will be in the form +HH:MM or -HH:MM.
Params:
utcOffset = The number of minutes offset from UTC (negative means
west).
+/
static string toISOString(Duration utcOffset)
{
immutable absOffset = abs(utcOffset);
enforceEx!DateTimeException(absOffset < dur!"minutes"(1440),
"Offset from UTC must be within range (-24:00 - 24:00).");
if(utcOffset < Duration.zero)
return format("-%02d:%02d", absOffset.hours, absOffset.minutes);
return format("+%02d:%02d", absOffset.hours, absOffset.minutes);
}
version(testStdDateTime) unittest
{
static string testSTZInvalid(Duration offset)
{
return SimpleTimeZone.toISOString(offset);
}
assertThrown!DateTimeException(testSTZInvalid(dur!"minutes"(1440)));
assertThrown!DateTimeException(testSTZInvalid(dur!"minutes"(-1440)));
assert(toISOString(dur!"minutes"(0)) == "+00:00");
assert(toISOString(dur!"minutes"(1)) == "+00:01");
assert(toISOString(dur!"minutes"(10)) == "+00:10");
assert(toISOString(dur!"minutes"(59)) == "+00:59");
assert(toISOString(dur!"minutes"(60)) == "+01:00");
assert(toISOString(dur!"minutes"(90)) == "+01:30");
assert(toISOString(dur!"minutes"(120)) == "+02:00");
assert(toISOString(dur!"minutes"(480)) == "+08:00");
assert(toISOString(dur!"minutes"(1439)) == "+23:59");
assert(toISOString(dur!"minutes"(-1)) == "-00:01");
assert(toISOString(dur!"minutes"(-10)) == "-00:10");
assert(toISOString(dur!"minutes"(-59)) == "-00:59");
assert(toISOString(dur!"minutes"(-60)) == "-01:00");
assert(toISOString(dur!"minutes"(-90)) == "-01:30");
assert(toISOString(dur!"minutes"(-120)) == "-02:00");
assert(toISOString(dur!"minutes"(-480)) == "-08:00");
assert(toISOString(dur!"minutes"(-1439)) == "-23:59");
}
/+
Takes a time zone as a string with an offset from UTC and returns a
$(LREF SimpleTimeZone) which matches.
The accepted formats for time zone offsets
are +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
Params:
isoString = A string which represents a time zone in the ISO format.
+/
static immutable(SimpleTimeZone) fromISOString(S)(S isoString)
if(isSomeString!S)
{
auto dstr = to!dstring(strip(isoString));
enforce(dstr.startsWith("-") || dstr.startsWith("+"), new DateTimeException("Invalid ISO String"));
auto sign = dstr.startsWith("-") ? -1 : 1;
dstr.popFront();
enforce(!dstr.empty, new DateTimeException("Invalid ISO String"));
immutable colon = dstr.stds_indexOf(":");
dstring hoursStr;
dstring minutesStr;
if(colon != -1)
{
hoursStr = dstr[0 .. colon];
minutesStr = dstr[colon + 1 .. $];
enforce(minutesStr.length == 2, new DateTimeException(format("Invalid ISO String: %s", dstr)));
}
else
hoursStr = dstr;
enforce(!canFind!(not!isDigit)(hoursStr), new DateTimeException(format("Invalid ISO String: %s", dstr)));
enforce(!canFind!(not!isDigit)(minutesStr), new DateTimeException(format("Invalid ISO String: %s", dstr)));
immutable hours = to!int(hoursStr);
immutable minutes = minutesStr.empty ? 0 : to!int(minutesStr);
return new SimpleTimeZone(sign * (dur!"hours"(hours) + dur!"minutes"(minutes)));
}
version(testStdDateTime) unittest
{
assertThrown!DateTimeException(SimpleTimeZone.fromISOString(""));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("Z"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("-"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("+"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("-:"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("+:"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("-1:"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("+1:"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("1"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("-24:00"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("+24:00"));
assertThrown!DateTimeException(SimpleTimeZone.fromISOString("+1:0"));
assert(SimpleTimeZone.fromISOString("+00:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(0))).utcOffset);
assert(SimpleTimeZone.fromISOString("+00:01").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(1))).utcOffset);
assert(SimpleTimeZone.fromISOString("+00:10").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(10))).utcOffset);
assert(SimpleTimeZone.fromISOString("+00:59").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(59))).utcOffset);
assert(SimpleTimeZone.fromISOString("+01:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(60))).utcOffset);
assert(SimpleTimeZone.fromISOString("+01:30").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(90))).utcOffset);
assert(SimpleTimeZone.fromISOString("+02:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(120))).utcOffset);
assert(SimpleTimeZone.fromISOString("+08:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(480))).utcOffset);
assert(SimpleTimeZone.fromISOString("+23:59").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(1439))).utcOffset);
assert(SimpleTimeZone.fromISOString("-00:01").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-1))).utcOffset);
assert(SimpleTimeZone.fromISOString("-00:10").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-10))).utcOffset);
assert(SimpleTimeZone.fromISOString("-00:59").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-59))).utcOffset);
assert(SimpleTimeZone.fromISOString("-01:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-60))).utcOffset);
assert(SimpleTimeZone.fromISOString("-01:30").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-90))).utcOffset);
assert(SimpleTimeZone.fromISOString("-02:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-120))).utcOffset);
assert(SimpleTimeZone.fromISOString("-08:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-480))).utcOffset);
assert(SimpleTimeZone.fromISOString("-23:59").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-1439))).utcOffset);
assert(SimpleTimeZone.fromISOString("+0").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(0))).utcOffset);
assert(SimpleTimeZone.fromISOString("+1").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(60))).utcOffset);
assert(SimpleTimeZone.fromISOString("+2").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(120))).utcOffset);
assert(SimpleTimeZone.fromISOString("+23").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(1380))).utcOffset);
assert(SimpleTimeZone.fromISOString("+2").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(120))).utcOffset);
assert(SimpleTimeZone.fromISOString("+0").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(0))).utcOffset);
assert(SimpleTimeZone.fromISOString("+1").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(60))).utcOffset);
assert(SimpleTimeZone.fromISOString("+2").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(120))).utcOffset);
assert(SimpleTimeZone.fromISOString("+23").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(1380))).utcOffset);
assert(SimpleTimeZone.fromISOString("+1:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(60))).utcOffset);
assert(SimpleTimeZone.fromISOString("+1:01").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(61))).utcOffset);
assert(SimpleTimeZone.fromISOString("-0").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(0))).utcOffset);
assert(SimpleTimeZone.fromISOString("-1").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-60))).utcOffset);
assert(SimpleTimeZone.fromISOString("-2").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-120))).utcOffset);
assert(SimpleTimeZone.fromISOString("-23").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-1380))).utcOffset);
assert(SimpleTimeZone.fromISOString("-1:00").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-60))).utcOffset);
assert(SimpleTimeZone.fromISOString("-1:01").utcOffset ==
(new SimpleTimeZone(dur!"minutes"(-61))).utcOffset);
}
//Test that converting from an ISO string to a SimpleTimeZone to an ISO String works properly.
version(testStdDateTime) unittest
{
static void testSTZ(in string isoString, int expectedOffset, size_t line = __LINE__)
{
auto stz = SimpleTimeZone.fromISOString(isoString);
_assertPred!"=="(stz.utcOffset, expectedOffset, "", __FILE__, line);
auto result = SimpleTimeZone.toISOString(dur!"minutes"(stz.utcOffset));
_assertPred!"=="(result, isoString, "", __FILE__, line);
}
testSTZ("+00:00", 0);
testSTZ("+00:01", 1);
testSTZ("+00:10", 10);
testSTZ("+00:59", 59);
testSTZ("+01:00", 60);
testSTZ("+01:30", 90);
testSTZ("+02:00", 120);
testSTZ("+08:00", 480);
testSTZ("+08:00", 480);
testSTZ("+23:59", 1439);
testSTZ("-00:01", -1);
testSTZ("-00:10", -10);
testSTZ("-00:59", -59);
testSTZ("-01:00", -60);
testSTZ("-01:30", -90);
testSTZ("-02:00", -120);
testSTZ("-08:00", -480);
testSTZ("-08:00", -480);
testSTZ("-23:59", -1439);
}
immutable Duration _utcOffset;
}
/++
Represents a time zone from a TZ Database time zone file. Files from the TZ
Database are how Posix systems hold their time zone information.
Unfortunately, Windows does not use the TZ Database. To use the TZ Database,
use $(LREF PosixTimeZone) (which reads its information from the TZ Database
files on disk) on Windows by providing the TZ Database files and telling
$(D PosixTimeZone.getTimeZone) where the directory holding them is.
To get a $(D PosixTimeZone), either call $(D PosixTimeZone.getTimeZone)
(which allows specifying the location the time zone files) or call
$(D TimeZone.getTimeZone) (which will give a $(D PosixTimeZone) on Posix
systems and a $(D WindowsTimeZone) on Windows systems).
Note:
Unless your system's local time zone deals with leap seconds (which is
highly unlikely), then the only way to get a time zone which
takes leap seconds into account is to use $(D PosixTimeZone) with a
time zone whose name starts with "right/". Those time zone files do
include leap seconds, and $(D PosixTimeZone) will take them into account
(though posix systems which use a "right/" time zone as their local time
zone will $(I not) take leap seconds into account even though they're
in the file).
See_Also:
$(WEB www.iana.org/time-zones, Home of the TZ Database files)<br>
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List of Time
Zones)
+/
final class PosixTimeZone : TimeZone
{
public:
/++
Whether this time zone has Daylight Savings Time at any point in time.
Note that for some time zone types it may not have DST for current
dates but will still return true for $(D hasDST) because the time zone
did at some point have DST.
+/
@property override bool hasDST() const nothrow
{
return _hasDST;
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and returns whether DST is in effect in this
time zone at the given point in time.
Params:
stdTime = The UTC time that needs to be checked for DST in this time
zone.
+/
override bool dstInEffect(long stdTime) const nothrow
{
assert(!_transitions.empty);
try
{
immutable unixTime = stdTimeToUnixTime(stdTime);
immutable found = countUntil!"b < a.timeT"(cast(Transition[])_transitions, unixTime);
if(found == -1)
return _transitions.back.ttInfo.isDST;
immutable transition = found == 0 ? _transitions[0] : _transitions[found - 1];
return transition.ttInfo.isDST;
}
catch(Exception e)
assert(0, format("Unexpected Exception: %s", e));
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in UTC time (i.e. std time) and converts it to this time zone's time.
Params:
stdTime = The UTC time that needs to be adjusted to this time zone's
time.
+/
override long utcToTZ(long stdTime) const nothrow
{
assert(!_transitions.empty);
try
{
immutable leapSecs = calculateLeapSeconds(stdTime);
immutable unixTime = stdTimeToUnixTime(stdTime);
immutable found = countUntil!"b < a.timeT"(cast(Transition[])_transitions, unixTime);
if(found == -1)
return stdTime + convert!("seconds", "hnsecs")(_transitions.back.ttInfo.utcOffset + leapSecs);
immutable transition = found == 0 ? _transitions[0] : _transitions[found - 1];
return stdTime + convert!("seconds", "hnsecs")(transition.ttInfo.utcOffset + leapSecs);
}
catch(Exception e)
assert(0, format("Unexpected Exception: %s", e));
}
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D.
in this time zone's time and converts it to UTC (i.e. std time).
Params:
adjTime = The time in this time zone that needs to be adjusted to
UTC time.
+/
override long tzToUTC(long adjTime) const nothrow
{
assert(!_transitions.empty);
try
{
immutable leapSecs = calculateLeapSeconds(adjTime);
time_t unixTime = stdTimeToUnixTime(adjTime);
immutable past = unixTime - convert!("days", "seconds")(1);
immutable future = unixTime + convert!("days", "seconds")(1);
immutable pastFound = countUntil!"b < a.timeT"(cast(Transition[])_transitions, past);
if(pastFound == -1)
return adjTime - convert!("seconds", "hnsecs")(_transitions.back.ttInfo.utcOffset + leapSecs);
immutable futureFound = countUntil!"b < a.timeT"(cast(Transition[])_transitions[pastFound .. $], future);
immutable pastTrans = pastFound == 0 ? _transitions[0] : _transitions[pastFound - 1];
if(futureFound == 0)
return adjTime - convert!("seconds", "hnsecs")(pastTrans.ttInfo.utcOffset + leapSecs);
immutable futureTrans = futureFound == -1 ? _transitions.back
: _transitions[pastFound + futureFound - 1];
immutable pastOffset = pastTrans.ttInfo.utcOffset;
if(pastOffset < futureTrans.ttInfo.utcOffset)
unixTime -= convert!("hours", "seconds")(1);
immutable found = countUntil!"b < a.timeT"(cast(Transition[])_transitions[pastFound .. $],
unixTime - pastOffset);
if(found == -1)
return adjTime - convert!("seconds", "hnsecs")(_transitions.back.ttInfo.utcOffset + leapSecs);
immutable transition = found == 0 ? pastTrans : _transitions[pastFound + found - 1];
return adjTime - convert!("seconds", "hnsecs")(transition.ttInfo.utcOffset + leapSecs);
}
catch(Exception e)
assert(0, format("Unexpected Exception: %s", e));
}
version(Posix)
{
/++
The default directory where the TZ Database files are. It's empty
for Windows, since Windows doesn't have them.
+/
enum defaultTZDatabaseDir = "/usr/share/zoneinfo/";
}
else version(Windows)
{
/++ The default directory where the TZ Database files are. It's empty
for Windows, since Windows doesn't have them.
+/
enum defaultTZDatabaseDir = "";
}
/++
Returns a $(D TimeZone) with the give name per the TZ Database. The time
zone information is fetched from the TZ Database time zone files in the
given directory.
See_Also:
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ
Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List of
Time Zones)
Params:
name = The TZ Database name of the desired time zone
tzDatabaseDir = The directory where the TZ Database files are
located. Because these files are not located on
Windows systems, provide them
and give their location here to
use $(D PosixTimeZone)s.
Throws:
$(D DateTimeException) if the given time zone could not be found or
$(D FileException) if the TZ Database file could not be opened.
Examples:
--------------------
auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles");
assert(tz.name == "America/Los_Angeles");
assert(tz.stdName == "PST");
assert(tz.dstName == "PDT");
--------------------
+/
//TODO make it possible for tzDatabaseDir to be gzipped tar file rather than an uncompressed
// directory.
static immutable(PosixTimeZone) getTimeZone(string name, string tzDatabaseDir = defaultTZDatabaseDir)
{
name = strip(name);
enforce(tzDatabaseDir.exists, new DateTimeException(format("Directory %s does not exist.", tzDatabaseDir)));
enforce(tzDatabaseDir.isDir, new DateTimeException(format("%s is not a directory.", tzDatabaseDir)));
version(Posix)
auto file = tzDatabaseDir ~ name;
else version(Windows)
auto file = tzDatabaseDir ~ replace(strip(name), "/", dirSeparator);
enforce(file.exists, new DateTimeException(format("File %s does not exist.", file)));
enforce(file.isFile, new DateTimeException(format("%s is not a file.", file)));
auto tzFile = File(file);
immutable gmtZone = file.canFind("GMT");
try
{
_enforceValidTZFile(readVal!(char[])(tzFile, 4) == "TZif");
immutable char tzFileVersion = readVal!char(tzFile);
_enforceValidTZFile(tzFileVersion == '\0' || tzFileVersion == '2');
{
auto zeroBlock = readVal!(ubyte[])(tzFile, 15);
bool allZeroes = true;
foreach(val; zeroBlock)
{
if(val != 0)
{
allZeroes = false;
break;
}
}
_enforceValidTZFile(allZeroes);
}
//The number of UTC/local indicators stored in the file.
auto tzh_ttisgmtcnt = readVal!int(tzFile);
//The number of standard/wall indicators stored in the file.
auto tzh_ttisstdcnt = readVal!int(tzFile);
//The number of leap seconds for which data is stored in the file.
auto tzh_leapcnt = readVal!int(tzFile);
//The number of "transition times" for which data is stored in the file.
auto tzh_timecnt = readVal!int(tzFile);
//The number of "local time types" for which data is stored in the file (must not be zero).
auto tzh_typecnt = readVal!int(tzFile);
_enforceValidTZFile(tzh_typecnt != 0);
//The number of characters of "timezone abbreviation strings" stored in the file.
auto tzh_charcnt = readVal!int(tzFile);
//time_ts where DST transitions occur.
auto transitionTimeTs = new long[](tzh_timecnt);
foreach(ref transition; transitionTimeTs)
transition = readVal!int(tzFile);
//Indices into ttinfo structs indicating the changes
//to be made at the corresponding DST transition.
auto ttInfoIndices = new ubyte[](tzh_timecnt);
foreach(ref ttInfoIndex; ttInfoIndices)
ttInfoIndex = readVal!ubyte(tzFile);
//ttinfos which give info on DST transitions.
auto tempTTInfos = new TempTTInfo[](tzh_typecnt);
foreach(ref ttInfo; tempTTInfos)
ttInfo = readVal!TempTTInfo(tzFile);
//The array of time zone abbreviation characters.
auto tzAbbrevChars = readVal!(char[])(tzFile, tzh_charcnt);
auto leapSeconds = new LeapSecond[](tzh_leapcnt);
foreach(ref leapSecond; leapSeconds)
{
//The time_t when the leap second occurs.
auto timeT = readVal!int(tzFile);
//The total number of leap seconds to be applied after
//the corresponding leap second.
auto total = readVal!int(tzFile);
leapSecond = LeapSecond(timeT, total);
}
//Indicate whether each corresponding DST transition were specified
//in standard time or wall clock time.
auto transitionIsStd = new bool[](tzh_ttisstdcnt);
foreach(ref isStd; transitionIsStd)
isStd = readVal!bool(tzFile);
//Indicate whether each corresponding DST transition associated with
//local time types are specified in UTC or local time.
auto transitionInUTC = new bool[](tzh_ttisgmtcnt);
foreach(ref inUTC; transitionInUTC)
inUTC = readVal!bool(tzFile);
_enforceValidTZFile(!tzFile.eof);
//If version 2, the information is duplicated in 64-bit.
if(tzFileVersion == '2')
{
_enforceValidTZFile(readVal!(char[])(tzFile, 4) == "TZif");
_enforceValidTZFile(readVal!(char)(tzFile) == '2');
{
auto zeroBlock = readVal!(ubyte[])(tzFile, 15);
bool allZeroes = true;
foreach(val; zeroBlock)
{
if(val != 0)
{
allZeroes = false;
break;
}
}
_enforceValidTZFile(allZeroes);
}
//The number of UTC/local indicators stored in the file.
tzh_ttisgmtcnt = readVal!int(tzFile);
//The number of standard/wall indicators stored in the file.
tzh_ttisstdcnt = readVal!int(tzFile);
//The number of leap seconds for which data is stored in the file.
tzh_leapcnt = readVal!int(tzFile);
//The number of "transition times" for which data is stored in the file.
tzh_timecnt = readVal!int(tzFile);
//The number of "local time types" for which data is stored in the file (must not be zero).
tzh_typecnt = readVal!int(tzFile);
_enforceValidTZFile(tzh_typecnt != 0);
//The number of characters of "timezone abbreviation strings" stored in the file.
tzh_charcnt = readVal!int(tzFile);
//time_ts where DST transitions occur.
transitionTimeTs = new long[](tzh_timecnt);
foreach(ref transition; transitionTimeTs)
transition = readVal!long(tzFile);
//Indices into ttinfo structs indicating the changes
//to be made at the corresponding DST transition.
ttInfoIndices = new ubyte[](tzh_timecnt);
foreach(ref ttInfoIndex; ttInfoIndices)
ttInfoIndex = readVal!ubyte(tzFile);
//ttinfos which give info on DST transitions.
tempTTInfos = new TempTTInfo[](tzh_typecnt);
foreach(ref ttInfo; tempTTInfos)
ttInfo = readVal!TempTTInfo(tzFile);
//The array of time zone abbreviation characters.
tzAbbrevChars = readVal!(char[])(tzFile, tzh_charcnt);
leapSeconds = new LeapSecond[](tzh_leapcnt);
foreach(ref leapSecond; leapSeconds)
{
//The time_t when the leap second occurs.
auto timeT = readVal!long(tzFile);
//The total number of leap seconds to be applied after
//the corresponding leap second.
auto total = readVal!int(tzFile);
leapSecond = LeapSecond(timeT, total);
}
//Indicate whether each corresponding DST transition were specified
//in standard time or wall clock time.
transitionIsStd = new bool[](tzh_ttisstdcnt);
foreach(ref isStd; transitionIsStd)
isStd = readVal!bool(tzFile);
//Indicate whether each corresponding DST transition associated with
//local time types are specified in UTC or local time.
transitionInUTC = new bool[](tzh_ttisgmtcnt);
foreach(ref inUTC; transitionInUTC)
inUTC = readVal!bool(tzFile);
}
_enforceValidTZFile(tzFile.readln().strip().empty);
auto posixEnvStr = tzFile.readln().strip();
_enforceValidTZFile(tzFile.readln().strip().empty);
_enforceValidTZFile(tzFile.eof);
auto transitionTypes = new TransitionType*[](tempTTInfos.length);
foreach(i, ref ttype; transitionTypes)
{
bool isStd = false;
if(i < transitionIsStd.length && !transitionIsStd.empty)
isStd = transitionIsStd[i];
bool inUTC = false;
if(i < transitionInUTC.length && !transitionInUTC.empty)
inUTC = transitionInUTC[i];
ttype = new TransitionType(isStd, inUTC);
}
auto ttInfos = new immutable(TTInfo)*[](tempTTInfos.length);
foreach(i, ref ttInfo; ttInfos)
{
auto tempTTInfo = tempTTInfos[i];
if(gmtZone)
tempTTInfo.tt_gmtoff = -tempTTInfo.tt_gmtoff;
auto abbrevChars = tzAbbrevChars[tempTTInfo.tt_abbrind .. $];
string abbrev = abbrevChars[0 .. abbrevChars.stds_indexOf("\0")].idup;
ttInfo = new immutable(TTInfo)(tempTTInfos[i], abbrev);
}
auto tempTransitions = new TempTransition[](transitionTimeTs.length);
foreach(i, ref tempTransition; tempTransitions)
{
immutable ttiIndex = ttInfoIndices[i];
auto transitionTimeT = transitionTimeTs[i];
auto ttype = transitionTypes[ttiIndex];
auto ttInfo = ttInfos[ttiIndex];
tempTransition = TempTransition(transitionTimeT, ttInfo, ttype);
}
if(tempTransitions.empty)
{
_enforceValidTZFile(ttInfos.length == 1 && transitionTypes.length == 1);
tempTransitions ~= TempTransition(0, ttInfos[0], transitionTypes[0]);
}
sort!"a.timeT < b.timeT"(tempTransitions);
sort!"a.timeT < b.timeT"(leapSeconds);
auto transitions = new Transition[](tempTransitions.length);
foreach(i, ref transition; transitions)
{
auto tempTransition = tempTransitions[i];
auto transitionTimeT = tempTransition.timeT;
auto ttInfo = tempTransition.ttInfo;
auto ttype = tempTransition.ttype;
_enforceValidTZFile(i == 0 || transitionTimeT > tempTransitions[i - 1].timeT);
transition = Transition(transitionTimeT, ttInfo);
}
string stdName;
string dstName;
bool hasDST = false;
foreach(transition; retro(transitions))
{
auto ttInfo = transition.ttInfo;
if(ttInfo.isDST)
{
if(dstName.empty)
dstName = ttInfo.abbrev;
hasDST = true;
}
else
{
if(stdName.empty)
stdName = ttInfo.abbrev;
}
if(!stdName.empty && !dstName.empty)
break;
}
return new PosixTimeZone(transitions.idup, leapSeconds.idup, name, stdName, dstName, hasDST);
}
catch(DateTimeException dte)
throw dte;
catch(Exception e)
throw new DateTimeException("Not a valid TZ data file", __FILE__, __LINE__, e);
}
/++
Returns a list of the names of the time zones installed on the system.
Providing a sub-name narrows down the list of time zones (which
can number in the thousands). For example,
passing in "America" as the sub-name returns only the time zones which
begin with "America".
Params:
subName = The first part of the desired time zones.
Throws:
$(D FileException) if it fails to read from disk.
+/
static string[] getInstalledTZNames(string subName = "", string tzDatabaseDir = defaultTZDatabaseDir)
{
version(Posix)
subName = strip(subName);
else version(Windows)
subName = replace(strip(subName), "/", dirSeparator);
if(!tzDatabaseDir.endsWith(dirSeparator))
tzDatabaseDir ~= dirSeparator;
enforce(tzDatabaseDir.exists, new DateTimeException(format("Directory %s does not exist.", tzDatabaseDir)));
enforce(tzDatabaseDir.isDir, new DateTimeException(format("%s is not a directory.", tzDatabaseDir)));
auto timezones = appender!(string[])();
foreach(DirEntry dentry; dirEntries(tzDatabaseDir, SpanMode.depth))
{
if(dentry.isFile)
{
auto tzName = dentry.name[tzDatabaseDir.length .. $];
if(!tzName.extension().empty ||
!tzName.startsWith(subName) ||
tzName == "+VERSION")
{
continue;
}
timezones.put(tzName);
}
}
sort(timezones.data);
return timezones.data;
}
unittest
{
version(testStdDateTime)
{
version(Posix)
{
static void testPTZSuccess(string tzName)
{
scope(failure) writefln("TZName which threw: %s", tzName);
PosixTimeZone.getTimeZone(tzName);
}
static void testPTZFailure(string tzName)
{
scope(success) writefln("TZName which was supposed to throw: %s", tzName);
PosixTimeZone.getTimeZone(tzName);
}
auto tzNames = getInstalledTZNames();
foreach(tzName; tzNames)
assertNotThrown!DateTimeException(testPTZSuccess(tzName));
foreach(DirEntry dentry; dirEntries(defaultTZDatabaseDir, SpanMode.depth))
{
if(dentry.isFile)
{
auto tzName = dentry.name[defaultTZDatabaseDir.length .. $];
if(!canFind(tzNames, tzName))
assertThrown!DateTimeException(testPTZFailure(tzName));
}
}
}
}
}
private:
/+
Holds information on when a time transition occures (usually a
transition to or from DST) as well as a pointer to the $(D TTInfo) which
holds information on the utc offset passed the transition.
+/
struct Transition
{
this(long timeT, immutable (TTInfo)* ttInfo)
{
this.timeT = timeT;
this.ttInfo = ttInfo;
}
long timeT;
immutable (TTInfo)* ttInfo;
}
/+
Holds information on when a leap second occurs.
+/
struct LeapSecond
{
this(long timeT, int total)
{
this.timeT = timeT;
this.total = total;
}
long timeT;
int total;
}
/+
Holds information on the utc offset after a transition as well as
whether DST is in effect after that transition.
+/
struct TTInfo
{
this(in TempTTInfo tempTTInfo, string abbrev) immutable
{
utcOffset = tempTTInfo.tt_gmtoff;
isDST = tempTTInfo.tt_isdst;
this.abbrev = abbrev;
}
immutable int utcOffset; /// Offset from UTC.
immutable bool isDST; /// Whether DST is in effect.
immutable string abbrev; /// The current abbreviation for the time zone.
}
/+
Struct used to hold information relating to $(D TTInfo) while organizing
the time zone information prior to putting it in its final form.
+/
struct TempTTInfo
{
this(int gmtOff, bool isDST, ubyte abbrInd)
{
tt_gmtoff = gmtOff;
tt_isdst = isDST;
tt_abbrind = abbrInd;
}
int tt_gmtoff;
bool tt_isdst;
ubyte tt_abbrind;
}
/+
Struct used to hold information relating to $(D Transition) while
organizing the time zone information prior to putting it in its final
form.
+/
struct TempTransition
{
this(long timeT, immutable (TTInfo)* ttInfo, TransitionType* ttype)
{
this.timeT = timeT;
this.ttInfo = ttInfo;
this.ttype = ttype;
}
long timeT;
immutable (TTInfo)* ttInfo;
TransitionType* ttype;
}
/+
Struct used to hold information relating to $(D Transition) and
$(D TTInfo) while organizing the time zone information prior to putting
it in its final form.
+/
struct TransitionType
{
this(bool isStd, bool inUTC)
{
this.isStd = isStd;
this.inUTC = inUTC;
}
/// Whether the transition is in std time (as opposed to wall clock time).
bool isStd;
/// Whether the transition is in UTC (as opposed to local time).
bool inUTC;
}
/+
Reads an int from a TZ file.
+/
static T readVal(T)(ref File tzFile)
if((isIntegral!T || isSomeChar!T) || is(Unqual!T == bool))
{
import std.bitmanip;
T[1] buff;
_enforceValidTZFile(!tzFile.eof);
tzFile.rawRead(buff);
return bigEndianToNative!T(cast(ubyte[T.sizeof])buff);
}
/+
Reads an array of values from a TZ file.
+/
static T readVal(T)(ref File tzFile, size_t length)
if(isArray!T)
{
auto buff = new T(length);
_enforceValidTZFile(!tzFile.eof);
tzFile.rawRead(buff);
return buff;
}
/+
Reads a $(D TempTTInfo) from a TZ file.
+/
static T readVal(T)(ref File tzFile)
if(is(T == TempTTInfo))
{
return TempTTInfo(readVal!int(tzFile),
readVal!bool(tzFile),
readVal!ubyte(tzFile));
}
/+
Throws:
$(D DateTimeException) if $(D result) is false.
+/
static void _enforceValidTZFile(bool result, size_t line = __LINE__)
{
if(!result)
throw new DateTimeException("Not a valid tzdata file.", __FILE__, line);
}
int calculateLeapSeconds(long stdTime) const nothrow
{
try
{
if(_leapSeconds.empty)
return 0;
immutable unixTime = stdTimeToUnixTime(stdTime);
if(_leapSeconds.front.timeT >= unixTime)
return 0;
immutable found = countUntil!"b < a.timeT"(cast(LeapSecond[])_leapSeconds, unixTime);
if(found == -1)
return _leapSeconds.back.total;
immutable leapSecond = found == 0 ? _leapSeconds[0] : _leapSeconds[found - 1];
return leapSecond.total;
}
catch(Exception e)
assert(0, format("Nothing in calculateLeapSeconds() should be throwing. Caught Exception: %s", e));
}
this(immutable Transition[] transitions,
immutable LeapSecond[] leapSeconds,
string name,
string stdName,
string dstName,
bool hasDST) immutable
{
if(dstName.empty && !stdName.empty)
dstName = stdName;
else if(stdName.empty && !dstName.empty)
stdName = dstName;
super(name, stdName, dstName);
if(!transitions.empty)
{
foreach(i, transition; transitions[0 .. $-1])
_enforceValidTZFile(transition.timeT < transitions[i + 1].timeT);
}
foreach(i, leapSecond; leapSeconds)
_enforceValidTZFile(i == leapSeconds.length - 1 || leapSecond.timeT < leapSeconds[i + 1].timeT);
_transitions = transitions;
_leapSeconds = leapSeconds;
_hasDST = hasDST;
}
/// List of times when the utc offset changes.
immutable Transition[] _transitions;
/// List of leap second occurrences.
immutable LeapSecond[] _leapSeconds;
/// Whether DST is in effect for this time zone at any point in time.
immutable bool _hasDST;
}
version(StdDdoc)
{
/++
$(BLUE This class is Windows-Only.)
Represents a time zone from the Windows registry. Unfortunately, Windows
does not use the TZ Database. To use the TZ Database, use
$(LREF PosixTimeZone) (which reads its information from the TZ Database
files on disk) on Windows by providing the TZ Database files and telling
$(D PosixTimeZone.getTimeZone) where the directory holding them is.
The TZ Database files and Windows' time zone information frequently
do not match. Windows has many errors with regards to when DST switches
occur (especially for historical dates). Also, the TZ Database files
include far more time zones than Windows does. So, for accurate
time zone information, use the TZ Database files with
$(LREF PosixTimeZone) rather than $(D WindowsTimeZone). However, because
$(D WindowsTimeZone) uses Windows system calls to deal with the time,
it's far more likely to match the behavior of other Windows programs.
Be aware of the differences when selecting a method.
$(D WindowsTimeZone) does not exist on Posix systems.
To get a $(D WindowsTimeZone), either call
$(D WindowsTimeZone.getTimeZone) or call $(D TimeZone.getTimeZone)
(which will give a $(LREF PosixTimeZone) on Posix systems and a
$(D WindowsTimeZone) on Windows systems).
See_Also:
$(WEB www.iana.org/time-zones, Home of the TZ Database files)
+/
final class WindowsTimeZone : TimeZone
{
public:
/++
Whether this time zone has Daylight Savings Time at any point in
time. Note that for some time zone types it may not have DST for
current dates but will still return true for $(D hasDST) because the
time zone did at some point have DST.
+/
@property override bool hasDST() const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st,
1 A.D. in UTC time (i.e. std time) and returns whether DST is in
effect in this time zone at the given point in time.
Params:
stdTime = The UTC time that needs to be checked for DST in this
time zone.
+/
override bool dstInEffect(long stdTime) const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st,
1 A.D. in UTC time (i.e. std time) and converts it to this time
zone's time.
Params:
stdTime = The UTC time that needs to be adjusted to this time
zone's time.
+/
override long utcToTZ(long stdTime) const nothrow;
/++
Takes the number of hnsecs (100 ns) since midnight, January 1st,
1 A.D. in this time zone's time and converts it to UTC (i.e. std
time).
Params:
adjTime = The time in this time zone that needs to be adjusted
to UTC time.
+/
override long tzToUTC(long adjTime) const nothrow;
/++
Returns a $(D TimeZone) with the given name per the Windows time
zone names. The time zone information is fetched from the Windows
registry.
See_Also:
$(WEB en.wikipedia.org/wiki/Tz_database, Wikipedia entry on TZ
Database)<br>
$(WEB en.wikipedia.org/wiki/List_of_tz_database_time_zones, List
of Time Zones)
Params:
name = The TZ Database name of the desired time zone.
Throws:
$(D DateTimeException) if the given time zone could not be
found.
Examples:
--------------------
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
--------------------
+/
static immutable(WindowsTimeZone) getTimeZone(string name);
/++
Returns a list of the names of the time zones installed on the
system.
+/
static string[] getInstalledTZNames();
private:
version(Windows) {}
else
alias void* TIME_ZONE_INFORMATION;
static bool _dstInEffect(const TIME_ZONE_INFORMATION* tzInfo, long stdTime) nothrow;
static long _utcToTZ(const TIME_ZONE_INFORMATION* tzInfo, long stdTime, bool hasDST) nothrow;
static long _tzToUTC(const TIME_ZONE_INFORMATION* tzInfo, long adjTime, bool hasDST) nothrow;
this() immutable pure
{
super("", "", "");
}
}
}
else version(Windows)
{
final class WindowsTimeZone : TimeZone
{
public:
@property override bool hasDST() const nothrow
{
return _tzInfo.DaylightDate.wMonth != 0;
}
override bool dstInEffect(long stdTime) const nothrow
{
return _dstInEffect(&_tzInfo, stdTime);
}
override long utcToTZ(long stdTime) const nothrow
{
return _utcToTZ(&_tzInfo, stdTime, hasDST);
}
override long tzToUTC(long adjTime) const nothrow
{
return _tzToUTC(&_tzInfo, adjTime, hasDST);
}
static immutable(WindowsTimeZone) getTimeZone(string name)
{
scope baseKey = Registry.localMachine.getKey(`Software\Microsoft\Windows NT\CurrentVersion\Time Zones`);
foreach (tzKeyName; baseKey.keyNames)
{
if (tzKeyName != name)
continue;
scope tzKey = baseKey.getKey(tzKeyName);
scope stdVal = tzKey.getValue("Std");
auto stdName = stdVal.value_SZ;
scope dstVal = tzKey.getValue("Dlt");
auto dstName = dstVal.value_SZ;
scope tziVal = tzKey.getValue("TZI");
auto binVal = tziVal.value_BINARY;
assert(binVal.length == REG_TZI_FORMAT.sizeof);
auto tziFmt = cast(REG_TZI_FORMAT*)binVal.ptr;
TIME_ZONE_INFORMATION tzInfo;
auto wstdName = toUTF16(stdName);
auto wdstName = toUTF16(dstName);
auto wstdNameLen = wstdName.length > 32 ? 32 : wstdName.length;
auto wdstNameLen = wdstName.length > 32 ? 32 : wdstName.length;
tzInfo.Bias = tziFmt.Bias;
tzInfo.StandardName[0 .. wstdNameLen] = wstdName[0 .. wstdNameLen];
tzInfo.StandardName[wstdNameLen .. $] = '\0';
tzInfo.StandardDate = tziFmt.StandardDate;
tzInfo.StandardBias = tziFmt.StandardBias;
tzInfo.DaylightName[0 .. wdstNameLen] = wdstName[0 .. wdstNameLen];
tzInfo.DaylightName[wdstNameLen .. $] = '\0';
tzInfo.DaylightDate = tziFmt.DaylightDate;
tzInfo.DaylightBias = tziFmt.DaylightBias;
return new WindowsTimeZone(name, tzInfo);
}
throw new DateTimeException(format("Failed to find time zone: %s", name));
}
static string[] getInstalledTZNames()
{
auto timezones = appender!(string[])();
scope baseKey = Registry.localMachine.getKey(`Software\Microsoft\Windows NT\CurrentVersion\Time Zones`);
foreach (tzKeyName; baseKey.keyNames)
{
timezones.put(tzKeyName);
}
sort(timezones.data);
return timezones.data;
}
unittest
{
version(testStdDateTime)
{
static void testWTZSuccess(string tzName)
{
scope(failure) writefln("TZName which threw: %s", tzName);
WindowsTimeZone.getTimeZone(tzName);
}
auto tzNames = getInstalledTZNames();
foreach(tzName; tzNames)
assertNotThrown!DateTimeException(testWTZSuccess(tzName));
}
}
private:
static bool _dstInEffect(const TIME_ZONE_INFORMATION* tzInfo, long stdTime) nothrow
{
try
{
if(tzInfo.DaylightDate.wMonth == 0)
return false;
auto utcDateTime = cast(DateTime)SysTime(stdTime, UTC());
//The limits of what SystemTimeToTzSpecificLocalTime will accept.
if(utcDateTime.year < 1601)
{
if(utcDateTime.month == Month.feb && utcDateTime.day == 29)
utcDateTime.day = 28;
utcDateTime.year = 1601;
}
else if(utcDateTime.year > 30_827)
{
if(utcDateTime.month == Month.feb && utcDateTime.day == 29)
utcDateTime.day = 28;
utcDateTime.year = 30_827;
}
//SystemTimeToTzSpecificLocalTime doesn't act correctly at the
//beginning or end of the year (bleh). Unless some bizarre time
//zone changes DST on January 1st or December 31st, this should
//fix the problem.
if(utcDateTime.month == Month.jan)
{
if(utcDateTime.day == 1)
utcDateTime.day = 2;
}
else if(utcDateTime.month == Month.dec && utcDateTime.day == 31)
utcDateTime.day = 30;
SYSTEMTIME utcTime = void;
SYSTEMTIME otherTime = void;
utcTime.wYear = utcDateTime.year;
utcTime.wMonth = utcDateTime.month;
utcTime.wDay = utcDateTime.day;
utcTime.wHour = utcDateTime.hour;
utcTime.wMinute = utcDateTime.minute;
utcTime.wSecond = utcDateTime.second;
utcTime.wMilliseconds = 0;
immutable result = SystemTimeToTzSpecificLocalTime(cast(TIME_ZONE_INFORMATION*)tzInfo,
&utcTime,
&otherTime);
assert(result);
immutable otherDateTime = DateTime(otherTime.wYear,
otherTime.wMonth,
otherTime.wDay,
otherTime.wHour,
otherTime.wMinute,
otherTime.wSecond);
immutable diff = utcDateTime - otherDateTime;
immutable minutes = diff.total!"minutes" - tzInfo.Bias;
if(minutes == tzInfo.DaylightBias)
return true;
assert(minutes == tzInfo.StandardBias);
return false;
}
catch(Exception e)
assert(0, "DateTime's constructor threw.");
}
version(testStdDateTime) unittest
{
TIME_ZONE_INFORMATION tzInfo;
GetTimeZoneInformation(&tzInfo);
foreach(year; [1600, 1601, 30_827, 30_828])
WindowsTimeZone._dstInEffect(&tzInfo, SysTime(DateTime(year, 1, 1)).stdTime);
}
static long _utcToTZ(const TIME_ZONE_INFORMATION* tzInfo, long stdTime, bool hasDST) nothrow
{
if(hasDST && WindowsTimeZone._dstInEffect(tzInfo, stdTime))
return stdTime - convert!("minutes", "hnsecs")(tzInfo.Bias + tzInfo.DaylightBias);
return stdTime - convert!("minutes", "hnsecs")(tzInfo.Bias + tzInfo.StandardBias);
}
static long _tzToUTC(const TIME_ZONE_INFORMATION* tzInfo, long adjTime, bool hasDST) nothrow
{
if(hasDST)
{
try
{
bool dstInEffectForLocalDateTime(DateTime localDateTime)
{
//The limits of what SystemTimeToTzSpecificLocalTime will accept.
if(localDateTime.year < 1601)
{
if(localDateTime.month == Month.feb && localDateTime.day == 29)
localDateTime.day = 28;
localDateTime.year = 1601;
}
else if(localDateTime.year > 30_827)
{
if(localDateTime.month == Month.feb && localDateTime.day == 29)
localDateTime.day = 28;
localDateTime.year = 30_827;
}
//SystemTimeToTzSpecificLocalTime doesn't act correctly at the
//beginning or end of the year (bleh). Unless some bizarre time
//zone changes DST on January 1st or December 31st, this should
//fix the problem.
if(localDateTime.month == Month.jan)
{
if(localDateTime.day == 1)
localDateTime.day = 2;
}
else if(localDateTime.month == Month.dec && localDateTime.day == 31)
localDateTime.day = 30;
SYSTEMTIME utcTime = void;
SYSTEMTIME localTime = void;
localTime.wYear = localDateTime.year;
localTime.wMonth = localDateTime.month;
localTime.wDay = localDateTime.day;
localTime.wHour = localDateTime.hour;
localTime.wMinute = localDateTime.minute;
localTime.wSecond = localDateTime.second;
localTime.wMilliseconds = 0;
immutable result = TzSpecificLocalTimeToSystemTime(cast(TIME_ZONE_INFORMATION*)tzInfo,
&localTime,
&utcTime);
assert(result);
immutable utcDateTime = DateTime(utcTime.wYear,
utcTime.wMonth,
utcTime.wDay,
utcTime.wHour,
utcTime.wMinute,
utcTime.wSecond);
immutable diff = localDateTime - utcDateTime;
immutable minutes = -tzInfo.Bias - diff.total!"minutes";
if(minutes == tzInfo.DaylightBias)
return true;
assert(minutes == tzInfo.StandardBias);
return false;
}
auto localDateTime = cast(DateTime)SysTime(adjTime, UTC());
auto localDateTimeBefore = localDateTime - dur!"hours"(1);
auto localDateTimeAfter = localDateTime + dur!"hours"(1);
auto dstInEffectNow = dstInEffectForLocalDateTime(localDateTime);
auto dstInEffectBefore = dstInEffectForLocalDateTime(localDateTimeBefore);
auto dstInEffectAfter = dstInEffectForLocalDateTime(localDateTimeAfter);
bool isDST;
if(dstInEffectBefore && dstInEffectNow && dstInEffectAfter)
isDST = true;
else if(!dstInEffectBefore && !dstInEffectNow && !dstInEffectAfter)
isDST = false;
else if(!dstInEffectBefore && dstInEffectAfter)
isDST = false;
else if(dstInEffectBefore && !dstInEffectAfter)
isDST = dstInEffectNow;
else
assert(0, "Bad Logic.");
if(isDST)
return adjTime + convert!("minutes", "hnsecs")(tzInfo.Bias + tzInfo.DaylightBias);
}
catch(Exception e)
assert(0, "SysTime's constructor threw.");
}
return adjTime + convert!("minutes", "hnsecs")(tzInfo.Bias + tzInfo.StandardBias);
}
this(string name, TIME_ZONE_INFORMATION tzInfo) immutable
{
//Cannot use to!string(wchar*), probably due to bug http://d.puremagic.com/issues/show_bug.cgi?id=5016
static string conv(wchar* wcstr)
{
wcstr[31] = '\0';
wstring retval;
for(;; ++wcstr)
{
if(*wcstr == '\0')
break;
retval ~= *wcstr;
}
return to!string(retval);
}
//super(name, to!string(tzInfo.StandardName.ptr), to!string(tzInfo.DaylightName.ptr));
super(name, conv(tzInfo.StandardName.ptr), conv(tzInfo.DaylightName.ptr));
_tzInfo = tzInfo;
}
TIME_ZONE_INFORMATION _tzInfo;
}
}
version(StdDdoc)
{
/++
$(BLUE This function is Posix-Only.)
Sets the local time zone on Posix systems with the TZ
Database name by setting the TZ environment variable.
Unfortunately, there is no way to do it on Windows using the TZ
Database name, so this function only exists on Posix systems.
+/
void setTZEnvVar(string tzDatabaseName);
/++
$(BLUE This function is Posix-Only.)
Clears the TZ environment variable.
+/
void clearTZEnvVar();
}
else version(Posix)
{
void setTZEnvVar(string tzDatabaseName) nothrow
{
try
{
auto value = PosixTimeZone.defaultTZDatabaseDir ~ tzDatabaseName ~ "\0";
setenv("TZ", value.ptr, 1);
tzset();
}
catch(Exception e)
assert(0, "The impossible happened. setenv or tzset threw.");
}
void clearTZEnvVar() nothrow
{
try
{
unsetenv("TZ");
tzset();
}
catch(Exception e)
assert(0, "The impossible happened. unsetenv or tzset threw.");
}
}
/++
Converts the given TZ Database name to the corresponding Windows time zone
name.
Note that in a few cases, a TZ Dabatase name corresponds to two different
Windows time zone names. So, while in most cases converting from one to the
other and back again will result in the same time zone name started
with, in a few case, it'll get a different name.
Also, there are far more TZ Database names than Windows time zones, so some
of the more exotic TZ Database names don't have corresponding Windows time
zone names.
See_Also:
$(WEB unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html,
Windows <-> TZ Database Name Conversion Table)
Params:
tzName = The TZ Database name to convert.
Throws:
$(D DateTimeException) if the given $(D_PARAM tzName) cannot be
converted.
+/
string tzDatabaseNameToWindowsTZName(string tzName)
{
switch(tzName)
{
//Most of these come from the link in the documentation, but a few have
//been added because they were found in the Windows registry.
case "Africa/Cairo": return "Egypt Standard Time";
case "Africa/Casablanca": return "Morocco Standard Time";
case "Africa/Johannesburg": return "South Africa Standard Time";
case "Africa/Lagos": return "W. Central Africa Standard Time";
case "Africa/Nairobi": return "E. Africa Standard Time";
case "Africa/Windhoek": return "Namibia Standard Time";
case "America/Anchorage": return "Alaskan Standard Time";
case "America/Asuncion": return "Paraguay Standard Time";
case "America/Bahia": return "Bahia Standard Time";
case "America/Bogota": return "SA Pacific Standard Time";
case "America/Buenos_Aires": return "Argentina Standard Time";
case "America/Caracas": return "Venezuela Standard Time";
case "America/Cayenne": return "SA Eastern Standard Time";
case "America/Chicago": return "Central Standard Time";
case "America/Chihuahua": return "Mountain Standard Time (Mexico)";
case "America/Cuiaba": return "Central Brazilian Standard Time";
case "America/Denver": return "Mountain Standard Time";
case "America/Godthab": return "Greenland Standard Time";
case "America/Guatemala": return "Central America Standard Time";
case "America/Halifax": return "Atlantic Standard Time";
case "America/La_Paz": return "SA Western Standard Time";
case "America/Los_Angeles": return "Pacific Standard Time";
case "America/Mexico_City": return "Central Standard Time (Mexico)";
case "America/Montevideo": return "Montevideo Standard Time";
case "America/New_York": return "Eastern Standard Time";
case "America/Phoenix": return "US Mountain Standard Time";
case "America/Regina": return "Canada Central Standard Time";
case "America/Santa_Isabel": return "Pacific Standard Time (Mexico)";
case "America/Santiago": return "Pacific SA Standard Time";
case "America/Sao_Paulo": return "E. South America Standard Time";
case "America/St_Johns": return "Newfoundland Standard Time";
case "Asia/Almaty": return "Central Asia Standard Time";
case "Asia/Amman": return "Jordan Standard Time";
case "Asia/Baghdad": return "Arabic Standard Time";
case "Asia/Baku": return "Azerbaijan Standard Time";
case "Asia/Bangkok": return "SE Asia Standard Time";
case "Asia/Beirut": return "Middle East Standard Time";
case "Asia/Calcutta": return "India Standard Time";
case "Asia/Colombo": return "Sri Lanka Standard Time";
case "Asia/Damascus": return "Syria Standard Time";
case "Asia/Dhaka": return "Bangladesh Standard Time";
case "Asia/Dubai": return "Arabian Standard Time";
case "Asia/Irkutsk": return "North Asia East Standard Time";
case "Asia/Jerusalem": return "Israel Standard Time";
case "Asia/Kabul": return "Afghanistan Standard Time";
case "Asia/Kamchatka": return "Kamchatka Standard Time";
case "Asia/Karachi": return "Pakistan Standard Time";
case "Asia/Katmandu": return "Nepal Standard Time";
case "Asia/Krasnoyarsk": return "North Asia Standard Time";
case "Asia/Magadan": return "Magadan Standard Time";
case "Asia/Novosibirsk": return "N. Central Asia Standard Time";
case "Asia/Rangoon": return "Myanmar Standard Time";
case "Asia/Riyadh": return "Arab Standard Time";
case "Asia/Seoul": return "Korea Standard Time";
case "Asia/Shanghai": return "China Standard Time";
case "Asia/Singapore": return "Singapore Standard Time";
case "Asia/Taipei": return "Taipei Standard Time";
case "Asia/Tashkent": return "West Asia Standard Time";
case "Asia/Tbilisi": return "Georgian Standard Time";
case "Asia/Tehran": return "Iran Standard Time";
case "Asia/Tokyo": return "Tokyo Standard Time";
case "Asia/Ulaanbaatar": return "Ulaanbaatar Standard Time";
case "Asia/Vladivostok": return "Vladivostok Standard Time";
case "Asia/Yakutsk": return "Yakutsk Standard Time";
case "Asia/Yekaterinburg": return "Ekaterinburg Standard Time";
case "Asia/Yerevan": return "Caucasus Standard Time";
case "Atlantic/Azores": return "Azores Standard Time";
case "Atlantic/Cape_Verde": return "Cape Verde Standard Time";
case "Atlantic/Reykjavik": return "Greenwich Standard Time";
case "Australia/Adelaide": return "Cen. Australia Standard Time";
case "Australia/Brisbane": return "E. Australia Standard Time";
case "Australia/Darwin": return "AUS Central Standard Time";
case "Australia/Hobart": return "Tasmania Standard Time";
case "Australia/Perth": return "W. Australia Standard Time";
case "Australia/Sydney": return "AUS Eastern Standard Time";
case "Etc/GMT-12": return "UTC+12";
case "Etc/GMT": return "UTC";
case "Etc/GMT+11": return "UTC-11";
case "Etc/GMT+12": return "Dateline Standard Time";
case "Etc/GMT+2": return "Mid-Atlantic Standard Time";
case "Etc/GMT+5": return "US Eastern Standard Time";
case "Europe/Berlin": return "W. Europe Standard Time";
case "Europe/Budapest": return "Central Europe Standard Time";
//This should probably be Turkey Standard Time, but GTB Standard Time
//has been around longer and therefore will work on more systems.
case "Europe/Istanbul": return "GTB Standard Time";
case "Europe/Kaliningrad": return "Kaliningrad Standard Time";
case "Europe/Kiev": return "FLE Standard Time";
case "Europe/London": return "GMT Standard Time";
case "Europe/Minsk": return "E. Europe Standard Time";
case "Europe/Moscow": return "Russian Standard Time";
case "Europe/Paris": return "Romance Standard Time";
case "Europe/Warsaw": return "Central European Standard Time";
case "Indian/Mauritius": return "Mauritius Standard Time";
case "Pacific/Apia": return "Samoa Standard Time";
case "Pacific/Auckland": return "New Zealand Standard Time";
case "Pacific/Fiji": return "Fiji Standard Time";
case "Pacific/Guadalcanal": return "Central Pacific Standard Time";
case "Pacific/Honolulu": return "Hawaiian Standard Time";
case "Pacific/Port_Moresby": return "West Pacific Standard Time";
case "Pacific/Tongatapu": return "Tonga Standard Time";
default:
throw new DateTimeException(format("Could not find Windows time zone name for: %s.", tzName));
}
}
unittest
{
version(testStdDateTime)
{
version(Windows)
{
static void testTZSuccess(string tzName)
{
scope(failure) writefln("TZName which threw: %s", tzName);
tzDatabaseNameToWindowsTZName(tzName);
}
auto timeZones = TimeZone.getInstalledTZNames();
foreach(tzname; timeZones)
assertNotThrown!DateTimeException(testTZSuccess(tzname));
}
}
}
/++
Converts the given Windows time zone name to a corresponding TZ Database
name.
See_Also:
$(WEB unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html,
Windows <-> TZ Database Name Conversion Table)
Params:
tzName = The TZ Database name to convert.
Throws:
$(D DateTimeException) if the given $(D_PARAM tzName) cannot be
converted.
+/
string windowsTZNameToTZDatabaseName(string tzName)
{
switch(tzName)
{
//Most of these come from the link in the documentation, but a few have
//been added because they were found in the Windows registry.
case "AUS Central Standard Time": return "Australia/Darwin";
case "AUS Eastern Standard Time": return "Australia/Sydney";
case "Afghanistan Standard Time": return "Asia/Kabul";
case "Alaskan Standard Time": return "America/Anchorage";
case "Arab Standard Time": return "Asia/Riyadh";
case "Arabian Standard Time": return "Asia/Dubai";
case "Arabic Standard Time": return "Asia/Baghdad";
case "Argentina Standard Time": return "America/Buenos_Aires";
case "Armenian Standard Time": return "Asia/Yerevan";
case "Atlantic Standard Time": return "America/Halifax";
case "Azerbaijan Standard Time": return "Asia/Baku";
case "Azores Standard Time": return "Atlantic/Azores";
case "Bahia Standard Time": return "America/Bahia";
case "Bangladesh Standard Time": return "Asia/Dhaka";
case "Canada Central Standard Time": return "America/Regina";
case "Cape Verde Standard Time": return "Atlantic/Cape_Verde";
case "Caucasus Standard Time": return "Asia/Yerevan";
case "Cen. Australia Standard Time": return "Australia/Adelaide";
case "Central America Standard Time": return "America/Guatemala";
case "Central Asia Standard Time": return "Asia/Almaty";
case "Central Brazilian Standard Time": return "America/Cuiaba";
case "Central Europe Standard Time": return "Europe/Budapest";
case "Central European Standard Time": return "Europe/Warsaw";
case "Central Pacific Standard Time": return "Pacific/Guadalcanal";
case "Central Standard Time": return "America/Chicago";
case "Central Standard Time (Mexico)": return "America/Mexico_City";
case "China Standard Time": return "Asia/Shanghai";
case "Dateline Standard Time": return "Etc/GMT+12";
case "E. Africa Standard Time": return "Africa/Nairobi";
case "E. Australia Standard Time": return "Australia/Brisbane";
case "E. Europe Standard Time": return "Europe/Minsk";
case "E. South America Standard Time": return "America/Sao_Paulo";
case "Eastern Standard Time": return "America/New_York";
case "Egypt Standard Time": return "Africa/Cairo";
case "Ekaterinburg Standard Time": return "Asia/Yekaterinburg";
case "FLE Standard Time": return "Europe/Kiev";
case "Fiji Standard Time": return "Pacific/Fiji";
case "GMT Standard Time": return "Europe/London";
case "GTB Standard Time": return "Europe/Istanbul";
case "Georgian Standard Time": return "Asia/Tbilisi";
case "Greenland Standard Time": return "America/Godthab";
case "Greenwich Standard Time": return "Atlantic/Reykjavik";
case "Hawaiian Standard Time": return "Pacific/Honolulu";
case "India Standard Time": return "Asia/Calcutta";
case "Iran Standard Time": return "Asia/Tehran";
case "Israel Standard Time": return "Asia/Jerusalem";
case "Jordan Standard Time": return "Asia/Amman";
case "Kaliningrad Standard Time": return "Europe/Kaliningrad";
case "Kamchatka Standard Time": return "Asia/Kamchatka";
case "Korea Standard Time": return "Asia/Seoul";
case "Magadan Standard Time": return "Asia/Magadan";
case "Mauritius Standard Time": return "Indian/Mauritius";
case "Mexico Standard Time": return "America/Mexico_City";
case "Mexico Standard Time 2": return "America/Chihuahua";
case "Mid-Atlantic Standard Time": return "Etc/GMT+2";
case "Middle East Standard Time": return "Asia/Beirut";
case "Montevideo Standard Time": return "America/Montevideo";
case "Morocco Standard Time": return "Africa/Casablanca";
case "Mountain Standard Time": return "America/Denver";
case "Mountain Standard Time (Mexico)": return "America/Chihuahua";
case "Myanmar Standard Time": return "Asia/Rangoon";
case "N. Central Asia Standard Time": return "Asia/Novosibirsk";
case "Namibia Standard Time": return "Africa/Windhoek";
case "Nepal Standard Time": return "Asia/Katmandu";
case "New Zealand Standard Time": return "Pacific/Auckland";
case "Newfoundland Standard Time": return "America/St_Johns";
case "North Asia East Standard Time": return "Asia/Irkutsk";
case "North Asia Standard Time": return "Asia/Krasnoyarsk";
case "Pacific SA Standard Time": return "America/Santiago";
case "Pacific Standard Time": return "America/Los_Angeles";
case "Pacific Standard Time (Mexico)": return "America/Santa_Isabel";
case "Pakistan Standard Time": return "Asia/Karachi";
case "Paraguay Standard Time": return "America/Asuncion";
case "Romance Standard Time": return "Europe/Paris";
case "Russian Standard Time": return "Europe/Moscow";
case "SA Eastern Standard Time": return "America/Cayenne";
case "SA Pacific Standard Time": return "America/Bogota";
case "SA Western Standard Time": return "America/La_Paz";
case "SE Asia Standard Time": return "Asia/Bangkok";
case "Samoa Standard Time": return "Pacific/Apia";
case "Singapore Standard Time": return "Asia/Singapore";
case "South Africa Standard Time": return "Africa/Johannesburg";
case "Sri Lanka Standard Time": return "Asia/Colombo";
case "Syria Standard Time": return "Asia/Damascus";
case "Taipei Standard Time": return "Asia/Taipei";
case "Tasmania Standard Time": return "Australia/Hobart";
case "Tokyo Standard Time": return "Asia/Tokyo";
case "Tonga Standard Time": return "Pacific/Tongatapu";
case "Turkey Standard Time": return "Europe/Istanbul";
case "US Eastern Standard Time": return "Etc/GMT+5";
case "US Mountain Standard Time": return "America/Phoenix";
case "UTC": return "Etc/GMT";
case "UTC+12": return "Etc/GMT-12";
case "UTC-02": return "Etc/GMT+2";
case "UTC-11": return "Etc/GMT+11";
case "Ulaanbaatar Standard Time": return "Asia/Ulaanbaatar";
case "Venezuela Standard Time": return "America/Caracas";
case "Vladivostok Standard Time": return "Asia/Vladivostok";
case "W. Australia Standard Time": return "Australia/Perth";
case "W. Central Africa Standard Time": return "Africa/Lagos";
case "W. Europe Standard Time": return "Europe/Berlin";
case "West Asia Standard Time": return "Asia/Tashkent";
case "West Pacific Standard Time": return "Pacific/Port_Moresby";
case "Yakutsk Standard Time": return "Asia/Yakutsk";
default:
throw new DateTimeException(format("Could not find TZ Database name for: %s.", tzName));
}
}
unittest
{
version(testStdDateTime)
{
version(Windows)
{
static void testTZSuccess(string tzName)
{
scope(failure) writefln("TZName which threw: %s", tzName);
windowsTZNameToTZDatabaseName(tzName);
}
auto timeZones = WindowsTimeZone.getInstalledTZNames();
foreach(tzname; timeZones)
assertNotThrown!DateTimeException(testTZSuccess(tzname));
}
}
}
//==============================================================================
// Section with StopWatch and Benchmark Code.
//==============================================================================
/++
$(D StopWatch) measures time as precisely as possible.
This class uses a high-performance counter. On Windows systems, it uses
$(D QueryPerformanceCounter), and on Posix systems, it uses
$(D clock_gettime) if available, and $(D gettimeofday) otherwise.
But the precision of $(D StopWatch) differs from system to system. It is
impossible to for it to be the same from system to system since the precision
of the system clock varies from system to system, and other system-dependent
and situation-dependent stuff (such as the overhead of a context switch
between threads) can also affect $(D StopWatch)'s accuracy.
Examples:
--------------------
void foo()
{
StopWatch sw;
enum n = 100;
TickDuration[n] times;
TickDuration last = TickDuration.from!"seconds"(0);
foreach(i; 0..n)
{
sw.start(); //start/resume mesuring.
foreach(unused; 0..1_000_000)
bar();
sw.stop(); //stop/pause measuring.
//Return value of peek() after having stopped are the always same.
writeln((i + 1) * 1_000_000, " times done, lap time: ",
sw.peek().msecs, "[ms]");
times[i] = sw.peek() - last;
last = sw.peek();
}
real sum = 0;
// To know the number of seconds,
// use properties of TickDuration.
// (seconds, msecs, usecs, hnsecs)
foreach(t; times)
sum += t.hnsecs;
writeln("Average time: ", sum/n, " hnsecs");
}
--------------------
+/
@safe struct StopWatch
{
public:
//Verify Example
@safe unittest
{
void writeln(S...)(S args){}
static void bar() {}
StopWatch sw;
enum n = 100;
TickDuration[n] times;
TickDuration last = TickDuration.from!"seconds"(0);
foreach(i; 0..n)
{
sw.start(); //start/resume mesuring.
foreach(unused; 0..1_000_000)
bar();
sw.stop(); //stop/pause measuring.
//Return value of peek() after having stopped are the always same.
writeln((i + 1) * 1_000_000, " times done, lap time: ",
sw.peek().msecs, "[ms]");
times[i] = sw.peek() - last;
last = sw.peek();
}
real sum = 0;
// To get the number of seconds,
// use properties of TickDuration.
// (seconds, msecs, usecs, hnsecs)
foreach(t; times)
sum += t.hnsecs;
writeln("Average time: ", sum/n, " hnsecs");
}
/++
Auto start with constructor.
+/
this(AutoStart autostart)
{
if(autostart)
start();
}
version(testStdDateTime) @safe unittest
{
auto sw = StopWatch(AutoStart.yes);
sw.stop();
}
///
bool opEquals(const StopWatch rhs) const pure nothrow
{
return opEquals(rhs);
}
/// ditto
bool opEquals(const ref StopWatch rhs) const pure nothrow
{
return _timeStart == rhs._timeStart &&
_timeMeasured == rhs._timeMeasured;
}
/++
Resets the stop watch.
+/
void reset()
{
if(_flagStarted)
{
// Set current system time if StopWatch is measuring.
_timeStart = Clock.currSystemTick;
}
else
{
// Set zero if StopWatch is not measuring.
_timeStart.length = 0;
}
_timeMeasured.length = 0;
}
version(testStdDateTime) @safe unittest
{
StopWatch sw;
sw.start();
sw.stop();
sw.reset();
assert(sw.peek().to!("seconds", real)() == 0);
}
/++
Starts the stop watch.
+/
void start()
{
assert(!_flagStarted);
_flagStarted = true;
_timeStart = Clock.currSystemTick;
}
version(testStdDateTime) @trusted unittest
{
StopWatch sw;
sw.start();
auto t1 = sw.peek();
bool doublestart = true;
try
sw.start();
catch(AssertError e)
doublestart = false;
assert(!doublestart);
sw.stop();
assert((t1 - sw.peek()).to!("seconds", real)() <= 0);
}
/++
Stops the stop watch.
+/
void stop()
{
assert(_flagStarted);
_flagStarted = false;
_timeMeasured += Clock.currSystemTick - _timeStart;
}
version(testStdDateTime) @trusted unittest
{
StopWatch sw;
sw.start();
sw.stop();
auto t1 = sw.peek();
bool doublestop = true;
try
sw.stop();
catch(AssertError e)
doublestop = false;
assert(!doublestop);
assert((t1 - sw.peek()).to!("seconds", real)() == 0);
}
/++
Peek at the amount of time which has passed since the stop watch was
started.
+/
TickDuration peek() const
{
if(_flagStarted)
return Clock.currSystemTick - _timeStart + _timeMeasured;
return _timeMeasured;
}
version(testStdDateTime) @safe unittest
{
StopWatch sw;
sw.start();
auto t1 = sw.peek();
sw.stop();
auto t2 = sw.peek();
auto t3 = sw.peek();
assert(t1 <= t2);
assert(t2 == t3);
}
/++
Set the amount of time which has been measured since the stop watch was
started.
+/
void setMeasured(TickDuration d)
{
reset();
_timeMeasured = d;
}
version(testStdDateTime) @safe unittest
{
StopWatch sw;
TickDuration t0;
t0.length = 100;
sw.setMeasured(t0);
auto t1 = sw.peek();
assert(t0 == t1);
}
/++
Confirm whether this stopwatch is measuring time.
+/
bool running() @property const pure nothrow
{
return _flagStarted;
}
version(testStdDateTime) @safe unittest
{
StopWatch sw1;
assert(!sw1.running);
sw1.start();
assert(sw1.running);
sw1.stop();
assert(!sw1.running);
StopWatch sw2 = AutoStart.yes;
assert(sw2.running);
sw2.stop();
assert(!sw2.running);
sw2.start();
assert(sw2.running);
}
private:
// true if observing.
bool _flagStarted = false;
// TickDuration at the time of StopWatch starting measurement.
TickDuration _timeStart;
// Total time that StopWatch ran.
TickDuration _timeMeasured;
}
// workaround for bug4886
@safe size_t lengthof(aliases...)() pure nothrow
{
return aliases.length;
}
/++
Benchmarks code for speed assessment and comparison.
Params:
fun = aliases of callable objects (e.g. function names). Each should
take no arguments.
n = The number of times each function is to be executed.
Returns:
The amount of time (as a $(CXREF time, TickDuration)) that it took to
call each function $(D n) times. The first value is the length of time
that it took to call $(D fun[0]) $(D n) times. The second value is the
length of time it took to call $(D fun[1]) $(D n) times. Etc.
Examples:
--------------------
int a;
void f0() {}
void f1() {auto b = a;}
void f2() {auto b = to!(string)(a);}
auto r = benchmark!(f0, f1, f2)(10_000);
writefln("Milliseconds to call fun[0] n times: %s", r[0].to!("msecs", int));
--------------------
+/
TickDuration[lengthof!(fun)()] benchmark(fun...)(uint n)
{
TickDuration[lengthof!(fun)()] result;
StopWatch sw;
sw.start();
foreach(i, unused; fun)
{
sw.reset();
foreach(j; 0 .. n)
fun[i]();
result[i] = sw.peek();
}
return result;
}
//Verify Examples.
version(testStdDateTime) unittest
{
void writefln(S...)(S args){}
int a;
void f0() {}
void f1() {auto b = a;}
void f2() {auto b = to!(string)(a);}
auto r = benchmark!(f0, f1, f2)(10_000);
writefln("Milliseconds to call fun[0] n times: %s", r[0].to!("msecs", int)());
}
version(testStdDateTime) @safe unittest
{
int a;
void f0() {}
//void f1() {auto b = to!(string)(a);}
void f2() {auto b = (a);}
auto r = benchmark!(f0, f2)(100);
}
/++
Return value of benchmark with two functions comparing.
+/
@safe struct ComparingBenchmarkResult
{
/++
Evaluation value
This returns the evaluation value of performance as the ratio of
baseFunc's time over targetFunc's time. If performance is high, this
returns a high value.
+/
@property real point() const pure nothrow
{
return _baseTime.length / cast(const real)_targetTime.length;
}
/++
The time required of the base function
+/
@property public TickDuration baseTime() const pure nothrow
{
return _baseTime;
}
/++
The time required of the target function
+/
@property public TickDuration targetTime() const pure nothrow
{
return _targetTime;
}
private:
this(TickDuration baseTime, TickDuration targetTime) pure nothrow
{
_baseTime = baseTime;
_targetTime = targetTime;
}
TickDuration _baseTime;
TickDuration _targetTime;
}
/++
Benchmark with two functions comparing.
Params:
baseFunc = The function to become the base of the speed.
targetFunc = The function that wants to measure speed.
times = The number of times each function is to be executed.
Examples:
--------------------
void f1() {
// ...
}
void f2() {
// ...
}
void main() {
auto b = comparingBenchmark!(f1, f2, 0x80);
writeln(b.point);
}
--------------------
+/
ComparingBenchmarkResult comparingBenchmark(alias baseFunc,
alias targetFunc,
int times = 0xfff)()
{
auto t = benchmark!(baseFunc, targetFunc)(times);
return ComparingBenchmarkResult(t[0], t[1]);
}
version(testStdDateTime) @safe unittest
{
void f1x() {}
void f2x() {}
@safe void f1o() {}
@safe void f2o() {}
auto b1 = comparingBenchmark!(f1o, f2o, 1)(); // OK
//static auto b2 = comparingBenchmark!(f1x, f2x, 1); // NG
}
version(testStdDateTime) unittest
{
void f1x() {}
void f2x() {}
@safe void f1o() {}
@safe void f2o() {}
auto b1 = comparingBenchmark!(f1o, f2o, 1)(); // OK
auto b2 = comparingBenchmark!(f1x, f2x, 1)(); // OK
}
//Bug# 8450
version(testStdDateTime) unittest
{
@safe void safeFunc() {}
@trusted void trustFunc() {}
@system void sysFunc() {}
auto safeResult = comparingBenchmark!((){safeFunc();}, (){safeFunc();})();
auto trustResult = comparingBenchmark!((){trustFunc();}, (){trustFunc();})();
auto sysResult = comparingBenchmark!((){sysFunc();}, (){sysFunc();})();
auto mixedResult1 = comparingBenchmark!((){safeFunc();}, (){trustFunc();})();
auto mixedResult2 = comparingBenchmark!((){trustFunc();}, (){sysFunc();})();
auto mixedResult3 = comparingBenchmark!((){safeFunc();}, (){sysFunc();})();
}
//==============================================================================
// Section with public helper functions and templates.
//==============================================================================
/++
Whether the given type defines all of the necessary functions for it to
function as a time point.
+/
template isTimePoint(T)
{
enum isTimePoint = hasMin!T &&
hasMax!T &&
hasOverloadedOpBinaryWithDuration!T &&
hasOverloadedOpAssignWithDuration!T &&
hasOverloadedOpBinaryWithSelf!T;
}
unittest
{
version(testStdDateTime)
{
static assert(isTimePoint!(Date));
static assert(isTimePoint!(DateTime));
static assert(isTimePoint!(TimeOfDay));
static assert(isTimePoint!(SysTime));
static assert(isTimePoint!(const Date));
static assert(isTimePoint!(const DateTime));
static assert(isTimePoint!(const TimeOfDay));
static assert(isTimePoint!(const SysTime));
static assert(isTimePoint!(immutable Date));
static assert(isTimePoint!(immutable DateTime));
static assert(isTimePoint!(immutable TimeOfDay));
static assert(isTimePoint!(immutable SysTime));
}
}
/++
Whether the given Gregorian Year is a leap year.
Params:
year = The year to to be tested.
+/
static bool yearIsLeapYear(int year) pure nothrow
{
if(year % 400 == 0)
return true;
if(year % 100 == 0)
return false;
return year % 4 == 0;
}
version(testStdDateTime) unittest
{
foreach(year; [1, 2, 3, 5, 6, 7, 100, 200, 300, 500, 600, 700, 1998, 1999,
2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010, 2011])
{
assert(!yearIsLeapYear(year), format("year: %s.", year));
assert(!yearIsLeapYear(-year), format("year: %s.", year));
}
foreach(year; [0, 4, 8, 400, 800, 1600, 1996, 2000, 2004, 2008, 2012])
{
assert(yearIsLeapYear(year), format("year: %s.", year));
assert(yearIsLeapYear(-year), format("year: %s.", year));
}
}
/++
Converts a $(D time_t) (which uses midnight, January 1st, 1970 UTC as its
epoch and seconds as its units) to std time (which uses midnight,
January 1st, 1 A.D. UTC and hnsecs as its units).
Params:
unixTime = The $(D time_t) to convert.
+/
long unixTimeToStdTime(time_t unixTime) pure nothrow
{
return 621_355_968_000_000_000L + convert!("seconds", "hnsecs")(unixTime);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(unixTimeToStdTime(0), 621_355_968_000_000_000L); //Midnight, January 1st, 1970
_assertPred!"=="(unixTimeToStdTime(86_400), 621_355_968_000_000_000L + 864_000_000_000L); //Midnight, January 2nd, 1970
_assertPred!"=="(unixTimeToStdTime(-86_400), 621_355_968_000_000_000L - 864_000_000_000L); //Midnight, December 31st, 1969
_assertPred!"=="(unixTimeToStdTime(0), (Date(1970, 1, 1) - Date(1, 1, 1)).total!"hnsecs");
_assertPred!"=="(unixTimeToStdTime(0), (DateTime(1970, 1, 1) - DateTime(1, 1, 1)).total!"hnsecs");
}
}
/++
Converts std time (which uses midnight, January 1st, 1 A.D. UTC as its epoch
and hnsecs as its units) to $(D time_t) (which uses midnight, January 1st,
1970 UTC as its epoch and seconds as its units). If $(D time_t) is 32 bits,
rather than 64, and the result can't fit in a 32-bit value, then the closest
value that can be held in 32 bits will be used (so $(D time_t.max) if it
goes over and $(D time_t.min) if it goes under).
Note:
While Windows systems require that $(D time_t) be non-negative (in spite
of $(D time_t) being signed), this function still returns negative
numbers on Windows, since it's more flexible to allow negative time_t
for those who need it. If on Windows and using the
standard C functions or Win32 API functions which take a $(D time_t),
check whether the return value of
$(D stdTimeToUnixTime) is non-negative.
Params:
stdTime = The std time to convert.
+/
time_t stdTimeToUnixTime(long stdTime) pure nothrow
{
immutable unixTime = convert!("hnsecs", "seconds")(stdTime - 621_355_968_000_000_000L);
static if(time_t.sizeof >= long.sizeof)
return cast(time_t)unixTime;
else
{
if(unixTime > 0)
{
if(unixTime > time_t.max)
return time_t.max;
return cast(time_t)unixTime;
}
if(unixTime < time_t.min)
return time_t.min;
return cast(time_t)unixTime;
}
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(stdTimeToUnixTime(621_355_968_000_000_000L), 0); //Midnight, January 1st, 1970
_assertPred!"=="(stdTimeToUnixTime(621_355_968_000_000_000L + 864_000_000_000L), 86_400); //Midnight, January 2nd, 1970
_assertPred!"=="(stdTimeToUnixTime(621_355_968_000_000_000L - 864_000_000_000L), -86_400); //Midnight, December 31st, 1969
_assertPred!"=="(stdTimeToUnixTime((Date(1970, 1, 1) - Date(1, 1, 1)).total!"hnsecs"), 0);
_assertPred!"=="(stdTimeToUnixTime((DateTime(1970, 1, 1) - DateTime(1, 1, 1)).total!"hnsecs"), 0);
}
}
version(StdDdoc)
{
version(Windows) {}
else
{
alias void* SYSTEMTIME;
alias void* FILETIME;
}
/++
$(BLUE This function is Windows-Only.)
Converts a $(D SYSTEMTIME) struct to a $(D SysTime).
Params:
st = The $(D SYSTEMTIME) struct to convert.
tz = The time zone that the time in the $(D SYSTEMTIME) struct is
assumed to be (if the $(D SYSTEMTIME) was supplied by a Windows
system call, the $(D SYSTEMTIME) will either be in local time
or UTC, depending on the call).
Throws:
$(D DateTimeException) if the given $(D SYSTEMTIME) will not fit in
a $(D SysTime), which is highly unlikely to happen given that
$(D SysTime.max) is in 29,228 A.D. and the maximum $(D SYSTEMTIME)
is in 30,827 A.D.
+/
SysTime SYSTEMTIMEToSysTime(const SYSTEMTIME* st, immutable TimeZone tz = LocalTime());
/++
$(BLUE This function is Windows-Only.)
Converts a $(D SysTime) to a $(D SYSTEMTIME) struct.
The $(D SYSTEMTIME) which is returned will be set using the given
$(D SysTime)'s time zone, so to get the $(D SYSTEMTIME) in
UTC, set the $(D SysTime)'s time zone to UTC.
Params:
sysTime = The $(D SysTime) to convert.
Throws:
$(D DateTimeException) if the given $(D SysTime) will not fit in a
$(D SYSTEMTIME). This will only happen if the $(D SysTime)'s date is
prior to 1601 A.D.
+/
SYSTEMTIME SysTimeToSYSTEMTIME(in SysTime sysTime);
/++
$(BLUE This function is Windows-Only.)
Converts a $(D FILETIME) struct to the number of hnsecs since midnight,
January 1st, 1 A.D.
Params:
ft = The $(D FILETIME) struct to convert.
Throws:
$(D DateTimeException) if the given $(D FILETIME) cannot be
represented as the return value.
+/
long FILETIMEToStdTime(const FILETIME* ft);
/++
$(BLUE This function is Windows-Only.)
Converts a $(D FILETIME) struct to a $(D SysTime).
Params:
ft = The $(D FILETIME) struct to convert.
tz = The time zone that the $(D SysTime) will be in ($(D FILETIME)s
are in UTC).
Throws:
$(D DateTimeException) if the given $(D FILETIME) will not fit in a
$(D SysTime).
+/
SysTime FILETIMEToSysTime(const FILETIME* ft, immutable TimeZone tz = LocalTime());
/++
$(BLUE This function is Windows-Only.)
Converts a number of hnsecs since midnight, January 1st, 1 A.D. to a
$(D FILETIME) struct.
Params:
sysTime = The $(D SysTime) to convert.
Throws:
$(D DateTimeException) if the given value will not fit in a
$(D FILETIME).
+/
FILETIME stdTimeToFILETIME(long stdTime);
/++
$(BLUE This function is Windows-Only.)
Converts a $(D SysTime) to a $(D FILETIME) struct.
$(D FILETIME)s are always in UTC.
Params:
sysTime = The $(D SysTime) to convert.
Throws:
$(D DateTimeException) if the given $(D SysTime) will not fit in a
$(D FILETIME).
+/
FILETIME SysTimeToFILETIME(SysTime sysTime);
}
else version(Windows)
{
SysTime SYSTEMTIMEToSysTime(const SYSTEMTIME* st, immutable TimeZone tz = LocalTime())
{
const max = SysTime.max;
static void throwLaterThanMax()
{
throw new DateTimeException("The given SYSTEMTIME is for a date greater than SysTime.max.");
}
if(st.wYear > max.year)
throwLaterThanMax();
else if(st.wYear == max.year)
{
if(st.wMonth > max.month)
throwLaterThanMax();
else if(st.wMonth == max.month)
{
if(st.wDay > max.day)
throwLaterThanMax();
else if(st.wDay == max.day)
{
if(st.wHour > max.hour)
throwLaterThanMax();
else if(st.wHour == max.hour)
{
if(st.wMinute > max.minute)
throwLaterThanMax();
else if(st.wMinute == max.minute)
{
if(st.wSecond > max.second)
throwLaterThanMax();
else if(st.wSecond == max.second)
{
if(st.wMilliseconds > max.fracSec.msecs)
throwLaterThanMax();
}
}
}
}
}
}
auto dt = DateTime(st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond);
return SysTime(dt, FracSec.from!"msecs"(st.wMilliseconds), tz);
}
unittest
{
version(testStdDateTime)
{
auto sysTime = Clock.currTime(UTC());
SYSTEMTIME st = void;
GetSystemTime(&st);
auto converted = SYSTEMTIMEToSysTime(&st, UTC());
_assertPred!"<="(abs((converted - sysTime)),
dur!"seconds"(2));
}
}
SYSTEMTIME SysTimeToSYSTEMTIME(in SysTime sysTime)
{
immutable dt = cast(DateTime)sysTime;
if(dt.year < 1601)
throw new DateTimeException("SYSTEMTIME cannot hold dates prior to the year 1601.");
SYSTEMTIME st;
st.wYear = dt.year;
st.wMonth = dt.month;
st.wDayOfWeek = dt.dayOfWeek;
st.wDay = dt.day;
st.wHour = dt.hour;
st.wMinute = dt.minute;
st.wSecond = dt.second;
st.wMilliseconds = cast(ushort)sysTime.fracSec.msecs;
return st;
}
unittest
{
version(testStdDateTime)
{
SYSTEMTIME st = void;
GetSystemTime(&st);
auto sysTime = SYSTEMTIMEToSysTime(&st, UTC());
SYSTEMTIME result = SysTimeToSYSTEMTIME(sysTime);
_assertPred!"=="(st.wYear, result.wYear);
_assertPred!"=="(st.wMonth, result.wMonth);
_assertPred!"=="(st.wDayOfWeek, result.wDayOfWeek);
_assertPred!"=="(st.wDay, result.wDay);
_assertPred!"=="(st.wHour, result.wHour);
_assertPred!"=="(st.wMinute, result.wMinute);
_assertPred!"=="(st.wSecond, result.wSecond);
_assertPred!"=="(st.wMilliseconds, result.wMilliseconds);
}
}
private enum hnsecsFrom1601 = 504_911_232_000_000_000L;
long FILETIMEToStdTime(const FILETIME* ft)
{
ULARGE_INTEGER ul;
ul.HighPart = ft.dwHighDateTime;
ul.LowPart = ft.dwLowDateTime;
ulong tempHNSecs = ul.QuadPart;
if(tempHNSecs > long.max - hnsecsFrom1601)
throw new DateTimeException("The given FILETIME cannot be represented as a stdTime value.");
return cast(long)tempHNSecs + hnsecsFrom1601;
}
SysTime FILETIMEToSysTime(const FILETIME* ft, immutable TimeZone tz = LocalTime())
{
auto sysTime = SysTime(FILETIMEToStdTime(ft), UTC());
sysTime.timezone = tz;
return sysTime;
}
unittest
{
version(testStdDateTime)
{
auto sysTime = Clock.currTime(UTC());
SYSTEMTIME st = void;
GetSystemTime(&st);
FILETIME ft = void;
SystemTimeToFileTime(&st, &ft);
auto converted = FILETIMEToSysTime(&ft);
_assertPred!"<="(abs((converted - sysTime)),
dur!"seconds"(2));
}
}
FILETIME stdTimeToFILETIME(long stdTime)
{
if(stdTime < hnsecsFrom1601)
throw new DateTimeException("The given stdTime value cannot be represented as a FILETIME.");
ULARGE_INTEGER ul;
ul.QuadPart = cast(ulong)stdTime - hnsecsFrom1601;
FILETIME ft;
ft.dwHighDateTime = ul.HighPart;
ft.dwLowDateTime = ul.LowPart;
return ft;
}
FILETIME SysTimeToFILETIME(SysTime sysTime)
{
return stdTimeToFILETIME(sysTime.stdTime);
}
unittest
{
version(testStdDateTime)
{
SYSTEMTIME st = void;
GetSystemTime(&st);
FILETIME ft = void;
SystemTimeToFileTime(&st, &ft);
auto sysTime = FILETIMEToSysTime(&ft, UTC());
FILETIME result = SysTimeToFILETIME(sysTime);
_assertPred!"=="(ft.dwLowDateTime, result.dwLowDateTime);
_assertPred!"=="(ft.dwHighDateTime, result.dwHighDateTime);
}
}
}
/++
Type representing the DOS file date/time format.
+/
alias uint DosFileTime;
/++
Converts from DOS file date/time to $(D SysTime).
Params:
dft = The DOS file time to convert.
tz = The time zone which the DOS file time is assumed to be in.
Throws:
$(D DateTimeException) if the $(D DosFileTime) is invalid.
+/
SysTime DosFileTimeToSysTime(DosFileTime dft, immutable TimeZone tz = LocalTime())
{
uint dt = cast(uint)dft;
if(dt == 0)
throw new DateTimeException("Invalid DosFileTime.");
int year = ((dt >> 25) & 0x7F) + 1980;
int month = ((dt >> 21) & 0x0F); // 1..12
int dayOfMonth = ((dt >> 16) & 0x1F); // 1..31
int hour = (dt >> 11) & 0x1F; // 0..23
int minute = (dt >> 5) & 0x3F; // 0..59
int second = (dt << 1) & 0x3E; // 0..58 (in 2 second increments)
SysTime sysTime = void;
try
return SysTime(DateTime(year, month, dayOfMonth, hour, minute, second), tz);
catch(DateTimeException dte)
throw new DateTimeException("Invalid DosFileTime", __FILE__, __LINE__, dte);
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(DosFileTimeToSysTime(0b00000000001000010000000000000000),
SysTime(DateTime(1980, 1, 1, 0, 0, 0)));
_assertPred!"=="(DosFileTimeToSysTime(0b11111111100111111011111101111101),
SysTime(DateTime(2107, 12, 31, 23, 59, 58)));
_assertPred!"=="(DosFileTimeToSysTime(0x3E3F8456),
SysTime(DateTime(2011, 1, 31, 16, 34, 44)));
}
}
/++
Converts from $(D SysTime) to DOS file date/time.
Params:
sysTime = The $(D SysTime) to convert.
Throws:
$(D DateTimeException) if the given $(D SysTime) cannot be converted to
a $(D DosFileTime).
+/
DosFileTime SysTimeToDosFileTime(SysTime sysTime)
{
auto dateTime = cast(DateTime)sysTime;
if(dateTime.year < 1980)
throw new DateTimeException("DOS File Times cannot hold dates prior to 1980.");
if(dateTime.year > 2107)
throw new DateTimeException("DOS File Times cannot hold dates passed 2107.");
uint retval = 0;
retval = (dateTime.year - 1980) << 25;
retval |= (dateTime.month & 0x0F) << 21;
retval |= (dateTime.day & 0x1F) << 16;
retval |= (dateTime.hour & 0x1F) << 11;
retval |= (dateTime.minute & 0x3F) << 5;
retval |= (dateTime.second >> 1) & 0x1F;
return cast(DosFileTime)retval;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(SysTimeToDosFileTime(SysTime(DateTime(1980, 1, 1, 0, 0, 0))),
0b00000000001000010000000000000000);
_assertPred!"=="(SysTimeToDosFileTime(SysTime(DateTime(2107, 12, 31, 23, 59, 58))),
0b11111111100111111011111101111101);
_assertPred!"=="(SysTimeToDosFileTime(SysTime(DateTime(2011, 1, 31, 16, 34, 44))),
0x3E3F8456);
}
}
/++
Whether all of the given strings are valid units of time.
$(D "nsecs") is not considered a valid unit of time. Nothing in std.datetime
can handle precision greater than hnsecs, and the few functions in core.time
which deal with "nsecs" deal with it explicitly.
+/
bool validTimeUnits(string[] units...)
{
foreach(str; units)
{
if(!canFind(timeStrings.dup, str))
return false;
}
return true;
}
/++
Compares two time unit strings. $(D "years") are the largest units and
$(D "hnsecs") are the smallest.
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
Throws:
$(D DateTimeException) if either of the given strings is not a valid
time unit string.
+/
int cmpTimeUnits(string lhs, string rhs)
{
auto tstrings = timeStrings.dup;
immutable indexOfLHS = countUntil(tstrings, lhs);
immutable indexOfRHS = countUntil(tstrings, rhs);
enforce(indexOfLHS != -1, format("%s is not a valid TimeString", lhs));
enforce(indexOfRHS != -1, format("%s is not a valid TimeString", rhs));
if(indexOfLHS < indexOfRHS)
return -1;
if(indexOfLHS > indexOfRHS)
return 1;
return 0;
}
unittest
{
version(testStdDateTime)
{
foreach(i, outerUnits; timeStrings)
{
_assertPred!"=="(cmpTimeUnits(outerUnits, outerUnits), 0);
//For some reason, $ won't compile.
foreach(innerUnits; timeStrings[i+1 .. timeStrings.length])
_assertPred!"=="(cmpTimeUnits(outerUnits, innerUnits), -1);
}
foreach(i, outerUnits; timeStrings)
{
foreach(innerUnits; timeStrings[0 .. i])
_assertPred!"=="(cmpTimeUnits(outerUnits, innerUnits), 1);
}
}
}
/++
Compares two time unit strings at compile time. $(D "years") are the largest
units and $(D "hnsecs") are the smallest.
This template is used instead of $(D cmpTimeUnits) because exceptions
can't be thrown at compile time and $(D cmpTimeUnits) must enforce that
the strings it's given are valid time unit strings. This template uses a
template constraint instead.
Returns:
$(BOOKTABLE,
$(TR $(TD this < rhs) $(TD < 0))
$(TR $(TD this == rhs) $(TD 0))
$(TR $(TD this > rhs) $(TD > 0))
)
+/
template CmpTimeUnits(string lhs, string rhs)
if(validTimeUnits(lhs, rhs))
{
enum CmpTimeUnits = cmpTimeUnitsCTFE(lhs, rhs);
}
/+
Helper function for $(D CmpTimeUnits).
+/
private int cmpTimeUnitsCTFE(string lhs, string rhs)
{
auto tstrings = timeStrings.dup;
immutable indexOfLHS = countUntil(tstrings, lhs);
immutable indexOfRHS = countUntil(tstrings, rhs);
if(indexOfLHS < indexOfRHS)
return -1;
if(indexOfLHS > indexOfRHS)
return 1;
return 0;
}
unittest
{
version(testStdDateTime)
{
static string genTest(size_t index)
{
auto currUnits = timeStrings[index];
auto test = `_assertPred!"=="(CmpTimeUnits!("` ~ currUnits ~ `", "` ~ currUnits ~ `"), 0); `;
//For some reason, $ won't compile.
foreach(units; timeStrings[index + 1 .. timeStrings.length])
test ~= `_assertPred!"=="(CmpTimeUnits!("` ~ currUnits ~ `", "` ~ units ~ `"), -1); `;
foreach(units; timeStrings[0 .. index])
test ~= `_assertPred!"=="(CmpTimeUnits!("` ~ currUnits ~ `", "` ~ units ~ `"), 1); `;
return test;
}
mixin(genTest(0));
mixin(genTest(1));
mixin(genTest(2));
mixin(genTest(3));
mixin(genTest(4));
mixin(genTest(5));
mixin(genTest(6));
mixin(genTest(7));
mixin(genTest(8));
mixin(genTest(9));
}
}
/++
Returns whether the given value is valid for the given unit type when in a
time point. Naturally, a duration is not held to a particular range, but
the values in a time point are (e.g. a month must be in the range of
1 - 12 inclusive).
Params:
units = The units of time to validate.
value = The number to validate.
Examples:
--------------------
assert(valid!"hours"(12));
assert(!valid!"hours"(32));
assert(valid!"months"(12));
assert(!valid!"months"(13));
--------------------
+/
bool valid(string units)(int value) pure nothrow
if(units == "months" ||
units == "hours" ||
units == "minutes" ||
units == "seconds")
{
static if(units == "months")
return value >= Month.jan && value <= Month.dec;
else static if(units == "hours")
return value >= 0 && value <= TimeOfDay.maxHour;
else static if(units == "minutes")
return value >= 0 && value <= TimeOfDay.maxMinute;
else static if(units == "seconds")
return value >= 0 && value <= TimeOfDay.maxSecond;
}
unittest
{
version(testStdDateTime)
{
//Verify Examples.
assert(valid!"hours"(12));
assert(!valid!"hours"(32));
assert(valid!"months"(12));
assert(!valid!"months"(13));
}
}
/++
Returns whether the given day is valid for the given year and month.
Params:
units = The units of time to validate.
year = The year of the day to validate.
month = The month of the day to validate.
day = The day to validate.
+/
bool valid(string units)(int year, int month, int day) pure nothrow
if(units == "days")
{
return day > 0 && day <= maxDay(year, month);
}
/++
Params:
units = The units of time to validate.
value = The number to validate.
file = The file that the $(D DateTimeException) will list if thrown.
line = The line number that the $(D DateTimeException) will list if
thrown.
Throws:
$(D DateTimeException) if $(D valid!units(value)) is false.
+/
void enforceValid(string units)(int value, string file = __FILE__, size_t line = __LINE__) pure
if(units == "months" ||
units == "hours" ||
units == "minutes" ||
units == "seconds")
{
static if(units == "months")
{
if(!valid!units(value))
throw new DateTimeException(numToString(value) ~ " is not a valid month of the year.", file, line);
}
else static if(units == "hours")
{
if(!valid!units(value))
throw new DateTimeException(numToString(value) ~ " is not a valid hour of the day.", file, line);
}
else static if(units == "minutes")
{
if(!valid!units(value))
throw new DateTimeException(numToString(value) ~ " is not a valid minute of an hour.", file, line);
}
else static if(units == "seconds")
{
if(!valid!units(value))
throw new DateTimeException(numToString(value) ~ " is not a valid second of a minute.", file, line);
}
}
/++
Params:
units = The units of time to validate.
year = The year of the day to validate.
month = The month of the day to validate.
day = The day to validate.
file = The file that the $(D DateTimeException) will list if thrown.
line = The line number that the $(D DateTimeException) will list if
thrown.
Throws:
$(D DateTimeException) if $(D valid!"days"(year, month, day)) is false.
+/
void enforceValid(string units)(int year, Month month, int day, string file = __FILE__, size_t line = __LINE__) pure
if(units == "days")
{
if(!valid!"days"(year, month, day))
{
throw new DateTimeException(numToString(day) ~
" is not a valid day in " ~
monthToString(month) ~
" in " ~
numToString(year), file, line);
}
}
/++
Returns the number of months from the current months of the year to the
given month of the year. If they are the same, then the result is 0.
Params:
currMonth = The current month of the year.
month = The month of the year to get the number of months to.
+/
static int monthsToMonth(int currMonth, int month) pure
{
enforceValid!"months"(currMonth);
enforceValid!"months"(month);
if(currMonth == month)
return 0;
if(currMonth < month)
return month - currMonth;
return (Month.dec - currMonth) + month;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(monthsToMonth(Month.jan, Month.jan), 0);
_assertPred!"=="(monthsToMonth(Month.jan, Month.feb), 1);
_assertPred!"=="(monthsToMonth(Month.jan, Month.mar), 2);
_assertPred!"=="(monthsToMonth(Month.jan, Month.apr), 3);
_assertPred!"=="(monthsToMonth(Month.jan, Month.may), 4);
_assertPred!"=="(monthsToMonth(Month.jan, Month.jun), 5);
_assertPred!"=="(monthsToMonth(Month.jan, Month.jul), 6);
_assertPred!"=="(monthsToMonth(Month.jan, Month.aug), 7);
_assertPred!"=="(monthsToMonth(Month.jan, Month.sep), 8);
_assertPred!"=="(monthsToMonth(Month.jan, Month.oct), 9);
_assertPred!"=="(monthsToMonth(Month.jan, Month.nov), 10);
_assertPred!"=="(monthsToMonth(Month.jan, Month.dec), 11);
_assertPred!"=="(monthsToMonth(Month.may, Month.jan), 8);
_assertPred!"=="(monthsToMonth(Month.may, Month.feb), 9);
_assertPred!"=="(monthsToMonth(Month.may, Month.mar), 10);
_assertPred!"=="(monthsToMonth(Month.may, Month.apr), 11);
_assertPred!"=="(monthsToMonth(Month.may, Month.may), 0);
_assertPred!"=="(monthsToMonth(Month.may, Month.jun), 1);
_assertPred!"=="(monthsToMonth(Month.may, Month.jul), 2);
_assertPred!"=="(monthsToMonth(Month.may, Month.aug), 3);
_assertPred!"=="(monthsToMonth(Month.may, Month.sep), 4);
_assertPred!"=="(monthsToMonth(Month.may, Month.oct), 5);
_assertPred!"=="(monthsToMonth(Month.may, Month.nov), 6);
_assertPred!"=="(monthsToMonth(Month.may, Month.dec), 7);
_assertPred!"=="(monthsToMonth(Month.oct, Month.jan), 3);
_assertPred!"=="(monthsToMonth(Month.oct, Month.feb), 4);
_assertPred!"=="(monthsToMonth(Month.oct, Month.mar), 5);
_assertPred!"=="(monthsToMonth(Month.oct, Month.apr), 6);
_assertPred!"=="(monthsToMonth(Month.oct, Month.may), 7);
_assertPred!"=="(monthsToMonth(Month.oct, Month.jun), 8);
_assertPred!"=="(monthsToMonth(Month.oct, Month.jul), 9);
_assertPred!"=="(monthsToMonth(Month.oct, Month.aug), 10);
_assertPred!"=="(monthsToMonth(Month.oct, Month.sep), 11);
_assertPred!"=="(monthsToMonth(Month.oct, Month.oct), 0);
_assertPred!"=="(monthsToMonth(Month.oct, Month.nov), 1);
_assertPred!"=="(monthsToMonth(Month.oct, Month.dec), 2);
_assertPred!"=="(monthsToMonth(Month.dec, Month.jan), 1);
_assertPred!"=="(monthsToMonth(Month.dec, Month.feb), 2);
_assertPred!"=="(monthsToMonth(Month.dec, Month.mar), 3);
_assertPred!"=="(monthsToMonth(Month.dec, Month.apr), 4);
_assertPred!"=="(monthsToMonth(Month.dec, Month.may), 5);
_assertPred!"=="(monthsToMonth(Month.dec, Month.jun), 6);
_assertPred!"=="(monthsToMonth(Month.dec, Month.jul), 7);
_assertPred!"=="(monthsToMonth(Month.dec, Month.aug), 8);
_assertPred!"=="(monthsToMonth(Month.dec, Month.sep), 9);
_assertPred!"=="(monthsToMonth(Month.dec, Month.oct), 10);
_assertPred!"=="(monthsToMonth(Month.dec, Month.nov), 11);
_assertPred!"=="(monthsToMonth(Month.dec, Month.dec), 0);
}
}
/++
Returns the number of days from the current day of the week to the given
day of the week. If they are the same, then the result is 0.
Params:
currDoW = The current day of the week.
dow = The day of the week to get the number of days to.
+/
static int daysToDayOfWeek(DayOfWeek currDoW, DayOfWeek dow) pure nothrow
{
if(currDoW == dow)
return 0;
if(currDoW < dow)
return dow - currDoW;
return (DayOfWeek.sat - currDoW) + dow + 1;
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.sun), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.mon), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.tue), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.wed), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.thu), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.fri), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sun, DayOfWeek.sat), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.sun), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.mon), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.tue), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.wed), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.thu), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.fri), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.sat), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.sun), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.mon), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.tue), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.wed), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.thu), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.fri), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.tue, DayOfWeek.sat), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.sun), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.mon), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.tue), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.wed), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.thu), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.fri), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.wed, DayOfWeek.sat), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.sun), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.mon), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.tue), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.wed), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.thu), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.fri), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.thu, DayOfWeek.sat), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.sun), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.mon), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.tue), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.wed), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.thu), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.fri), 0);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.fri, DayOfWeek.sat), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.sun), 1);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.mon), 2);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.tue), 3);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.wed), 4);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.thu), 5);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.fri), 6);
_assertPred!"=="(daysToDayOfWeek(DayOfWeek.sat, DayOfWeek.sat), 0);
}
}
version(StdDdoc)
{
/++
Function for starting to a stop watch time when the function is called
and stopping it when its return value goes out of scope and is destroyed.
When the value that is returned by this function is destroyed,
$(D func) will run. $(D func) is a unary function that takes a
$(CXREF time, TickDuration).
Examples:
--------------------
writeln("benchmark start!");
{
auto mt = measureTime!((a){assert(a.seconds);});
doSomething();
}
writeln("benchmark end!");
--------------------
+/
auto measureTime(alias func)();
}
else
{
@safe auto measureTime(alias func)()
if(isSafe!((){StopWatch sw; unaryFun!func(sw.peek());}))
{
struct Result
{
private StopWatch _sw = void;
this(AutoStart as)
{
_sw = StopWatch(as);
}
~this()
{
unaryFun!(func)(_sw.peek());
}
}
return Result(AutoStart.yes);
}
auto measureTime(alias func)()
if(!isSafe!((){StopWatch sw; unaryFun!func(sw.peek());}))
{
struct Result
{
private StopWatch _sw = void;
this(AutoStart as)
{
_sw = StopWatch(as);
}
~this()
{
unaryFun!(func)(_sw.peek());
}
}
return Result(AutoStart.yes);
}
}
version(testStdDateTime) @safe unittest
{
@safe static void func(TickDuration td)
{
assert(td.to!("seconds", real)() <>= 0);
}
auto mt = measureTime!(func)();
/+
with (measureTime!((a){assert(a.seconds);}))
{
// doSomething();
// @@@BUG@@@ doesn't work yet.
}
+/
}
version(testStdDateTime) unittest
{
static void func(TickDuration td)
{
assert(td.to!("seconds", real)() <>= 0);
}
auto mt = measureTime!(func)();
/+
with (measureTime!((a){assert(a.seconds);}))
{
// doSomething();
// @@@BUG@@@ doesn't work yet.
}
+/
}
//Bug# 8450
version(testStdDateTime) unittest
{
@safe void safeFunc() {}
@trusted void trustFunc() {}
@system void sysFunc() {}
auto safeResult = measureTime!((a){safeFunc();})();
auto trustResult = measureTime!((a){trustFunc();})();
auto sysResult = measureTime!((a){sysFunc();})();
}
//==============================================================================
// Private Section.
//==============================================================================
private:
//==============================================================================
// Section with private enums and constants.
//==============================================================================
enum daysInYear = 365; /// The number of days in a non-leap year.
enum daysInLeapYear = 366; /// The numbef or days in a leap year.
enum daysIn4Years = daysInYear * 3 + daysInLeapYear; /// Number of days in 4 years.
enum daysIn100Years = daysIn4Years * 25 - 1; /// The number of days in 100 years.
enum daysIn400Years = daysIn100Years * 4 + 1; /// The number of days in 400 years.
//==============================================================================
// Section with private helper functions and templates.
//==============================================================================
/+
Template to help with converting between time units.
+/
template hnsecsPer(string units)
if(CmpTimeUnits!(units, "months") < 0)
{
static if(units == "hnsecs")
enum hnsecsPer = 1L;
else static if(units == "usecs")
enum hnsecsPer = 10L;
else static if(units == "msecs")
enum hnsecsPer = 1000 * hnsecsPer!"usecs";
else static if(units == "seconds")
enum hnsecsPer = 1000 * hnsecsPer!"msecs";
else static if(units == "minutes")
enum hnsecsPer = 60 * hnsecsPer!"seconds";
else static if(units == "hours")
enum hnsecsPer = 60 * hnsecsPer!"minutes";
else static if(units == "days")
enum hnsecsPer = 24 * hnsecsPer!"hours";
else static if(units == "weeks")
enum hnsecsPer = 7 * hnsecsPer!"days";
}
/+
Splits out a particular unit from hnsecs and gives the value for that
unit and the remaining hnsecs. It really shouldn't be used unless unless
all units larger than the given units have already been split out.
Params:
units = The units to split out.
hnsecs = The current total hnsecs. Upon returning, it is the hnsecs left
after splitting out the given units.
Returns:
The number of the given units from converting hnsecs to those units.
Examples:
--------------------
auto hnsecs = 2595000000007L;
immutable days = splitUnitsFromHNSecs!"days"(hnsecs);
assert(days == 3);
assert(hnsecs == 3000000007);
immutable minutes = splitUnitsFromHNSecs!"minutes"(hnsecs);
assert(minutes == 5);
assert(hnsecs == 7);
--------------------
+/
long splitUnitsFromHNSecs(string units)(ref long hnsecs) pure nothrow
if(validTimeUnits(units) &&
CmpTimeUnits!(units, "months") < 0)
{
immutable value = convert!("hnsecs", units)(hnsecs);
hnsecs -= convert!(units, "hnsecs")(value);
return value;
}
unittest
{
version(testStdDateTime)
{
//Verify Example.
auto hnsecs = 2595000000007L;
immutable days = splitUnitsFromHNSecs!"days"(hnsecs);
assert(days == 3);
assert(hnsecs == 3000000007);
immutable minutes = splitUnitsFromHNSecs!"minutes"(hnsecs);
assert(minutes == 5);
assert(hnsecs == 7);
}
}
/+
This function is used to split out the units without getting the remaining
hnsecs.
See_Also:
$(LREF splitUnitsFromHNSecs)
Params:
units = The units to split out.
hnsecs = The current total hnsecs.
Returns:
The split out value.
Examples:
--------------------
auto hnsecs = 2595000000007L;
immutable days = getUnitsFromHNSecs!"days"(hnsecs);
assert(days == 3);
assert(hnsecs == 2595000000007L);
--------------------
+/
long getUnitsFromHNSecs(string units)(long hnsecs) pure nothrow
if(validTimeUnits(units) &&
CmpTimeUnits!(units, "months") < 0)
{
return convert!("hnsecs", units)(hnsecs);
}
unittest
{
version(testStdDateTime)
{
//Verify Example.
auto hnsecs = 2595000000007L;
immutable days = getUnitsFromHNSecs!"days"(hnsecs);
assert(days == 3);
assert(hnsecs == 2595000000007L);
}
}
/+
This function is used to split out the units without getting the units but
just the remaining hnsecs.
See_Also:
$(LREF splitUnitsFromHNSecs)
Params:
units = The units to split out.
hnsecs = The current total hnsecs.
Returns:
The remaining hnsecs.
Examples:
--------------------
auto hnsecs = 2595000000007L;
auto returned = removeUnitsFromHNSecs!"days"(hnsecs);
assert(returned == 3000000007);
assert(hnsecs == 2595000000007L);
--------------------
+/
long removeUnitsFromHNSecs(string units)(long hnsecs) pure nothrow
if(validTimeUnits(units) &&
CmpTimeUnits!(units, "months") < 0)
{
immutable value = convert!("hnsecs", units)(hnsecs);
return hnsecs - convert!(units, "hnsecs")(value);
}
unittest
{
version(testStdDateTime)
{
//Verify Example.
auto hnsecs = 2595000000007L;
auto returned = removeUnitsFromHNSecs!"days"(hnsecs);
assert(returned == 3000000007);
assert(hnsecs == 2595000000007L);
}
}
/+
The maximum valid Day in the given month in the given year.
Params:
year = The year to get the day for.
month = The month of the Gregorian Calendar to get the day for.
+/
static ubyte maxDay(int year, int month) pure nothrow
in
{
assert(valid!"months"(month));
}
body
{
switch(month)
{
case Month.jan, Month.mar, Month.may, Month.jul, Month.aug, Month.oct, Month.dec:
return 31;
case Month.feb:
return yearIsLeapYear(year) ? 29 : 28;
case Month.apr, Month.jun, Month.sep, Month.nov:
return 30;
default:
assert(0, "Invalid month.");
}
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(maxDay(1999, 1), 31);
_assertPred!"=="(maxDay(1999, 2), 28);
_assertPred!"=="(maxDay(1999, 3), 31);
_assertPred!"=="(maxDay(1999, 4), 30);
_assertPred!"=="(maxDay(1999, 5), 31);
_assertPred!"=="(maxDay(1999, 6), 30);
_assertPred!"=="(maxDay(1999, 7), 31);
_assertPred!"=="(maxDay(1999, 8), 31);
_assertPred!"=="(maxDay(1999, 9), 30);
_assertPred!"=="(maxDay(1999, 10), 31);
_assertPred!"=="(maxDay(1999, 11), 30);
_assertPred!"=="(maxDay(1999, 12), 31);
_assertPred!"=="(maxDay(2000, 1), 31);
_assertPred!"=="(maxDay(2000, 2), 29);
_assertPred!"=="(maxDay(2000, 3), 31);
_assertPred!"=="(maxDay(2000, 4), 30);
_assertPred!"=="(maxDay(2000, 5), 31);
_assertPred!"=="(maxDay(2000, 6), 30);
_assertPred!"=="(maxDay(2000, 7), 31);
_assertPred!"=="(maxDay(2000, 8), 31);
_assertPred!"=="(maxDay(2000, 9), 30);
_assertPred!"=="(maxDay(2000, 10), 31);
_assertPred!"=="(maxDay(2000, 11), 30);
_assertPred!"=="(maxDay(2000, 12), 31);
//Test B.C.
_assertPred!"=="(maxDay(-1999, 1), 31);
_assertPred!"=="(maxDay(-1999, 2), 28);
_assertPred!"=="(maxDay(-1999, 3), 31);
_assertPred!"=="(maxDay(-1999, 4), 30);
_assertPred!"=="(maxDay(-1999, 5), 31);
_assertPred!"=="(maxDay(-1999, 6), 30);
_assertPred!"=="(maxDay(-1999, 7), 31);
_assertPred!"=="(maxDay(-1999, 8), 31);
_assertPred!"=="(maxDay(-1999, 9), 30);
_assertPred!"=="(maxDay(-1999, 10), 31);
_assertPred!"=="(maxDay(-1999, 11), 30);
_assertPred!"=="(maxDay(-1999, 12), 31);
_assertPred!"=="(maxDay(-2000, 1), 31);
_assertPred!"=="(maxDay(-2000, 2), 29);
_assertPred!"=="(maxDay(-2000, 3), 31);
_assertPred!"=="(maxDay(-2000, 4), 30);
_assertPred!"=="(maxDay(-2000, 5), 31);
_assertPred!"=="(maxDay(-2000, 6), 30);
_assertPred!"=="(maxDay(-2000, 7), 31);
_assertPred!"=="(maxDay(-2000, 8), 31);
_assertPred!"=="(maxDay(-2000, 9), 30);
_assertPred!"=="(maxDay(-2000, 10), 31);
_assertPred!"=="(maxDay(-2000, 11), 30);
_assertPred!"=="(maxDay(-2000, 12), 31);
}
}
/+
Returns the day of the week for the given day of the Gregorian Calendar.
Params:
day = The day of the Gregorian Calendar for which to get the day of
the week.
+/
DayOfWeek getDayOfWeek(int day) pure nothrow
{
//January 1st, 1 A.D. was a Monday
if(day >= 0)
return cast(DayOfWeek)(day % 7);
else
{
immutable dow = cast(DayOfWeek)((day % 7) + 7);
if(dow == 7)
return DayOfWeek.sun;
else
return dow;
}
}
unittest
{
version(testStdDateTime)
{
//Test A.D.
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 1)).dayOfGregorianCal), DayOfWeek.mon);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 2)).dayOfGregorianCal), DayOfWeek.tue);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 3)).dayOfGregorianCal), DayOfWeek.wed);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 4)).dayOfGregorianCal), DayOfWeek.thu);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 5)).dayOfGregorianCal), DayOfWeek.fri);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 6)).dayOfGregorianCal), DayOfWeek.sat);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 7)).dayOfGregorianCal), DayOfWeek.sun);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 8)).dayOfGregorianCal), DayOfWeek.mon);
_assertPred!"=="(getDayOfWeek(SysTime(Date(1, 1, 9)).dayOfGregorianCal), DayOfWeek.tue);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2, 1, 1)).dayOfGregorianCal), DayOfWeek.tue);
_assertPred!"=="(getDayOfWeek(SysTime(Date(3, 1, 1)).dayOfGregorianCal), DayOfWeek.wed);
_assertPred!"=="(getDayOfWeek(SysTime(Date(4, 1, 1)).dayOfGregorianCal), DayOfWeek.thu);
_assertPred!"=="(getDayOfWeek(SysTime(Date(5, 1, 1)).dayOfGregorianCal), DayOfWeek.sat);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2000, 1, 1)).dayOfGregorianCal), DayOfWeek.sat);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 22)).dayOfGregorianCal), DayOfWeek.sun);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 23)).dayOfGregorianCal), DayOfWeek.mon);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 24)).dayOfGregorianCal), DayOfWeek.tue);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 25)).dayOfGregorianCal), DayOfWeek.wed);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 26)).dayOfGregorianCal), DayOfWeek.thu);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 27)).dayOfGregorianCal), DayOfWeek.fri);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 28)).dayOfGregorianCal), DayOfWeek.sat);
_assertPred!"=="(getDayOfWeek(SysTime(Date(2010, 8, 29)).dayOfGregorianCal), DayOfWeek.sun);
//Test B.C.
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 31)).dayOfGregorianCal), DayOfWeek.sun);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 30)).dayOfGregorianCal), DayOfWeek.sat);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 29)).dayOfGregorianCal), DayOfWeek.fri);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 28)).dayOfGregorianCal), DayOfWeek.thu);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 27)).dayOfGregorianCal), DayOfWeek.wed);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 26)).dayOfGregorianCal), DayOfWeek.tue);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 25)).dayOfGregorianCal), DayOfWeek.mon);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 24)).dayOfGregorianCal), DayOfWeek.sun);
_assertPred!"=="(getDayOfWeek(SysTime(Date(0, 12, 23)).dayOfGregorianCal), DayOfWeek.sat);
}
}
/+
Returns the string representation of the given month.
Params:
useLongName = Whether the long or short version of the month name should
be used.
plural = Whether the string should be plural or not.
Throws:
$(D DateTimeException) if the given month is not a valid month.
+/
string monthToString(Month month, bool useLongName = true) pure
{
if (month < Month.jan || month > Month.dec)
{
throw new DateTimeException("Invalid month: " ~ numToString(month));
}
if(useLongName == true)
{
return longMonthNames[month - Month.jan];
}
else
{
return shortMonthNames[month - Month.jan];
}
}
unittest
{
version(testStdDateTime)
{
static void testMTSInvalid(Month month, bool useLongName)
{
monthToString(month, useLongName);
}
assertThrown!DateTimeException(testMTSInvalid(cast(Month)0, true));
assertThrown!DateTimeException(testMTSInvalid(cast(Month)0, false));
assertThrown!DateTimeException(testMTSInvalid(cast(Month)13, true));
assertThrown!DateTimeException(testMTSInvalid(cast(Month)13, false));
_assertPred!"=="(monthToString(Month.jan), "January");
_assertPred!"=="(monthToString(Month.feb), "February");
_assertPred!"=="(monthToString(Month.mar), "March");
_assertPred!"=="(monthToString(Month.apr), "April");
_assertPred!"=="(monthToString(Month.may), "May");
_assertPred!"=="(monthToString(Month.jun), "June");
_assertPred!"=="(monthToString(Month.jul), "July");
_assertPred!"=="(monthToString(Month.aug), "August");
_assertPred!"=="(monthToString(Month.sep), "September");
_assertPred!"=="(monthToString(Month.oct), "October");
_assertPred!"=="(monthToString(Month.nov), "November");
_assertPred!"=="(monthToString(Month.dec), "December");
_assertPred!"=="(monthToString(Month.jan, false), "Jan");
_assertPred!"=="(monthToString(Month.feb, false), "Feb");
_assertPred!"=="(monthToString(Month.mar, false), "Mar");
_assertPred!"=="(monthToString(Month.apr, false), "Apr");
_assertPred!"=="(monthToString(Month.may, false), "May");
_assertPred!"=="(monthToString(Month.jun, false), "Jun");
_assertPred!"=="(monthToString(Month.jul, false), "Jul");
_assertPred!"=="(monthToString(Month.aug, false), "Aug");
_assertPred!"=="(monthToString(Month.sep, false), "Sep");
_assertPred!"=="(monthToString(Month.oct, false), "Oct");
_assertPred!"=="(monthToString(Month.nov, false), "Nov");
_assertPred!"=="(monthToString(Month.dec, false), "Dec");
}
}
/+
Returns the Month corresponding to the given string. Casing is ignored.
Params:
monthStr = The string representation of the month to get the Month for.
Throws:
$(D DateTimeException) if the given month is not a valid month string.
+/
Month monthFromString(string monthStr)
{
switch(toLower(monthStr))
{
case "january":
case "jan":
return Month.jan;
case "february":
case "feb":
return Month.feb;
case "march":
case "mar":
return Month.mar;
case "april":
case "apr":
return Month.apr;
case "may":
return Month.may;
case "june":
case "jun":
return Month.jun;
case "july":
case "jul":
return Month.jul;
case "august":
case "aug":
return Month.aug;
case "september":
case "sep":
return Month.sep;
case "october":
case "oct":
return Month.oct;
case "november":
case "nov":
return Month.nov;
case "december":
case "dec":
return Month.dec;
default:
throw new DateTimeException(format("Invalid month %s", monthStr));
}
}
unittest
{
version(testStdDateTime)
{
static void testMFSInvalid(string monthStr)
{
monthFromString(monthStr);
}
assertThrown!DateTimeException(testMFSInvalid("Ja"));
assertThrown!DateTimeException(testMFSInvalid("Janu"));
assertThrown!DateTimeException(testMFSInvalid("Januar"));
assertThrown!DateTimeException(testMFSInvalid("Januarys"));
assertThrown!DateTimeException(testMFSInvalid("JJanuary"));
_assertPred!"=="(monthFromString(monthToString(Month.jan)), Month.jan);
_assertPred!"=="(monthFromString(monthToString(Month.feb)), Month.feb);
_assertPred!"=="(monthFromString(monthToString(Month.mar)), Month.mar);
_assertPred!"=="(monthFromString(monthToString(Month.apr)), Month.apr);
_assertPred!"=="(monthFromString(monthToString(Month.may)), Month.may);
_assertPred!"=="(monthFromString(monthToString(Month.jun)), Month.jun);
_assertPred!"=="(monthFromString(monthToString(Month.jul)), Month.jul);
_assertPred!"=="(monthFromString(monthToString(Month.aug)), Month.aug);
_assertPred!"=="(monthFromString(monthToString(Month.sep)), Month.sep);
_assertPred!"=="(monthFromString(monthToString(Month.oct)), Month.oct);
_assertPred!"=="(monthFromString(monthToString(Month.nov)), Month.nov);
_assertPred!"=="(monthFromString(monthToString(Month.dec)), Month.dec);
_assertPred!"=="(monthFromString(monthToString(Month.jan, false)), Month.jan);
_assertPred!"=="(monthFromString(monthToString(Month.feb, false)), Month.feb);
_assertPred!"=="(monthFromString(monthToString(Month.mar, false)), Month.mar);
_assertPred!"=="(monthFromString(monthToString(Month.apr, false)), Month.apr);
_assertPred!"=="(monthFromString(monthToString(Month.may, false)), Month.may);
_assertPred!"=="(monthFromString(monthToString(Month.jun, false)), Month.jun);
_assertPred!"=="(monthFromString(monthToString(Month.jul, false)), Month.jul);
_assertPred!"=="(monthFromString(monthToString(Month.aug, false)), Month.aug);
_assertPred!"=="(monthFromString(monthToString(Month.sep, false)), Month.sep);
_assertPred!"=="(monthFromString(monthToString(Month.oct, false)), Month.oct);
_assertPred!"=="(monthFromString(monthToString(Month.nov, false)), Month.nov);
_assertPred!"=="(monthFromString(monthToString(Month.dec, false)), Month.dec);
_assertPred!"=="(monthFromString("JANUARY"), Month.jan);
_assertPred!"=="(monthFromString("JAN"), Month.jan);
_assertPred!"=="(monthFromString("january"), Month.jan);
_assertPred!"=="(monthFromString("jan"), Month.jan);
_assertPred!"=="(monthFromString("jaNuary"), Month.jan);
_assertPred!"=="(monthFromString("jaN"), Month.jan);
_assertPred!"=="(monthFromString("jaNuaRy"), Month.jan);
_assertPred!"=="(monthFromString("jAn"), Month.jan);
}
}
/+
The time units which are one step smaller than the given units.
Examples:
--------------------
assert(nextSmallerTimeUnits!"years" == "months");
assert(nextSmallerTimeUnits!"usecs" == "hnsecs");
--------------------
+/
template nextSmallerTimeUnits(string units)
if(validTimeUnits(units) &&
timeStrings.front != units)
{
enum nextSmallerTimeUnits = timeStrings[countUntil(timeStrings.dup, units) - 1];
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(nextSmallerTimeUnits!"months", "weeks");
_assertPred!"=="(nextSmallerTimeUnits!"weeks", "days");
_assertPred!"=="(nextSmallerTimeUnits!"days", "hours");
_assertPred!"=="(nextSmallerTimeUnits!"hours", "minutes");
_assertPred!"=="(nextSmallerTimeUnits!"minutes", "seconds");
_assertPred!"=="(nextSmallerTimeUnits!"seconds", "msecs");
_assertPred!"=="(nextSmallerTimeUnits!"msecs", "usecs");
static assert(!__traits(compiles, nextSmallerTimeUnits!"hnsecs"));
//Verify Examples.
assert(nextSmallerTimeUnits!"years" == "months");
assert(nextSmallerTimeUnits!"usecs" == "hnsecs");
}
}
/+
The time units which are one step larger than the given units.
Examples:
--------------------
assert(nextLargerTimeUnits!"months" == "years");
assert(nextLargerTimeUnits!"hnsecs" == "usecs");
--------------------
+/
template nextLargerTimeUnits(string units)
if(validTimeUnits(units) &&
timeStrings.back != units)
{
enum nextLargerTimeUnits = timeStrings[countUntil(timeStrings.dup, units) + 1];
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(nextLargerTimeUnits!"usecs", "msecs");
_assertPred!"=="(nextLargerTimeUnits!"msecs", "seconds");
_assertPred!"=="(nextLargerTimeUnits!"seconds", "minutes");
_assertPred!"=="(nextLargerTimeUnits!"minutes", "hours");
_assertPred!"=="(nextLargerTimeUnits!"hours", "days");
_assertPred!"=="(nextLargerTimeUnits!"days", "weeks");
_assertPred!"=="(nextLargerTimeUnits!"weeks", "months");
static assert(!__traits(compiles, nextLargerTimeUnits!"years"));
//Verify Examples.
assert(nextLargerTimeUnits!"months" == "years");
assert(nextLargerTimeUnits!"hnsecs" == "usecs");
}
}
/+
Returns the given hnsecs as an ISO string of fractional seconds.
+/
static string fracSecToISOString(int hnsecs) nothrow
in
{
assert(hnsecs >= 0);
}
body
{
try
{
string isoString = format(".%07d", hnsecs);
while(isoString.endsWith("0"))
isoString.popBack();
if(isoString.length == 1)
return "";
return isoString;
}
catch(Exception e)
assert(0, "format() threw.");
}
unittest
{
version(testStdDateTime)
{
_assertPred!"=="(fracSecToISOString(0), "");
_assertPred!"=="(fracSecToISOString(1), ".0000001");
_assertPred!"=="(fracSecToISOString(10), ".000001");
_assertPred!"=="(fracSecToISOString(100), ".00001");
_assertPred!"=="(fracSecToISOString(1000), ".0001");
_assertPred!"=="(fracSecToISOString(10_000), ".001");
_assertPred!"=="(fracSecToISOString(100_000), ".01");
_assertPred!"=="(fracSecToISOString(1_000_000), ".1");
_assertPred!"=="(fracSecToISOString(1_000_001), ".1000001");
_assertPred!"=="(fracSecToISOString(1_001_001), ".1001001");
_assertPred!"=="(fracSecToISOString(1_071_601), ".1071601");
_assertPred!"=="(fracSecToISOString(1_271_641), ".1271641");
_assertPred!"=="(fracSecToISOString(9_999_999), ".9999999");
_assertPred!"=="(fracSecToISOString(9_999_990), ".999999");
_assertPred!"=="(fracSecToISOString(9_999_900), ".99999");
_assertPred!"=="(fracSecToISOString(9_999_000), ".9999");
_assertPred!"=="(fracSecToISOString(9_990_000), ".999");
_assertPred!"=="(fracSecToISOString(9_900_000), ".99");
_assertPred!"=="(fracSecToISOString(9_000_000), ".9");
_assertPred!"=="(fracSecToISOString(999), ".0000999");
_assertPred!"=="(fracSecToISOString(9990), ".000999");
_assertPred!"=="(fracSecToISOString(99_900), ".00999");
_assertPred!"=="(fracSecToISOString(999_000), ".0999");
}
}
/+
Returns a FracSec corresponding to to the given ISO string of
fractional seconds.
+/
static FracSec fracSecFromISOString(S)(in S isoString)
if(isSomeString!S)
{
if(isoString.empty)
return FracSec.from!"hnsecs"(0);
auto dstr = to!dstring(isoString);
enforce(dstr.startsWith("."), new DateTimeException("Invalid ISO String"));
dstr.popFront();
enforce(!dstr.empty && dstr.length <= 7, new DateTimeException("Invalid ISO String"));
enforce(!canFind!(not!isDigit)(dstr), new DateTimeException("Invalid ISO String"));
dchar[7] fullISOString;
foreach(i, ref dchar c; fullISOString)
{
if(i < dstr.length)
c = dstr[i];
else
c = '0';
}
return FracSec.from!"hnsecs"(to!int(fullISOString[]));
}
unittest
{
version(testStdDateTime)
{
static void testFSInvalid(string isoString)
{
fracSecFromISOString(isoString);
}
assertThrown!DateTimeException(testFSInvalid("."));
assertThrown!DateTimeException(testFSInvalid("0."));
assertThrown!DateTimeException(testFSInvalid("0"));
assertThrown!DateTimeException(testFSInvalid("0000000"));
assertThrown!DateTimeException(testFSInvalid(".00000000"));
assertThrown!DateTimeException(testFSInvalid(".00000001"));
assertThrown!DateTimeException(testFSInvalid("T"));
assertThrown!DateTimeException(testFSInvalid("T."));
assertThrown!DateTimeException(testFSInvalid(".T"));
_assertPred!"=="(fracSecFromISOString(""), FracSec.from!"hnsecs"(0));
_assertPred!"=="(fracSecFromISOString(".0000001"), FracSec.from!"hnsecs"(1));
_assertPred!"=="(fracSecFromISOString(".000001"), FracSec.from!"hnsecs"(10));
_assertPred!"=="(fracSecFromISOString(".00001"), FracSec.from!"hnsecs"(100));
_assertPred!"=="(fracSecFromISOString(".0001"), FracSec.from!"hnsecs"(1000));
_assertPred!"=="(fracSecFromISOString(".001"), FracSec.from!"hnsecs"(10_000));
_assertPred!"=="(fracSecFromISOString(".01"), FracSec.from!"hnsecs"(100_000));
_assertPred!"=="(fracSecFromISOString(".1"), FracSec.from!"hnsecs"(1_000_000));
_assertPred!"=="(fracSecFromISOString(".1000001"), FracSec.from!"hnsecs"(1_000_001));
_assertPred!"=="(fracSecFromISOString(".1001001"), FracSec.from!"hnsecs"(1_001_001));
_assertPred!"=="(fracSecFromISOString(".1071601"), FracSec.from!"hnsecs"(1_071_601));
_assertPred!"=="(fracSecFromISOString(".1271641"), FracSec.from!"hnsecs"(1_271_641));
_assertPred!"=="(fracSecFromISOString(".9999999"), FracSec.from!"hnsecs"(9_999_999));
_assertPred!"=="(fracSecFromISOString(".9999990"), FracSec.from!"hnsecs"(9_999_990));
_assertPred!"=="(fracSecFromISOString(".999999"), FracSec.from!"hnsecs"(9_999_990));
_assertPred!"=="(fracSecFromISOString(".9999900"), FracSec.from!"hnsecs"(9_999_900));
_assertPred!"=="(fracSecFromISOString(".99999"), FracSec.from!"hnsecs"(9_999_900));
_assertPred!"=="(fracSecFromISOString(".9999000"), FracSec.from!"hnsecs"(9_999_000));
_assertPred!"=="(fracSecFromISOString(".9999"), FracSec.from!"hnsecs"(9_999_000));
_assertPred!"=="(fracSecFromISOString(".9990000"), FracSec.from!"hnsecs"(9_990_000));
_assertPred!"=="(fracSecFromISOString(".999"), FracSec.from!"hnsecs"(9_990_000));
_assertPred!"=="(fracSecFromISOString(".9900000"), FracSec.from!"hnsecs"(9_900_000));
_assertPred!"=="(fracSecFromISOString(".9900"), FracSec.from!"hnsecs"(9_900_000));
_assertPred!"=="(fracSecFromISOString(".99"), FracSec.from!"hnsecs"(9_900_000));
_assertPred!"=="(fracSecFromISOString(".9000000"), FracSec.from!"hnsecs"(9_000_000));
_assertPred!"=="(fracSecFromISOString(".9"), FracSec.from!"hnsecs"(9_000_000));
_assertPred!"=="(fracSecFromISOString(".0000999"), FracSec.from!"hnsecs"(999));
_assertPred!"=="(fracSecFromISOString(".0009990"), FracSec.from!"hnsecs"(9990));
_assertPred!"=="(fracSecFromISOString(".000999"), FracSec.from!"hnsecs"(9990));
_assertPred!"=="(fracSecFromISOString(".0099900"), FracSec.from!"hnsecs"(99_900));
_assertPred!"=="(fracSecFromISOString(".00999"), FracSec.from!"hnsecs"(99_900));
_assertPred!"=="(fracSecFromISOString(".0999000"), FracSec.from!"hnsecs"(999_000));
_assertPred!"=="(fracSecFromISOString(".0999"), FracSec.from!"hnsecs"(999_000));
}
}
/+
Whether the given type defines the static property min which returns the
minimum value for the type.
+/
template hasMin(T)
{
enum hasMin = __traits(hasMember, T, "min") &&
__traits(isStaticFunction, T.min) &&
is(ReturnType!(T.min) == Unqual!T) &&
(functionAttributes!(T.min) & FunctionAttribute.property) &&
(functionAttributes!(T.min) & FunctionAttribute.nothrow_);
//(functionAttributes!(T.min) & FunctionAttribute.pure_); //Ideally this would be the case, but SysTime's min() can't currently be pure.
}
unittest
{
version(testStdDateTime)
{
static assert(hasMin!(Date));
static assert(hasMin!(TimeOfDay));
static assert(hasMin!(DateTime));
static assert(hasMin!(SysTime));
static assert(hasMin!(const Date));
static assert(hasMin!(const TimeOfDay));
static assert(hasMin!(const DateTime));
static assert(hasMin!(const SysTime));
static assert(hasMin!(immutable Date));
static assert(hasMin!(immutable TimeOfDay));
static assert(hasMin!(immutable SysTime));
}
}
/+
Whether the given type defines the static property max which returns the
maximum value for the type.
+/
template hasMax(T)
{
enum hasMax = __traits(hasMember, T, "max") &&
__traits(isStaticFunction, T.max) &&
is(ReturnType!(T.max) == Unqual!T) &&
(functionAttributes!(T.max) & FunctionAttribute.property) &&
(functionAttributes!(T.max) & FunctionAttribute.nothrow_);
//(functionAttributes!(T.max) & FunctionAttribute.pure_); //Ideally this would be the case, but SysTime's max() can't currently be pure.
}
unittest
{
version(testStdDateTime)
{
static assert(hasMax!(Date));
static assert(hasMax!(TimeOfDay));
static assert(hasMax!(DateTime));
static assert(hasMax!(SysTime));
static assert(hasMax!(const Date));
static assert(hasMax!(const TimeOfDay));
static assert(hasMax!(const DateTime));
static assert(hasMax!(const SysTime));
static assert(hasMax!(immutable Date));
static assert(hasMax!(immutable TimeOfDay));
static assert(hasMax!(immutable DateTime));
static assert(hasMax!(immutable SysTime));
}
}
/+
Whether the given type defines the overloaded opBinary operators that a time
point is supposed to define which work with time durations. Namely:
$(BOOKTABLE,
$(TR $(TD TimePoint opBinary"+"(duration)))
$(TR $(TD TimePoint opBinary"-"(duration)))
)
+/
template hasOverloadedOpBinaryWithDuration(T)
{
enum hasOverloadedOpBinaryWithDuration = __traits(compiles, T.init + dur!"days"(5)) &&
is(typeof(T.init + dur!"days"(5)) == Unqual!T) &&
__traits(compiles, T.init - dur!"days"(5)) &&
is(typeof(T.init - dur!"days"(5)) == Unqual!T) &&
__traits(compiles, T.init + TickDuration.from!"hnsecs"(5)) &&
is(typeof(T.init + TickDuration.from!"hnsecs"(5)) == Unqual!T) &&
__traits(compiles, T.init - TickDuration.from!"hnsecs"(5)) &&
is(typeof(T.init - TickDuration.from!"hnsecs"(5)) == Unqual!T);
}
unittest
{
version(testStdDateTime)
{
static assert(hasOverloadedOpBinaryWithDuration!(Date));
static assert(hasOverloadedOpBinaryWithDuration!(TimeOfDay));
static assert(hasOverloadedOpBinaryWithDuration!(DateTime));
static assert(hasOverloadedOpBinaryWithDuration!(SysTime));
static assert(hasOverloadedOpBinaryWithDuration!(const Date));
static assert(hasOverloadedOpBinaryWithDuration!(const TimeOfDay));
static assert(hasOverloadedOpBinaryWithDuration!(const DateTime));
static assert(hasOverloadedOpBinaryWithDuration!(const SysTime));
static assert(hasOverloadedOpBinaryWithDuration!(immutable Date));
static assert(hasOverloadedOpBinaryWithDuration!(immutable TimeOfDay));
static assert(hasOverloadedOpBinaryWithDuration!(immutable DateTime));
static assert(hasOverloadedOpBinaryWithDuration!(immutable SysTime));
}
}
/+
Whether the given type defines the overloaded opOpAssign operators that a time point is supposed
to define. Namely:
$(BOOKTABLE,
$(TR $(TD TimePoint opOpAssign"+"(duration)))
$(TR $(TD TimePoint opOpAssign"-"(duration)))
)
+/
template hasOverloadedOpAssignWithDuration(T)
{
enum hasOverloadedOpAssignWithDuration = is(typeof(
{
auto d = dur!"days"(5);
auto td = TickDuration.from!"hnsecs"(5);
alias U = Unqual!T;
static assert(is(typeof(U.init += d) == U));
static assert(is(typeof(U.init -= d) == U));
static assert(is(typeof(U.init += td) == U));
static assert(is(typeof(U.init -= td) == U));
}));
}
unittest
{
version(testStdDateTime)
{
static assert(hasOverloadedOpAssignWithDuration!(Date));
static assert(hasOverloadedOpAssignWithDuration!(TimeOfDay));
static assert(hasOverloadedOpAssignWithDuration!(DateTime));
static assert(hasOverloadedOpAssignWithDuration!(SysTime));
static assert(hasOverloadedOpAssignWithDuration!(const Date));
static assert(hasOverloadedOpAssignWithDuration!(const TimeOfDay));
static assert(hasOverloadedOpAssignWithDuration!(const DateTime));
static assert(hasOverloadedOpAssignWithDuration!(const SysTime));
static assert(hasOverloadedOpAssignWithDuration!(immutable Date));
static assert(hasOverloadedOpAssignWithDuration!(immutable TimeOfDay));
static assert(hasOverloadedOpAssignWithDuration!(immutable DateTime));
static assert(hasOverloadedOpAssignWithDuration!(immutable SysTime));
}
}
/+
Whether the given type defines the overloaded opBinary operator that a time point is supposed
to define which works with itself. Namely:
$(BOOKTABLE,
$(TR $(TD duration opBinary"-"(Date)))
)
+/
template hasOverloadedOpBinaryWithSelf(T)
{
enum hasOverloadedOpBinaryWithSelf = __traits(compiles, T.init - T.init) &&
is(Unqual!(typeof(T.init - T.init)) == Duration);
}
unittest
{
version(testStdDateTime)
{
static assert(hasOverloadedOpBinaryWithSelf!(Date));
static assert(hasOverloadedOpBinaryWithSelf!(TimeOfDay));
static assert(hasOverloadedOpBinaryWithSelf!(DateTime));
static assert(hasOverloadedOpBinaryWithSelf!(SysTime));
static assert(hasOverloadedOpBinaryWithSelf!(const Date));
static assert(hasOverloadedOpBinaryWithSelf!(const TimeOfDay));
static assert(hasOverloadedOpBinaryWithSelf!(const DateTime));
static assert(hasOverloadedOpBinaryWithSelf!(const SysTime));
static assert(hasOverloadedOpBinaryWithSelf!(immutable Date));
static assert(hasOverloadedOpBinaryWithSelf!(immutable TimeOfDay));
static assert(hasOverloadedOpBinaryWithSelf!(immutable DateTime));
static assert(hasOverloadedOpBinaryWithSelf!(immutable SysTime));
}
}
/+
Unfortunately, to!string() is not pure, so here's a way to convert
a number to a string which is. Once to!string() is properly pure
(like it hopefully will be at some point), this function should
be removed in favor of using to!string().
+/
string numToString(long value) pure nothrow
{
try
{
immutable negative = value < 0;
char[25] str;
size_t i = str.length;
if(negative)
value = -value;
while(1)
{
char digit = cast(char)('0' + value % 10);
value /= 10;
str[--i] = digit;
assert(i > 0);
if(value == 0)
break;
}
if(negative)
return "-" ~ str[i .. $].idup;
else
return str[i .. $].idup;
}
catch(Exception e)
assert(0, "Something threw when nothing can throw.");
}
version(unittest)
{
//Variables to help in testing.
Duration currLocalDiffFromUTC;
immutable (TimeZone)[] testTZs;
//All of these helper arrays are sorted in ascending order.
auto testYearsBC = [-1999, -1200, -600, -4, -1, 0];
auto testYearsAD = [1, 4, 1000, 1999, 2000, 2012];
//I'd use a Tuple, but I get forward reference errors if I try.
struct MonthDay
{
Month month;
short day;
this(int m, short d)
{
month = cast(Month)m;
day = d;
}
}
MonthDay[] testMonthDays = [MonthDay(1, 1),
MonthDay(1, 2),
MonthDay(3, 17),
MonthDay(7, 4),
MonthDay(10, 27),
MonthDay(12, 30),
MonthDay(12, 31)];
auto testDays = [1, 2, 9, 10, 16, 20, 25, 28, 29, 30, 31];
auto testTODs = [TimeOfDay(0, 0, 0),
TimeOfDay(0, 0, 1),
TimeOfDay(0, 1, 0),
TimeOfDay(1, 0, 0),
TimeOfDay(13, 13, 13),
TimeOfDay(23, 59, 59)];
auto testHours = [0, 1, 12, 22, 23];
auto testMinSecs = [0, 1, 30, 58, 59];
//Throwing exceptions is incredibly expensive, so we want to use a smaller
//set of values for tests using assertThrown.
auto testTODsThrown = [TimeOfDay(0, 0, 0),
TimeOfDay(13, 13, 13),
TimeOfDay(23, 59, 59)];
Date[] testDatesBC;
Date[] testDatesAD;
DateTime[] testDateTimesBC;
DateTime[] testDateTimesAD;
FracSec[] testFracSecs;
SysTime[] testSysTimesBC;
SysTime[] testSysTimesAD;
//I'd use a Tuple, but I get forward reference errors if I try.
struct GregDay { int day; Date date; }
auto testGregDaysBC = [GregDay(-1_373_427, Date(-3760, 9, 7)), //Start of the Hebrew Calendar
GregDay(-735_233, Date(-2012, 1, 1)),
GregDay(-735_202, Date(-2012, 2, 1)),
GregDay(-735_175, Date(-2012, 2, 28)),
GregDay(-735_174, Date(-2012, 2, 29)),
GregDay(-735_173, Date(-2012, 3, 1)),
GregDay(-734_502, Date(-2010, 1, 1)),
GregDay(-734_472, Date(-2010, 1, 31)),
GregDay(-734_471, Date(-2010, 2, 1)),
GregDay(-734_444, Date(-2010, 2, 28)),
GregDay(-734_443, Date(-2010, 3, 1)),
GregDay(-734_413, Date(-2010, 3, 31)),
GregDay(-734_412, Date(-2010, 4, 1)),
GregDay(-734_383, Date(-2010, 4, 30)),
GregDay(-734_382, Date(-2010, 5, 1)),
GregDay(-734_352, Date(-2010, 5, 31)),
GregDay(-734_351, Date(-2010, 6, 1)),
GregDay(-734_322, Date(-2010, 6, 30)),
GregDay(-734_321, Date(-2010, 7, 1)),
GregDay(-734_291, Date(-2010, 7, 31)),
GregDay(-734_290, Date(-2010, 8, 1)),
GregDay(-734_260, Date(-2010, 8, 31)),
GregDay(-734_259, Date(-2010, 9, 1)),
GregDay(-734_230, Date(-2010, 9, 30)),
GregDay(-734_229, Date(-2010, 10, 1)),
GregDay(-734_199, Date(-2010, 10, 31)),
GregDay(-734_198, Date(-2010, 11, 1)),
GregDay(-734_169, Date(-2010, 11, 30)),
GregDay(-734_168, Date(-2010, 12, 1)),
GregDay(-734_139, Date(-2010, 12, 30)),
GregDay(-734_138, Date(-2010, 12, 31)),
GregDay(-731_215, Date(-2001, 1, 1)),
GregDay(-730_850, Date(-2000, 1, 1)),
GregDay(-730_849, Date(-2000, 1, 2)),
GregDay(-730_486, Date(-2000, 12, 30)),
GregDay(-730_485, Date(-2000, 12, 31)),
GregDay(-730_484, Date(-1999, 1, 1)),
GregDay(-694_690, Date(-1901, 1, 1)),
GregDay(-694_325, Date(-1900, 1, 1)),
GregDay(-585_118, Date(-1601, 1, 1)),
GregDay(-584_753, Date(-1600, 1, 1)),
GregDay(-584_388, Date(-1600, 12, 31)),
GregDay(-584_387, Date(-1599, 1, 1)),
GregDay(-365_972, Date(-1001, 1, 1)),
GregDay(-365_607, Date(-1000, 1, 1)),
GregDay(-183_351, Date(-501, 1, 1)),
GregDay(-182_986, Date(-500, 1, 1)),
GregDay(-182_621, Date(-499, 1, 1)),
GregDay(-146_827, Date(-401, 1, 1)),
GregDay(-146_462, Date(-400, 1, 1)),
GregDay(-146_097, Date(-400, 12, 31)),
GregDay(-110_302, Date(-301, 1, 1)),
GregDay(-109_937, Date(-300, 1, 1)),
GregDay(-73_778, Date(-201, 1, 1)),
GregDay(-73_413, Date(-200, 1, 1)),
GregDay(-38_715, Date(-105, 1, 1)),
GregDay(-37_254, Date(-101, 1, 1)),
GregDay(-36_889, Date(-100, 1, 1)),
GregDay(-36_524, Date(-99, 1, 1)),
GregDay(-36_160, Date(-99, 12, 31)),
GregDay(-35_794, Date(-97, 1, 1)),
GregDay(-18_627, Date(-50, 1, 1)),
GregDay(-18_262, Date(-49, 1, 1)),
GregDay(-3652, Date(-9, 1, 1)),
GregDay(-2191, Date(-5, 1, 1)),
GregDay(-1827, Date(-5, 12, 31)),
GregDay(-1826, Date(-4, 1, 1)),
GregDay(-1825, Date(-4, 1, 2)),
GregDay(-1462, Date(-4, 12, 30)),
GregDay(-1461, Date(-4, 12, 31)),
GregDay(-1460, Date(-3, 1, 1)),
GregDay(-1096, Date(-3, 12, 31)),
GregDay(-1095, Date(-2, 1, 1)),
GregDay(-731, Date(-2, 12, 31)),
GregDay(-730, Date(-1, 1, 1)),
GregDay(-367, Date(-1, 12, 30)),
GregDay(-366, Date(-1, 12, 31)),
GregDay(-365, Date(0, 1, 1)),
GregDay(-31, Date(0, 11, 30)),
GregDay(-30, Date(0, 12, 1)),
GregDay(-1, Date(0, 12, 30)),
GregDay(0, Date(0, 12, 31))];
auto testGregDaysAD = [GregDay(1, Date(1, 1, 1)),
GregDay(2, Date(1, 1, 2)),
GregDay(32, Date(1, 2, 1)),
GregDay(365, Date(1, 12, 31)),
GregDay(366, Date(2, 1, 1)),
GregDay(731, Date(3, 1, 1)),
GregDay(1096, Date(4, 1, 1)),
GregDay(1097, Date(4, 1, 2)),
GregDay(1460, Date(4, 12, 30)),
GregDay(1461, Date(4, 12, 31)),
GregDay(1462, Date(5, 1, 1)),
GregDay(17_898, Date(50, 1, 1)),
GregDay(35_065, Date(97, 1, 1)),
GregDay(36_160, Date(100, 1, 1)),
GregDay(36_525, Date(101, 1, 1)),
GregDay(37_986, Date(105, 1, 1)),
GregDay(72_684, Date(200, 1, 1)),
GregDay(73_049, Date(201, 1, 1)),
GregDay(109_208, Date(300, 1, 1)),
GregDay(109_573, Date(301, 1, 1)),
GregDay(145_732, Date(400, 1, 1)),
GregDay(146_098, Date(401, 1, 1)),
GregDay(182_257, Date(500, 1, 1)),
GregDay(182_622, Date(501, 1, 1)),
GregDay(364_878, Date(1000, 1, 1)),
GregDay(365_243, Date(1001, 1, 1)),
GregDay(584_023, Date(1600, 1, 1)),
GregDay(584_389, Date(1601, 1, 1)),
GregDay(693_596, Date(1900, 1, 1)),
GregDay(693_961, Date(1901, 1, 1)),
GregDay(729_755, Date(1999, 1, 1)),
GregDay(730_120, Date(2000, 1, 1)),
GregDay(730_121, Date(2000, 1, 2)),
GregDay(730_484, Date(2000, 12, 30)),
GregDay(730_485, Date(2000, 12, 31)),
GregDay(730_486, Date(2001, 1, 1)),
GregDay(733_773, Date(2010, 1, 1)),
GregDay(733_774, Date(2010, 1, 2)),
GregDay(733_803, Date(2010, 1, 31)),
GregDay(733_804, Date(2010, 2, 1)),
GregDay(733_831, Date(2010, 2, 28)),
GregDay(733_832, Date(2010, 3, 1)),
GregDay(733_862, Date(2010, 3, 31)),
GregDay(733_863, Date(2010, 4, 1)),
GregDay(733_892, Date(2010, 4, 30)),
GregDay(733_893, Date(2010, 5, 1)),
GregDay(733_923, Date(2010, 5, 31)),
GregDay(733_924, Date(2010, 6, 1)),
GregDay(733_953, Date(2010, 6, 30)),
GregDay(733_954, Date(2010, 7, 1)),
GregDay(733_984, Date(2010, 7, 31)),
GregDay(733_985, Date(2010, 8, 1)),
GregDay(734_015, Date(2010, 8, 31)),
GregDay(734_016, Date(2010, 9, 1)),
GregDay(734_045, Date(2010, 9, 30)),
GregDay(734_046, Date(2010, 10, 1)),
GregDay(734_076, Date(2010, 10, 31)),
GregDay(734_077, Date(2010, 11, 1)),
GregDay(734_106, Date(2010, 11, 30)),
GregDay(734_107, Date(2010, 12, 1)),
GregDay(734_136, Date(2010, 12, 30)),
GregDay(734_137, Date(2010, 12, 31)),
GregDay(734_503, Date(2012, 1, 1)),
GregDay(734_534, Date(2012, 2, 1)),
GregDay(734_561, Date(2012, 2, 28)),
GregDay(734_562, Date(2012, 2, 29)),
GregDay(734_563, Date(2012, 3, 1)),
GregDay(734_858, Date(2012, 12, 21))];
//I'd use a Tuple, but I get forward reference errors if I try.
struct DayOfYear { int day; MonthDay md; }
auto testDaysOfYear = [DayOfYear(1, MonthDay(1, 1)),
DayOfYear(2, MonthDay(1, 2)),
DayOfYear(3, MonthDay(1, 3)),
DayOfYear(31, MonthDay(1, 31)),
DayOfYear(32, MonthDay(2, 1)),
DayOfYear(59, MonthDay(2, 28)),
DayOfYear(60, MonthDay(3, 1)),
DayOfYear(90, MonthDay(3, 31)),
DayOfYear(91, MonthDay(4, 1)),
DayOfYear(120, MonthDay(4, 30)),
DayOfYear(121, MonthDay(5, 1)),
DayOfYear(151, MonthDay(5, 31)),
DayOfYear(152, MonthDay(6, 1)),
DayOfYear(181, MonthDay(6, 30)),
DayOfYear(182, MonthDay(7, 1)),
DayOfYear(212, MonthDay(7, 31)),
DayOfYear(213, MonthDay(8, 1)),
DayOfYear(243, MonthDay(8, 31)),
DayOfYear(244, MonthDay(9, 1)),
DayOfYear(273, MonthDay(9, 30)),
DayOfYear(274, MonthDay(10, 1)),
DayOfYear(304, MonthDay(10, 31)),
DayOfYear(305, MonthDay(11, 1)),
DayOfYear(334, MonthDay(11, 30)),
DayOfYear(335, MonthDay(12, 1)),
DayOfYear(363, MonthDay(12, 29)),
DayOfYear(364, MonthDay(12, 30)),
DayOfYear(365, MonthDay(12, 31))];
auto testDaysOfLeapYear = [DayOfYear(1, MonthDay(1, 1)),
DayOfYear(2, MonthDay(1, 2)),
DayOfYear(3, MonthDay(1, 3)),
DayOfYear(31, MonthDay(1, 31)),
DayOfYear(32, MonthDay(2, 1)),
DayOfYear(59, MonthDay(2, 28)),
DayOfYear(60, MonthDay(2, 29)),
DayOfYear(61, MonthDay(3, 1)),
DayOfYear(91, MonthDay(3, 31)),
DayOfYear(92, MonthDay(4, 1)),
DayOfYear(121, MonthDay(4, 30)),
DayOfYear(122, MonthDay(5, 1)),
DayOfYear(152, MonthDay(5, 31)),
DayOfYear(153, MonthDay(6, 1)),
DayOfYear(182, MonthDay(6, 30)),
DayOfYear(183, MonthDay(7, 1)),
DayOfYear(213, MonthDay(7, 31)),
DayOfYear(214, MonthDay(8, 1)),
DayOfYear(244, MonthDay(8, 31)),
DayOfYear(245, MonthDay(9, 1)),
DayOfYear(274, MonthDay(9, 30)),
DayOfYear(275, MonthDay(10, 1)),
DayOfYear(305, MonthDay(10, 31)),
DayOfYear(306, MonthDay(11, 1)),
DayOfYear(335, MonthDay(11, 30)),
DayOfYear(336, MonthDay(12, 1)),
DayOfYear(364, MonthDay(12, 29)),
DayOfYear(365, MonthDay(12, 30)),
DayOfYear(366, MonthDay(12, 31))];
void initializeTests()
{
immutable lt = LocalTime().utcToTZ(0);
currLocalDiffFromUTC = dur!"hnsecs"(lt);
immutable otherTZ = lt < 0 ? TimeZone.getTimeZone("Australia/Sydney")
: TimeZone.getTimeZone("America/Denver");
immutable ot = otherTZ.utcToTZ(0);
auto diffs = [0, lt, ot];
auto diffAA = [0 : Rebindable!(immutable TimeZone)(UTC()),
lt : Rebindable!(immutable TimeZone)(LocalTime()),
ot : Rebindable!(immutable TimeZone)(otherTZ)];
sort(diffs);
testTZs = [diffAA[diffs[0]], diffAA[diffs[1]], diffAA[diffs[2]]];
testFracSecs = [FracSec.from!"hnsecs"(0),
FracSec.from!"hnsecs"(1),
FracSec.from!"hnsecs"(5007),
FracSec.from!"hnsecs"(9999999)];
foreach(year; testYearsBC)
{
foreach(md; testMonthDays)
testDatesBC ~= Date(year, md.month, md.day);
}
foreach(year; testYearsAD)
{
foreach(md; testMonthDays)
testDatesAD ~= Date(year, md.month, md.day);
}
foreach(dt; testDatesBC)
{
foreach(tod; testTODs)
testDateTimesBC ~= DateTime(dt, tod);
}
foreach(dt; testDatesAD)
{
foreach(tod; testTODs)
testDateTimesAD ~= DateTime(dt, tod);
}
foreach(dt; testDateTimesBC)
{
foreach(tz; testTZs)
{
foreach(fs; testFracSecs)
testSysTimesBC ~= SysTime(dt, fs, tz);
}
}
foreach(dt; testDateTimesAD)
{
foreach(tz; testTZs)
{
foreach(fs; testFracSecs)
testSysTimesAD ~= SysTime(dt, fs, tz);
}
}
}
}
//==============================================================================
// Unit testing functions.
//==============================================================================
void _assertPred(string op, L, R)
(L lhs, R rhs, lazy string msg = null, string file = __FILE__, size_t line = __LINE__)
if((op == "<" ||
op == "<=" ||
op == "==" ||
op == "!=" ||
op == ">=" ||
op == ">") &&
__traits(compiles, mixin("lhs " ~ op ~ " rhs")) &&
_isPrintable!L &&
_isPrintable!R)
{
immutable result = mixin("lhs " ~ op ~ " rhs");
if(!result)
{
if(msg.empty)
throw new AssertError(format(`_assertPred!"%s" failed: [%s] is not %s [%s].`, op, lhs, op, rhs), file, line);
else
throw new AssertError(format(`_assertPred!"%s" failed: [%s] is not %s [%s]: %s`, op, lhs, op, rhs, msg), file, line);
}
}
unittest
{
version(testStdDateTime)
{
struct IntWrapper
{
int value;
this(int value)
{
this.value = value;
}
string toString() const
{
return to!string(value);
}
}
//Test ==.
assertNotThrown!AssertError(_assertPred!"=="(6, 6));
assertNotThrown!AssertError(_assertPred!"=="(6, 6.0));
assertNotThrown!AssertError(_assertPred!"=="(IntWrapper(6), IntWrapper(6)));
assertThrown!AssertError(_assertPred!"=="(6, 7));
assertThrown!AssertError(_assertPred!"=="(6, 6.1));
assertThrown!AssertError(_assertPred!"=="(IntWrapper(6), IntWrapper(7)));
assertThrown!AssertError(_assertPred!"=="(IntWrapper(7), IntWrapper(6)));
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"=="(6, 7)),
`_assertPred!"==" failed: [6] is not == [7].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"=="(6, 7, "It failed!")),
`_assertPred!"==" failed: [6] is not == [7]: It failed!`);
//Test !=.
assertNotThrown!AssertError(_assertPred!"!="(6, 7));
assertNotThrown!AssertError(_assertPred!"!="(6, 6.1));
assertNotThrown!AssertError(_assertPred!"!="(IntWrapper(6), IntWrapper(7)));
assertNotThrown!AssertError(_assertPred!"!="(IntWrapper(7), IntWrapper(6)));
assertThrown!AssertError(_assertPred!"!="(6, 6));
assertThrown!AssertError(_assertPred!"!="(6, 6.0));
assertThrown!AssertError(_assertPred!"!="(IntWrapper(6), IntWrapper(6)));
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"!="(6, 6)),
`_assertPred!"!=" failed: [6] is not != [6].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"!="(6, 6, "It failed!")),
`_assertPred!"!=" failed: [6] is not != [6]: It failed!`);
//Test <, <=, >=, >.
assertNotThrown!AssertError(_assertPred!"<"(5, 7));
assertNotThrown!AssertError(_assertPred!"<="(5, 7));
assertNotThrown!AssertError(_assertPred!"<="(5, 5));
assertNotThrown!AssertError(_assertPred!">="(7, 7));
assertNotThrown!AssertError(_assertPred!">="(7, 5));
assertNotThrown!AssertError(_assertPred!">"(7, 5));
assertThrown!AssertError(_assertPred!"<"(7, 5));
assertThrown!AssertError(_assertPred!"<="(7, 5));
assertThrown!AssertError(_assertPred!">="(5, 7));
assertThrown!AssertError(_assertPred!">"(5, 7));
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"<"(7, 5)),
`_assertPred!"<" failed: [7] is not < [5].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"<"(7, 5, "It failed!")),
`_assertPred!"<" failed: [7] is not < [5]: It failed!`);
//Verify Examples.
//Equivalent to assert(5 / 2 + 4 < 27);
_assertPred!"<"(5 / 2 + 4, 27);
//Equivalent to assert(4 <= 5);
_assertPred!"<="(4, 5);
//Equivalent to assert(1 * 2.1 == 2.1);
_assertPred!"=="(1 * 2.1, 2.1);
//Equivalent to assert("hello " ~ "world" != "goodbye world");
_assertPred!"!="("hello " ~ "world", "goodbye world");
//Equivalent to assert(14.2 >= 14);
_assertPred!">="(14.2, 14);
//Equivalent to assert(15 > 2 + 1);
_assertPred!">"(15, 2 + 1);
assert(collectExceptionMsg!AssertError(_assertPred!"=="("hello", "goodbye")) ==
`_assertPred!"==" failed: [hello] is not == [goodbye].`);
assert(collectExceptionMsg!AssertError(_assertPred!"<"(5, 2, "My test failed!")) ==
`_assertPred!"<" failed: [5] is not < [2]: My test failed!`);
}
}
void _assertPred(string func, string expected, L, R)
(L lhs, R rhs, lazy string msg = null, string file = __FILE__, size_t line = __LINE__)
if(func == "opCmp" &&
(expected == "<" ||
expected == "==" ||
expected == ">") &&
__traits(compiles, lhs.opCmp(rhs)) &&
_isPrintable!L &&
_isPrintable!R)
{
immutable result = lhs.opCmp(rhs);
static if(expected == "<")
{
if(result < 0)
return;
if(result == 0)
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", "<") failed: [%s] == [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", "<") failed: [%s] == [%s]: %s`, lhs, rhs, msg), file, line);
}
else
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", "<") failed: [%s] > [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", "<") failed: [%s] > [%s]: %s`, lhs, rhs, msg), file, line);
}
}
else static if(expected == "==")
{
if(result == 0)
return;
if(result < 0)
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", "==") failed: [%s] < [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", "==") failed: [%s] < [%s]: %s`, lhs, rhs, msg), file, line);
}
else
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", "==") failed: [%s] > [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", "==") failed: [%s] > [%s]: %s`, lhs, rhs, msg), file, line);
}
}
else static if(expected == ">")
{
if(result > 0)
return;
if(result < 0)
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", ">") failed: [%s] < [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", ">") failed: [%s] < [%s]: %s`, lhs, rhs, msg), file, line);
}
else
{
if(msg.empty)
throw new AssertError(format(`_assertPred!("opCmp", ">") failed: [%s] == [%s].`, lhs, rhs), file, line);
else
throw new AssertError(format(`_assertPred!("opCmp", ">") failed: [%s] == [%s]: %s`, lhs, rhs, msg), file, line);
}
}
else
static assert(0);
}
void _assertPred(string op, L, R, E)
(L lhs, R rhs, E expected, lazy string msg = null, string file = __FILE__, size_t line = __LINE__)
if((op == "+=" ||
op == "-=" ||
op == "*=" ||
op == "/=" ||
op == "%=" ||
op == "^^=" ||
op == "&=" ||
op == "|=" ||
op == "^=" ||
op == "<<=" ||
op == ">>=" ||
op == ">>>=" ||
op == "~=") &&
__traits(compiles, mixin("lhs " ~ op ~ " rhs")) &&
__traits(compiles, mixin("(lhs " ~ op ~ " rhs) == expected")) &&
_isPrintable!L &&
_isPrintable!R)
{
immutable origLHSStr = to!string(lhs);
const result = mixin("lhs " ~ op ~ " rhs");
if(lhs != expected)
{
if(msg.empty)
{
throw new AssertError(format(`_assertPred!"%s" failed: After [%s] %s [%s], lhs was assigned to [%s] instead of [%s].`,
op,
origLHSStr,
op,
rhs,
lhs,
expected),
file,
line);
}
else
{
throw new AssertError(format(`_assertPred!"%s" failed: After [%s] %s [%s], lhs was assigned to [%s] instead of [%s]: %s`,
op,
origLHSStr,
op,
rhs,
lhs,
expected,
msg),
file,
line);
}
}
if(result != expected)
{
if(msg.empty)
{
throw new AssertError(format(`_assertPred!"%s" failed: Return value of [%s] %s [%s] was [%s] instead of [%s].`,
op,
origLHSStr,
op,
rhs,
result,
expected),
file,
line);
}
else
{
throw new AssertError(format(`_assertPred!"%s" failed: Return value of [%s] %s [%s] was [%s] instead of [%s]: %s`,
op,
origLHSStr,
op,
rhs,
result,
expected,
msg),
file,
line);
}
}
}
unittest
{
version(testStdDateTime)
{
assertNotThrown!AssertError(_assertPred!"+="(7, 5, 12));
assertNotThrown!AssertError(_assertPred!"-="(7, 5, 2));
assertNotThrown!AssertError(_assertPred!"*="(7, 5, 35));
assertNotThrown!AssertError(_assertPred!"/="(7, 5, 1));
assertNotThrown!AssertError(_assertPred!"%="(7, 5, 2));
assertNotThrown!AssertError(_assertPred!"^^="(7, 5, 16_807));
assertNotThrown!AssertError(_assertPred!"&="(7, 5, 5));
assertNotThrown!AssertError(_assertPred!"|="(7, 5, 7));
assertNotThrown!AssertError(_assertPred!"^="(7, 5, 2));
assertNotThrown!AssertError(_assertPred!"<<="(7, 1, 14));
assertNotThrown!AssertError(_assertPred!">>="(7, 1, 3));
assertNotThrown!AssertError(_assertPred!">>>="(-7, 1, 2_147_483_644));
assertNotThrown!AssertError(_assertPred!"~="("hello ", "world", "hello world"));
assertThrown!AssertError(_assertPred!"+="(7, 5, 0));
assertThrown!AssertError(_assertPred!"-="(7, 5, 0));
assertThrown!AssertError(_assertPred!"*="(7, 5, 0));
assertThrown!AssertError(_assertPred!"/="(7, 5, 0));
assertThrown!AssertError(_assertPred!"%="(7, 5, 0));
assertThrown!AssertError(_assertPred!"^^="(7, 5, 0));
assertThrown!AssertError(_assertPred!"&="(7, 5, 0));
assertThrown!AssertError(_assertPred!"|="(7, 5, 0));
assertThrown!AssertError(_assertPred!"^="(7, 5, 0));
assertThrown!AssertError(_assertPred!"<<="(7, 1, 0));
assertThrown!AssertError(_assertPred!">>="(7, 1, 0));
assertThrown!AssertError(_assertPred!">>>="(-7, 1, 0));
assertThrown!AssertError(_assertPred!"~="("hello ", "world", "goodbye world"));
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(7, 5, 11)),
`_assertPred!"+=" failed: After [7] += [5], lhs was assigned to [12] instead of [11].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(7, 5, 11, "It failed!")),
`_assertPred!"+=" failed: After [7] += [5], lhs was assigned to [12] instead of [11]: It failed!`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"^^="(7, 5, 42)),
`_assertPred!"^^=" failed: After [7] ^^= [5], lhs was assigned to [16807] instead of [42].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"^^="(7, 5, 42, "It failed!")),
`_assertPred!"^^=" failed: After [7] ^^= [5], lhs was assigned to [16807] instead of [42]: It failed!`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"~="("hello ", "world", "goodbye world")),
`_assertPred!"~=" failed: After [hello ] ~= [world], lhs was assigned to [hello world] instead of [goodbye world].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"~="("hello ", "world", "goodbye world", "It failed!")),
`_assertPred!"~=" failed: After [hello ] ~= [world], lhs was assigned to [hello world] instead of [goodbye world]: It failed!`);
struct IntWrapper
{
int value;
this(int value)
{
this.value = value;
}
IntWrapper opOpAssign(string op)(IntWrapper rhs)
{
mixin("this.value " ~ op ~ "= rhs.value;");
return this;
}
string toString() const
{
return to!string(value);
}
}
struct IntWrapper_BadAssign
{
int value;
this(int value)
{
this.value = value;
}
IntWrapper_BadAssign opOpAssign(string op)(IntWrapper_BadAssign rhs)
{
auto old = this.value;
mixin("this.value " ~ op ~ "= -rhs.value;");
return IntWrapper_BadAssign(mixin("old " ~ op ~ " rhs.value"));
}
string toString() const
{
return to!string(value);
}
}
struct IntWrapper_BadReturn
{
int value;
this(int value)
{
this.value = value;
}
IntWrapper_BadReturn opOpAssign(string op)(IntWrapper_BadReturn rhs)
{
mixin("this.value " ~ op ~ "= rhs.value;");
return IntWrapper_BadReturn(rhs.value);
}
string toString() const
{
return to!string(value);
}
}
assertNotThrown!AssertError(_assertPred!"+="(IntWrapper(5), IntWrapper(2), IntWrapper(7)));
assertNotThrown!AssertError(_assertPred!"*="(IntWrapper(5), IntWrapper(2), IntWrapper(10)));
assertThrown!AssertError(_assertPred!"+="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(7)));
assertThrown!AssertError(_assertPred!"+="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(7)));
assertThrown!AssertError(_assertPred!"*="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(10)));
assertThrown!AssertError(_assertPred!"*="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(10)));
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(7))),
`_assertPred!"+=" failed: After [5] += [2], lhs was assigned to [3] instead of [7].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(7), "It failed!")),
`_assertPred!"+=" failed: After [5] += [2], lhs was assigned to [3] instead of [7]: It failed!`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(7))),
`_assertPred!"+=" failed: Return value of [5] += [2] was [2] instead of [7].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"+="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(7), "It failed!")),
`_assertPred!"+=" failed: Return value of [5] += [2] was [2] instead of [7]: It failed!`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"*="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(10))),
`_assertPred!"*=" failed: After [5] *= [2], lhs was assigned to [-10] instead of [10].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"*="(IntWrapper_BadAssign(5), IntWrapper_BadAssign(2), IntWrapper_BadAssign(10), "It failed!")),
`_assertPred!"*=" failed: After [5] *= [2], lhs was assigned to [-10] instead of [10]: It failed!`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"*="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(10))),
`_assertPred!"*=" failed: Return value of [5] *= [2] was [2] instead of [10].`);
_assertPred!"=="(collectExceptionMsg!AssertError(_assertPred!"*="(IntWrapper_BadReturn(5), IntWrapper_BadReturn(2), IntWrapper_BadReturn(10), "It failed!")),
`_assertPred!"*=" failed: Return value of [5] *= [2] was [2] instead of [10]: It failed!`);
}
}
unittest
{
/* Issue 6642 */
static assert(!hasUnsharedAliasing!Date);
static assert(!hasUnsharedAliasing!TimeOfDay);
static assert(!hasUnsharedAliasing!DateTime);
static assert(!hasUnsharedAliasing!SysTime);
}
template _isPrintable(T...)
{
static if(T.length == 0)
enum _isPrintable = true;
else static if(T.length == 1)
{
enum _isPrintable = (!isArray!(T[0]) && __traits(compiles, to!string(T[0].init))) ||
(isArray!(T[0]) && __traits(compiles, to!string(T[0].init[0])));
}
else
{
enum _isPrintable = _isPrintable!(T[0]) && _isPrintable!(T[1 .. $]);
}
}
| D |
/Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/Objects-normal/x86_64/DateTransform.o : /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/FromJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ToJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ImmutableMappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformType.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOf.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/URLTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DataTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CodableTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateFormatterTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/HexColorTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DictionaryTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Map.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mapper.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/MapError.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Operators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/IntegerOperators.swift /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/ObjectiveC.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreImage.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/QuartzCore.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Dispatch.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Metal.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Darwin.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreFoundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreGraphics.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/UIKit.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/SwiftOnoneSupport.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Combine.framework/Modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftinterface /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/Target\ Support\ Files/ObjectMapper/ObjectMapper-umbrella.h /Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/Objects-normal/x86_64/DateTransform~partial.swiftmodule : /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/FromJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ToJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ImmutableMappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformType.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOf.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/URLTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DataTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CodableTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateFormatterTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/HexColorTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DictionaryTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Map.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mapper.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/MapError.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Operators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/IntegerOperators.swift /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/ObjectiveC.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreImage.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/QuartzCore.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Dispatch.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Metal.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Darwin.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreFoundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreGraphics.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/UIKit.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/SwiftOnoneSupport.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Combine.framework/Modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftinterface /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/Target\ Support\ Files/ObjectMapper/ObjectMapper-umbrella.h /Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/Objects-normal/x86_64/DateTransform~partial.swiftdoc : /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/FromJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ToJSON.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ImmutableMappable.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformType.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOf.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/URLTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DataTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CodableTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DateFormatterTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/HexColorTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/DictionaryTransform.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Map.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Mapper.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/MapError.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/Operators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/TransformOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/EnumOperators.swift /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/ObjectMapper/Sources/IntegerOperators.swift /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/ObjectiveC.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreImage.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/QuartzCore.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Dispatch.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Metal.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Darwin.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreFoundation.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/CoreGraphics.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/UIKit.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/lib/swift/SwiftOnoneSupport.swiftmodule/x86_64.swiftinterface /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Combine.framework/Modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftinterface /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/macosx/Desktop/IOS-OBJ/ViberDemo/Pods/Target\ Support\ Files/ObjectMapper/ObjectMapper-umbrella.h /Users/macosx/Desktop/IOS-OBJ/ViberDemo/build/Pods.build/Debug-iphonesimulator/ObjectMapper.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
| D |
/*
Файл: LinkSeq.d
Originally записано by Doug Lea и released преобр_в the public домен.
Thanks for the assistance и support of Sun Microsystems Labs, Agorics
Inc, Loral, и everyone contributing, testing, и using this код.
History:
Дата Who What
2Oct95 [email protected] repack из_ LLSeq.d
9apr97 dl вставь bounds проверь in первый
*/
module util.collection.LinkSeq;
private import util.collection.model.Iterator,
util.collection.model.Sortable,
util.collection.model.Comparator,
util.collection.model.GuardIterator;
private import util.collection.impl.LLCell,
util.collection.impl.SeqCollection,
util.collection.impl.AbstractIterator;
/**
*
* LinkedList implementation.
* Publically реализует only those methods defined in its interfaces.
*
*
author: Doug Lea
* @version 0.93
*
* <P> For an introduction в_ this package see <A HREF="индекс.html"> Overview </A>.
**/
deprecated public class LinkSeq(T) : SeqCollection!(T), Sortable!(T)
{
alias LLCell!(T) LLCellT;
alias SeqCollection!(T).удали удали;
alias SeqCollection!(T).удалиВсе удалиВсе;
// экземпляр variables
/**
* The голова of the список. Пусто iff счёт == 0
**/
package LLCellT список;
// constructors
/**
* Созд a new пустой список
**/
public this ()
{
this(пусто, пусто, 0);
}
/**
* Созд a список with a given элемент скринер
**/
public this (Предикат скринер)
{
this(скринер, пусто, 0);
}
/**
* Special version of constructor needed by клонируй()
**/
protected this (Предикат s, LLCellT l, цел c)
{
super(s);
список = l;
счёт = c;
}
/**
* Build an independent копируй of the список.
* The элементы themselves are not cloned
**/
// protected Объект клонируй() {
public LinkSeq!(T) дубликат()
{
if (список is пусто)
return new LinkSeq!(T)(скринер, пусто, 0);
else
return new LinkSeq!(T)(скринер, список.копируйСписок(), счёт);
}
// Коллекция methods
/**
* Implements util.collection.impl.Collection.Коллекция.содержит
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.содержит
**/
public final бул содержит(T элемент)
{
if (!действительныйАргумент(элемент) || счёт is 0)
return нет;
return список.найди(элемент) !is пусто;
}
/**
* Implements util.collection.impl.Collection.Коллекция.экземпляры
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.экземпляры
**/
public final бцел экземпляры(T элемент)
{
if (!действительныйАргумент(элемент) || счёт is 0)
return 0;
return список.счёт(элемент);
}
/**
* Implements util.collection.impl.Collection.Коллекция.элементы
* Время complexity: O(1).
* See_Also: util.collection.impl.Collection.Коллекция.элементы
**/
public final GuardIterator!(T) элементы()
{
return new CellIterator!(T)(this);
}
/**
* Implements util.collection.model.View.View.opApply
* Время complexity: O(n).
* See_Also: util.collection.model.View.View.opApply
**/
цел opApply (цел delegate (inout T значение) дг)
{
auto scope обходчик = new CellIterator!(T)(this);
return обходчик.opApply (дг);
}
// Seq Methods
/**
* Implements util.collection.model.Seq.Seq.голова.
* Время complexity: O(1).
* See_Also: util.collection.model.Seq.Seq.голова
**/
public final T голова()
{
return перваяЯчейка().элемент();
}
/**
* Implements util.collection.model.Seq.Seq.хвост.
* Время complexity: O(n).
* See_Also: util.collection.model.Seq.Seq.хвост
**/
public final T хвост()
{
return последняяЯчейка().элемент();
}
/**
* Implements util.collection.model.Seq.Seq.получи.
* Время complexity: O(n).
* See_Also: util.collection.model.Seq.Seq.получи
**/
public final T получи(цел индекс)
{
return ячейкаПо(индекс).элемент();
}
/**
* Implements util.collection.model.Seq.Seq.первый.
* Время complexity: O(n).
* See_Also: util.collection.model.Seq.Seq.первый
**/
public final цел первый(T элемент, цел startingIndex = 0)
{
if (!действительныйАргумент(элемент) || список is пусто || startingIndex >= счёт)
return -1;
if (startingIndex < 0)
startingIndex = 0;
LLCellT p = список.н_ый(startingIndex);
if (p !is пусто)
{
цел i = p.индекс(элемент);
if (i >= 0)
return i + startingIndex;
}
return -1;
}
/**
* Implements util.collection.model.Seq.Seq.последний.
* Время complexity: O(n).
* See_Also: util.collection.model.Seq.Seq.последний
**/
public final цел последний(T элемент, цел startingIndex = 0)
{
if (!действительныйАргумент(элемент) || список is пусто)
return -1;
цел i = 0;
if (startingIndex >= размер())
startingIndex = размер() - 1;
цел индекс = -1;
LLCellT p = список;
while (i <= startingIndex && p !is пусто)
{
if (p.элемент() == (элемент))
индекс = i;
++i;
p = p.следщ();
}
return индекс;
}
/**
* Implements util.collection.model.Seq.Seq.subseq.
* Время complexity: O(length).
* See_Also: util.collection.model.Seq.Seq.subseq
**/
public final LinkSeq поднабор(цел из_, цел _length)
{
if (_length > 0)
{
LLCellT p = ячейкаПо(из_);
LLCellT новый_список = new LLCellT(p.элемент(), пусто);
LLCellT текущ = новый_список;
for (цел i = 1; i < _length; ++i)
{
p = p.следщ();
if (p is пусто)
проверьИндекс(из_ + i); // force исключение
текущ.вяжиСледщ(new LLCellT(p.элемент(), пусто));
текущ = текущ.следщ();
}
return new LinkSeq!(T)(скринер, новый_список, _length);
}
else
return new LinkSeq!(T)(скринер, пусто, 0);
}
// MutableCollection methods
/**
* Implements util.collection.impl.Collection.Коллекция.очисть.
* Время complexity: O(1).
* See_Also: util.collection.impl.Collection.Коллекция.очисть
**/
public final проц очисть()
{
if (список !is пусто)
{
список = пусто;
устСчёт(0);
}
}
/**
* Implements util.collection.impl.Collection.Коллекция.exclude.
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.exclude
**/
public final проц удалиВсе (T элемент)
{
удали_(элемент, да);
}
/**
* Implements util.collection.impl.Collection.Коллекция.removeOneOf.
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.removeOneOf
**/
public final проц удали (T элемент)
{
удали_(элемент, нет);
}
/**
* Implements util.collection.impl.Collection.Коллекция.replaceOneOf
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.replaceOneOf
**/
public final проц замени (T старЭлемент, T новЭлемент)
{
замени_(старЭлемент, новЭлемент, нет);
}
/**
* Implements util.collection.impl.Collection.Коллекция.replaceAllOf.
* Время complexity: O(n).
* See_Also: util.collection.impl.Collection.Коллекция.replaceAllOf
**/
public final проц замениВсе(T старЭлемент, T новЭлемент)
{
замени_(старЭлемент, новЭлемент, да);
}
/**
* Implements util.collection.impl.Collection.Коллекция.возьми.
* Время complexity: O(1).
* takes the первый элемент on the список
* See_Also: util.collection.impl.Collection.Коллекция.возьми
**/
public final T возьми()
{
T v = голова();
удалиГолову();
return v;
}
// Sortable methods
/**
* Implements util.collection.Sortable.сортируй.
* Время complexity: O(n лог n).
* Uses a merge-сортируй-based algorithm.
* See_Also: util.collection.SortableCollection.сортируй
**/
public final проц сортируй(Сравнитель!(T) cmp)
{
if (список !is пусто)
{
список = LLCellT.mergeSort(список, cmp);
incVersion();
}
}
// MutableSeq methods
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.приставь.
* Время complexity: O(1).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.приставь
**/
public final проц приставь(T элемент)
{
проверьЭлемент(элемент);
список = new LLCellT(элемент, список);
incCount();
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.замениГолову.
* Время complexity: O(1).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.замениГолову
**/
public final проц замениГолову(T элемент)
{
проверьЭлемент(элемент);
перваяЯчейка().элемент(элемент);
incVersion();
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.удалиГолову.
* Время complexity: O(1).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.удалиГолову
**/
public final проц удалиГолову()
{
список = перваяЯчейка().следщ();
decCount();
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.добавь.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.добавь
**/
public final проц добавь(T элемент)
{
проверьЭлемент(элемент);
if (список is пусто)
приставь(элемент);
else
{
список.хвост().следщ(new LLCellT(элемент));
incCount();
}
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.замениХвост.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.замениХвост
**/
public final проц замениХвост(T элемент)
{
проверьЭлемент(элемент);
последняяЯчейка().элемент(элемент);
incVersion();
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.удалиХвост.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.удалиХвост
**/
public final проц удалиХвост()
{
if (перваяЯчейка().следщ() is пусто)
удалиГолову();
else
{
LLCellT trail = список;
LLCellT p = trail.следщ();
while (p.следщ() !is пусто)
{
trail = p;
p = p.следщ();
}
trail.следщ(пусто);
decCount();
}
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.добавьПо.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.добавьПо
**/
public final проц добавьПо(цел индекс, T элемент)
{
if (индекс is 0)
приставь(элемент);
else
{
проверьЭлемент(элемент);
ячейкаПо(индекс - 1).вяжиСледщ(new LLCellT(элемент));
incCount();
}
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.удалиПо.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.удалиПо
**/
public final проц удалиПо(цел индекс)
{
if (индекс is 0)
удалиГолову();
else
{
ячейкаПо(индекс - 1).отвяжиСледщ();
decCount();
}
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.замениПо.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.замениПо
**/
public final проц замениПо(цел индекс, T элемент)
{
ячейкаПо(индекс).элемент(элемент);
incVersion();
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.приставь.
* Время complexity: O(число of элементы in e).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.приставь
**/
public final проц приставь(Обходчик!(T) e)
{
splice_(e, пусто, список);
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.добавь.
* Время complexity: O(n + число of элементы in e).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.добавь
**/
public final проц добавь(Обходчик!(T) e)
{
if (список is пусто)
splice_(e, пусто, пусто);
else
splice_(e, список.хвост(), пусто);
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.добавьПо.
* Время complexity: O(n + число of элементы in e).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.добавьПо
**/
public final проц добавьПо(цел индекс, Обходчик!(T) e)
{
if (индекс is 0)
splice_(e, пусто, список);
else
{
LLCellT p = ячейкаПо(индекс - 1);
splice_(e, p, p.следщ());
}
}
/**
* Implements util.collection.impl.SeqCollection.SeqCollection.removeFromTo.
* Время complexity: O(n).
* See_Also: util.collection.impl.SeqCollection.SeqCollection.removeFromTo
**/
public final проц удалиДиапазон (цел отИндекса, цел доИндекса)
{
проверьИндекс(доИндекса);
if (отИндекса <= доИндекса)
{
if (отИндекса is 0)
{
LLCellT p = перваяЯчейка();
for (цел i = отИндекса; i <= доИндекса; ++i)
p = p.следщ();
список = p;
}
else
{
LLCellT f = ячейкаПо(отИндекса - 1);
LLCellT p = f;
for (цел i = отИндекса; i <= доИндекса; ++i)
p = p.следщ();
f.следщ(p.следщ());
}
добавьToCount( -(доИндекса - отИндекса + 1));
}
}
// helper methods
private final LLCellT перваяЯчейка()
{
if (список !is пусто)
return список;
проверьИндекс(0);
return пусто; // not reached!
}
private final LLCellT последняяЯчейка()
{
if (список !is пусто)
return список.хвост();
проверьИндекс(0);
return пусто; // not reached!
}
private final LLCellT ячейкаПо(цел индекс)
{
проверьИндекс(индекс);
return список.н_ый(индекс);
}
/**
* Helper метод for removeOneOf()
**/
private final проц удали_(T элемент, бул всеСлучаи)
{
if (!действительныйАргумент(элемент) || счёт is 0)
return ;
LLCellT p = список;
LLCellT trail = p;
while (p !is пусто)
{
LLCellT n = p.следщ();
if (p.элемент() == (элемент))
{
decCount();
if (p is список)
{
список = n;
trail = n;
}
else
trail.следщ(n);
if (!всеСлучаи || счёт is 0)
return ;
else
p = n;
}
else
{
trail = p;
p = n;
}
}
}
/**
* Helper for замени
**/
private final проц замени_(T старЭлемент, T новЭлемент, бул всеСлучаи)
{
if (счёт is 0 || !действительныйАргумент(старЭлемент) || старЭлемент == (новЭлемент))
return ;
LLCellT p = список.найди(старЭлемент);
while (p !is пусто)
{
проверьЭлемент(новЭлемент);
p.элемент(новЭлемент);
incVersion();
if (!всеСлучаи)
return ;
p = p.найди(старЭлемент);
}
}
/**
* Splice элементы of e between hd и tl. if hd is пусто return new hd
**/
private final проц splice_(Обходчик!(T) e, LLCellT hd, LLCellT tl)
{
if (e.ещё())
{
LLCellT новый_список = пусто;
LLCellT текущ = пусто;
while (e.ещё())
{
T v = e.получи();
проверьЭлемент(v);
incCount();
LLCellT p = new LLCellT(v, пусто);
if (новый_список is пусто)
новый_список = p;
else
текущ.следщ(p);
текущ = p;
}
if (текущ !is пусто)
текущ.следщ(tl);
if (hd is пусто)
список = новый_список;
else
hd.следщ(новый_список);
}
}
// ImplementationCheckable methods
/**
* Implements util.collection.model.View.View.проверьРеализацию.
* See_Also: util.collection.model.View.View.проверьРеализацию
**/
public override проц проверьРеализацию()
{
super.проверьРеализацию();
assert(((счёт is 0) is (список is пусто)));
assert((список is пусто || список._length() is счёт));
цел c = 0;
for (LLCellT p = список; p !is пусто; p = p.следщ())
{
assert(allows(p.элемент()));
assert(экземпляры(p.элемент()) > 0);
assert(содержит(p.элемент()));
++c;
}
assert(c is счёт);
}
/***********************************************************************
opApply() имеется migrated here в_ mitigate the virtual вызов
on метод получи()
************************************************************************/
private static class CellIterator(T) : AbstractIterator!(T)
{
private LLCellT ячейка;
public this (LinkSeq пследвтн)
{
super (пследвтн);
ячейка = пследвтн.список;
}
public final T получи()
{
decRemaining();
auto v = ячейка.элемент();
ячейка = ячейка.следщ();
return v;
}
цел opApply (цел delegate (inout T значение) дг)
{
цел результат;
for (auto i=остаток(); i--;)
{
auto значение = получи();
if ((результат = дг(значение)) != 0)
break;
}
return результат;
}
}
}
debug (Test)
{
import io.Console;
проц main()
{
auto пследвтн = new LinkSeq!(ткст);
пследвтн.добавь ("foo");
пследвтн.добавь ("wumpus");
пследвтн.добавь ("bar");
foreach (значение; пследвтн.элементы) {}
auto элементы = пследвтн.элементы();
while (элементы.ещё)
auto v = элементы.получи();
foreach (значение; пследвтн)
Квывод (значение).нс;
пследвтн.проверьРеализацию();
}
}
| D |
/*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage
/*
* Conversion parameters:
* inFile = gobject-Type-Information.html
* outPack = gobject
* outFile = Type
* strct =
* realStrct=
* ctorStrct=
* clss = Type
* interf =
* class Code: Yes
* interface Code: No
* template for:
* extend =
* implements:
* prefixes:
* - g_type_
* omit structs:
* - GTypeClass
* - GTypeInstance
* - GTypeInterface
* omit prefixes:
* omit code:
* omit signals:
* imports:
* - gtkD.glib.Str
* - gtkD.gobject.ObjectG
* - gtkD.gobject.TypePlugin
* structWrap:
* - GTypePlugin* -> TypePlugin
* module aliases:
* local aliases:
* overrides:
*/
module gtkD.gobject.Type;
public import gtkD.gtkc.gobjecttypes;
private import gtkD.gtkc.gobject;
private import gtkD.glib.ConstructionException;
private import gtkD.glib.Str;
private import gtkD.gobject.ObjectG;
private import gtkD.gobject.TypePlugin;
/**
* Description
* The GType API is the foundation of the GObject system. It provides the
* facilities for registering and managing all fundamental data types,
* user-defined object and interface types. Before using any GType
* or GObject functions, g_type_init() must be called to initialize the
* type system.
* For type creation and registration purposes, all types fall into one of
* two categories: static or dynamic. Static types are never loaded or
* unloaded at run-time as dynamic types may be. Static types are created
* with g_type_register_static() that gets type specific information passed
* in via a GTypeInfo structure.
* Dynamic types are created with g_type_register_dynamic() which takes a
* GTypePlugin structure instead. The remaining type information (the
* GTypeInfo structure) is retrieved during runtime through GTypePlugin
* and the g_type_plugin_*() API.
* These registration functions are usually called only once from a
* function whose only purpose is to return the type identifier for a
* specific class. Once the type (or class or interface) is registered,
* it may be instantiated, inherited, or implemented depending on exactly
* what sort of type it is.
* There is also a third registration function for registering fundamental
* types called g_type_register_fundamental() which requires both a GTypeInfo
* structure and a GTypeFundamentalInfo structure but it is seldom used
* since most fundamental types are predefined rather than user-defined.
* A final word about type names.
* Such an identifier needs to be at least three characters long. There is no
* upper length limit. The first character needs to be a letter (a-z or A-Z)
* or an underscore '_'. Subsequent characters can be letters, numbers or
* any of '-_+'.
*/
public class Type
{
public static T* getInstanceClass(T)(ObjectG obj)
{
return cast(T*) (cast(GTypeInstance*)obj.getObjectGStruct()).gClass;
}
/**
* Get the unique name that is assigned to the Objects type.
* Returns: Static type name or NULL.
*/
public static string name(ObjectG obj)
{
GType type = (cast(GTypeInstance*)obj.getObjectGStruct()).gClass.gType;
return name(type);
}
/**
*/
/**
* Prior to any use of the type system, g_type_init() has to be called
* to initialize the type system and assorted other code portions
* (such as the various fundamental type implementations or the signal
* system).
*/
public static void init()
{
// void g_type_init (void);
g_type_init();
}
/**
* Similar to g_type_init(), but additionally sets debug flags.
* Params:
* debugFlags = Bitwise combination of GTypeDebugFlags values for
* debugging purposes.
*/
public static void initWithDebugFlags(GTypeDebugFlags debugFlags)
{
// void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags);
g_type_init_with_debug_flags(debugFlags);
}
/**
* Get the unique name that is assigned to a type ID. Note that this
* function (like all other GType API) cannot cope with invalid type
* IDs. G_TYPE_INVALID may be passed to this function, as may be any
* other validly registered type ID, but randomized type IDs should
* not be passed in and will most likely lead to a crash.
* Params:
* type = Type to return name for.
* Returns: Static type name or NULL.
*/
public static string name(GType type)
{
// const gchar* g_type_name (GType type);
return Str.toString(g_type_name(type));
}
/**
* Get the corresponding quark of the type IDs name.
* Params:
* type = Type to return quark of type name for.
* Returns: The type names quark or 0.
*/
public static GQuark qname(GType type)
{
// GQuark g_type_qname (GType type);
return g_type_qname(type);
}
/**
* Lookup the type ID from a given type name, returning 0 if no type
* has been registered under this name (this is the preferred method
* to find out by name whether a specific type has been registered
* yet).
* Params:
* name = Type name to lookup.
* Returns: Corresponding type ID or 0.
*/
public static GType fromName(string name)
{
// GType g_type_from_name (const gchar *name);
return g_type_from_name(Str.toStringz(name));
}
/**
* Return the direct parent type of the passed in type. If the passed
* in type has no parent, i.e. is a fundamental type, 0 is returned.
* Params:
* type = The derived type.
* Returns: The parent type.
*/
public static GType parent(GType type)
{
// GType g_type_parent (GType type);
return g_type_parent(type);
}
/**
* Returns the length of the ancestry of the passed in type. This
* includes the type itself, so that e.g. a fundamental type has depth 1.
* Params:
* type = A GType value.
* Returns: The depth of type.
*/
public static uint depth(GType type)
{
// guint g_type_depth (GType type);
return g_type_depth(type);
}
/**
* Given a leaf_type and a root_type which is contained in its
* anchestry, return the type that root_type is the immediate parent
* of. In other words, this function determines the type that is
* derived directly from root_type which is also a base class of
* leaf_type. Given a root type and a leaf type, this function can
* be used to determine the types and order in which the leaf type is
* descended from the root type.
* Params:
* leafType = Descendant of root_type and the type to be returned.
* rootType = Immediate parent of the returned type.
* Returns: Immediate child of root_type and anchestor of leaf_type.
*/
public static GType nextBase(GType leafType, GType rootType)
{
// GType g_type_next_base (GType leaf_type, GType root_type);
return g_type_next_base(leafType, rootType);
}
/**
* If is_a_type is a derivable type, check whether type is a
* descendant of is_a_type. If is_a_type is an interface, check
* whether type conforms to it.
* Params:
* type = Type to check anchestry for.
* isAType = Possible anchestor of type or interface type could conform to.
* Returns: TRUE if type is_a is_a_type holds true.
*/
public static int isA(GType type, GType isAType)
{
// gboolean g_type_is_a (GType type, GType is_a_type);
return g_type_is_a(type, isAType);
}
/**
* Increments the reference count of the class structure belonging to
* type. This function will demand-create the class if it doesn't
* exist already.
* Params:
* type = Type ID of a classed type.
* Returns: The GTypeClass structure for the given type ID.
*/
public static void* classRef(GType type)
{
// gpointer g_type_class_ref (GType type);
return g_type_class_ref(type);
}
/**
* This function is essentially the same as g_type_class_ref(), except that
* the classes reference count isn't incremented. As a consequence, this function
* may return NULL if the class of the type passed in does not currently
* exist (hasn't been referenced before).
* Params:
* type = Type ID of a classed type.
* Returns: The GTypeClass structure for the given type ID or NULL if the class does not currently exist.
*/
public static void* classPeek(GType type)
{
// gpointer g_type_class_peek (GType type);
return g_type_class_peek(type);
}
/**
* A more efficient version of g_type_class_peek() which works only for
* static types.
* Since 2.4
* Params:
* type = Type ID of a classed type.
* Returns: The GTypeClass structure for the given type ID or NULL if the class does not currently exist or is dynamically loaded.
*/
public static void* classPeekStatic(GType type)
{
// gpointer g_type_class_peek_static (GType type);
return g_type_class_peek_static(type);
}
/**
* Decrements the reference count of the class structure being passed in.
* Once the last reference count of a class has been released, classes
* may be finalized by the type system, so further dereferencing of a
* class pointer after g_type_class_unref() are invalid.
* Params:
* gClass = The GTypeClass structure to unreference.
*/
public static void classUnref(void* gClass)
{
// void g_type_class_unref (gpointer g_class);
g_type_class_unref(gClass);
}
/**
* This is a convenience function often needed in class initializers.
* It returns the class structure of the immediate parent type of the
* class passed in. Since derived classes hold a reference count on
* their parent classes as long as they are instantiated, the returned
* class will always exist. This function is essentially equivalent
* Params:
* gClass = The GTypeClass structure to retrieve the parent class for.
* Returns: The parent class of g_class.
*/
public static void* classPeekParent(void* gClass)
{
// gpointer g_type_class_peek_parent (gpointer g_class);
return g_type_class_peek_parent(gClass);
}
/**
* Registers a private structure for an instantiatable type;
* when an object is allocated, the private structures for
* the type and all of its parent types are allocated
* sequentially in the same memory block as the public
* structures. This function should be called in the
* type's class_init() function. The private structure can
* be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro.
* The following example shows attaching a private structure
* MyObjectPrivate to an object
* MyObject defined in the standard GObject
* fashion.
* typedef struct _MyObjectPrivate MyObjectPrivate;
* struct _MyObjectPrivate {
* int some_field;
* };
* #define MY_OBJECT_GET_PRIVATE(o) \
* (G_TYPE_INSTANCE_GET_PRIVATE ((o), MY_TYPE_OBJECT, MyObjectPrivate))
* static void
* my_object_class_init (MyObjectClass *klass)
* {
* g_type_class_add_private (klass, sizeof (MyObjectPrivate));
* }
* static int
* my_object_get_some_field (MyObject *my_object)
* {
* MyObjectPrivate *priv = MY_OBJECT_GET_PRIVATE (my_object);
* return priv->some_field;
* }
* Since 2.4
* Params:
* gClass = class structure for an instantiatable type
* privateSize = size of private structure.
*/
public static void classAddPrivate(void* gClass, uint privateSize)
{
// void g_type_class_add_private (gpointer g_class, gsize private_size);
g_type_class_add_private(gClass, privateSize);
}
/**
* Returns the GTypeInterface structure of an interface to which the
* passed in class conforms.
* Params:
* instanceClass = A GTypeClass structure.
* ifaceType = An interface ID which this class conforms to.
* Returns: The GTypeInterface structure of iface_type if implemented by instance_class, NULL otherwise
*/
public static void* interfacePeek(void* instanceClass, GType ifaceType)
{
// gpointer g_type_interface_peek (gpointer instance_class, GType iface_type);
return g_type_interface_peek(instanceClass, ifaceType);
}
/**
* Returns the corresponding GTypeInterface structure of the parent type
* of the instance type to which g_iface belongs. This is useful when
* deriving the implementation of an interface from the parent type and
* then possibly overriding some methods.
* Params:
* gIface = A GTypeInterface structure.
* Returns: The corresponding GTypeInterface structure of the parent type of the instance type to which g_iface belongs, or NULL if the parent type doesn't conform to the interface.
*/
public static void* interfacePeekParent(void* gIface)
{
// gpointer g_type_interface_peek_parent (gpointer g_iface);
return g_type_interface_peek_parent(gIface);
}
/**
* Increments the reference count for the interface type g_type,
* and returns the default interface vtable for the type.
* If the type is not currently in use, then the default vtable
* for the type will be created and initalized by calling
* the base interface init and default vtable init functions for
* the type (the @base_init
* and class_init members of GTypeInfo).
* Calling g_type_default_interface_ref() is useful when you
* want to make sure that signals and properties for an interface
* have been installed.
* Since 2.4
* Params:
* gType = an interface type
* Returns: the default vtable for the interface; call g_type_default_interface_unref() when you are done using the interface.
*/
public static void* defaultInterfaceRef(GType gType)
{
// gpointer g_type_default_interface_ref (GType g_type);
return g_type_default_interface_ref(gType);
}
/**
* If the interface type g_type is currently in use, returns its
* default interface vtable.
* Since 2.4
* Params:
* gType = an interface type
* Returns: the default vtable for the interface, or NULL if the type is not currently in use.
*/
public static void* defaultInterfacePeek(GType gType)
{
// gpointer g_type_default_interface_peek (GType g_type);
return g_type_default_interface_peek(gType);
}
/**
* Decrements the reference count for the type corresponding to the
* interface default vtable g_iface. If the type is dynamic, then
* when no one is using the interface and all references have
* been released, the finalize function for the interface's default
* vtable (the class_finalize member of
* GTypeInfo) will be called.
* Since 2.4
* Params:
* gIface = the default vtable structure for a interface, as
* returned by g_type_default_interface_ref()
*/
public static void defaultInterfaceUnref(void* gIface)
{
// void g_type_default_interface_unref (gpointer g_iface);
g_type_default_interface_unref(gIface);
}
/**
* Return a newly allocated and 0-terminated array of type IDs, listing the
* child types of type. The return value has to be g_free()ed after use.
* Params:
* type = The parent type.
* Returns: Newly allocated and 0-terminated array of child types.
*/
public static GType[] children(GType type)
{
// GType* g_type_children (GType type, guint *n_children);
uint nChildren;
auto p = g_type_children(type, &nChildren);
return p[0 .. nChildren];
}
/**
* Return a newly allocated and 0-terminated array of type IDs, listing the
* interface types that type conforms to. The return value has to be
* g_free()ed after use.
* Params:
* type = The type to list interface types for.
* Returns: Newly allocated and 0-terminated array of interface types.
*/
public static GType[] interfaces(GType type)
{
// GType* g_type_interfaces (GType type, guint *n_interfaces);
uint nInterfaces;
auto p = g_type_interfaces(type, &nInterfaces);
return p[0 .. nInterfaces];
}
/**
* Returns the prerequisites of an interfaces type.
* Since 2.2
* Params:
* interfaceType = an interface type
* Returns: a newly-allocated zero-terminated array of GType containing the prerequisites of interface_type
*/
public static GType[] interfacePrerequisites(GType interfaceType)
{
// GType* g_type_interface_prerequisites (GType interface_type, guint *n_prerequisites);
uint nPrerequisites;
auto p = g_type_interface_prerequisites(interfaceType, &nPrerequisites);
return p[0 .. nPrerequisites];
}
/**
* Attaches arbitrary data to a type.
* Params:
* type = a GType
* quark = a GQuark id to identify the data
* data = the data
*/
public static void setQdata(GType type, GQuark quark, void* data)
{
// void g_type_set_qdata (GType type, GQuark quark, gpointer data);
g_type_set_qdata(type, quark, data);
}
/**
* Obtains data which has previously been attached to type
* with g_type_set_qdata().
* Params:
* type = a GType
* quark = a GQuark id to identify the data
* Returns: the data, or NULL if no data was found
*/
public static void* getQdata(GType type, GQuark quark)
{
// gpointer g_type_get_qdata (GType type, GQuark quark);
return g_type_get_qdata(type, quark);
}
/**
* Queries the type system for information about a specific type.
* This function will fill in a user-provided structure to hold
* type-specific information. If an invalid GType is passed in, the
* type member of the GTypeQuery is 0. All members filled into the
* GTypeQuery structure should be considered constant and have to be
* left untouched.
* Params:
* type = the GType value of a static, classed type.
* query = A user provided structure that is filled in with constant values
* upon success.
*/
public static void query(GType type, out GTypeQuery query)
{
// void g_type_query (GType type, GTypeQuery *query);
g_type_query(type, &query);
}
/**
* Registers type_name as the name of a new static type derived from
* parent_type. The type system uses the information contained in the
* GTypeInfo structure pointed to by info to manage the type and its
* instances (if not abstract). The value of flags determines the nature
* (e.g. abstract or not) of the type.
* Params:
* parentType = Type from which this type will be derived.
* typeName = 0-terminated string used as the name of the new type.
* info = The GTypeInfo structure for this type.
* flags = Bitwise combination of GTypeFlags values.
* Returns: The new type identifier.
*/
public static GType registerStatic(GType parentType, string typeName, GTypeInfo* info, GTypeFlags flags)
{
// GType g_type_register_static (GType parent_type, const gchar *type_name, const GTypeInfo *info, GTypeFlags flags);
return g_type_register_static(parentType, Str.toStringz(typeName), info, flags);
}
/**
* Registers type_name as the name of a new static type derived from
* parent_type. The value of flags determines the nature (e.g.
* abstract or not) of the type. It works by filling a GTypeInfo
* struct and calling g_type_register_static().
* Since 2.12
* Params:
* parentType = Type from which this type will be derived.
* typeName = 0-terminated string used as the name of the new type.
* classSize = Size of the class structure (see GTypeInfo)
* classInit = Location of the class initialization function (see GTypeInfo)
* instanceSize = Size of the instance structure (see GTypeInfo)
* instanceInit = Location of the instance initialization function (see GTypeInfo)
* flags = Bitwise combination of GTypeFlags values.
* Returns: The new type identifier.
*/
public static GType registerStaticSimple(GType parentType, string typeName, uint classSize, GClassInitFunc classInit, uint instanceSize, GInstanceInitFunc instanceInit, GTypeFlags flags)
{
// GType g_type_register_static_simple (GType parent_type, const gchar *type_name, guint class_size, GClassInitFunc class_init, guint instance_size, GInstanceInitFunc instance_init, GTypeFlags flags);
return g_type_register_static_simple(parentType, Str.toStringz(typeName), classSize, classInit, instanceSize, instanceInit, flags);
}
/**
* Registers type_name as the name of a new dynamic type derived from
* parent_type. The type system uses the information contained in the
* GTypePlugin structure pointed to by plugin to manage the type and its
* instances (if not abstract). The value of flags determines the nature
* (e.g. abstract or not) of the type.
* Params:
* parentType = Type from which this type will be derived.
* typeName = 0-terminated string used as the name of the new type.
* plugin = The GTypePlugin structure to retrieve the GTypeInfo from.
* flags = Bitwise combination of GTypeFlags values.
* Returns: The new type identifier or G_TYPE_INVALID if registration failed.
*/
public static GType registerDynamic(GType parentType, string typeName, TypePlugin plugin, GTypeFlags flags)
{
// GType g_type_register_dynamic (GType parent_type, const gchar *type_name, GTypePlugin *plugin, GTypeFlags flags);
return g_type_register_dynamic(parentType, Str.toStringz(typeName), (plugin is null) ? null : plugin.getTypePluginStruct(), flags);
}
/**
* Registers type_id as the predefined identifier and type_name as the
* name of a fundamental type. The type system uses the information
* contained in the GTypeInfo structure pointed to by info and the
* GTypeFundamentalInfo structure pointed to by finfo to manage the
* type and its instances. The value of flags determines additional
* characteristics of the fundamental type.
* Params:
* typeId = A predefined type identifier.
* typeName = 0-terminated string used as the name of the new type.
* info = The GTypeInfo structure for this type.
* finfo = The GTypeFundamentalInfo structure for this type.
* flags = Bitwise combination of GTypeFlags values.
* Returns: The predefined type identifier.
*/
public static GType registerFundamental(GType typeId, string typeName, GTypeInfo* info, GTypeFundamentalInfo* finfo, GTypeFlags flags)
{
// GType g_type_register_fundamental (GType type_id, const gchar *type_name, const GTypeInfo *info, const GTypeFundamentalInfo *finfo, GTypeFlags flags);
return g_type_register_fundamental(typeId, Str.toStringz(typeName), info, finfo, flags);
}
/**
* Adds the static interface_type to instantiable_type. The information
* contained in the GTypeInterfaceInfo structure pointed to by info
* is used to manage the relationship.
* Params:
* instanceType = GType value of an instantiable type.
* interfaceType = GType value of an interface type.
* info = The GInterfaceInfo structure for this
* (instance_type, interface_type) combination.
*/
public static void addInterfaceStatic(GType instanceType, GType interfaceType, GInterfaceInfo* info)
{
// void g_type_add_interface_static (GType instance_type, GType interface_type, const GInterfaceInfo *info);
g_type_add_interface_static(instanceType, interfaceType, info);
}
/**
* Adds the dynamic interface_type to instantiable_type. The information
* contained in the GTypePlugin structure pointed to by plugin
* is used to manage the relationship.
* Params:
* instanceType = the GType value of an instantiable type.
* interfaceType = the GType value of an interface type.
* plugin = the GTypePlugin structure to retrieve the GInterfaceInfo from.
*/
public static void addInterfaceDynamic(GType instanceType, GType interfaceType, TypePlugin plugin)
{
// void g_type_add_interface_dynamic (GType instance_type, GType interface_type, GTypePlugin *plugin);
g_type_add_interface_dynamic(instanceType, interfaceType, (plugin is null) ? null : plugin.getTypePluginStruct());
}
/**
* Adds prerequisite_type to the list of prerequisites of interface_type.
* This means that any type implementing interface_type must also implement
* prerequisite_type. Prerequisites can be thought of as an alternative to
* interface derivation (which GType doesn't support). An interface can have
* at most one instantiatable prerequisite type.
* Params:
* interfaceType = GType value of an interface type.
* prerequisiteType = GType value of an interface or instantiatable type.
*/
public static void interfaceAddPrerequisite(GType interfaceType, GType prerequisiteType)
{
// void g_type_interface_add_prerequisite (GType interface_type, GType prerequisite_type);
g_type_interface_add_prerequisite(interfaceType, prerequisiteType);
}
/**
* Returns the GTypePlugin structure for type or
* NULL if type does not have a GTypePlugin structure.
* Params:
* type = The GType to retrieve the plugin for.
* Returns: The corresponding plugin if type is a dynamic type, NULL otherwise.
*/
public static TypePlugin getPlugin(GType type)
{
// GTypePlugin* g_type_get_plugin (GType type);
auto p = g_type_get_plugin(type);
if(p is null)
{
return null;
}
return new TypePlugin(cast(GTypePlugin*) p);
}
/**
* Returns the GTypePlugin structure for the dynamic interface
* interface_type which has been added to instance_type, or NULL if
* interface_type has not been added to instance_type or does not
* have a GTypePlugin structure. See g_type_add_interface_dynamic().
* Params:
* instanceType = the GType value of an instantiatable type.
* interfaceType = the GType value of an interface type.
* Returns: the GTypePlugin for the dynamic interface interface_type of instance_type.
*/
public static TypePlugin interfaceGetPlugin(GType instanceType, GType interfaceType)
{
// GTypePlugin* g_type_interface_get_plugin (GType instance_type, GType interface_type);
auto p = g_type_interface_get_plugin(instanceType, interfaceType);
if(p is null)
{
return null;
}
return new TypePlugin(cast(GTypePlugin*) p);
}
/**
* Returns the next free fundamental type id which can be used to
* register a new fundamental type with g_type_register_fundamental().
* The returned type ID represents the highest currently registered
* fundamental type identifier.
* Returns: The nextmost fundamental type ID to be registered, or 0 if the type system ran out of fundamental type IDs.
*/
public static GType fundamentalNext()
{
// GType g_type_fundamental_next (void);
return g_type_fundamental_next();
}
/**
* Internal function, used to extract the fundamental type ID portion.
* use G_TYPE_FUNDAMENTAL() instead.
* Params:
* typeId = valid type ID
* Returns: fundamental type ID
*/
public static GType fundamental(GType typeId)
{
// GType g_type_fundamental (GType type_id);
return g_type_fundamental(typeId);
}
/**
* Creates and initializes an instance of type if type is valid and
* can be instantiated. The type system only performs basic allocation
* and structure setups for instances: actual instance creation should
* happen through functions supplied by the type's fundamental type
* implementation. So use of g_type_create_instance() is reserved for
* implementators of fundamental types only. E.g. instances of the
* GObject hierarchy should be created via g_object_new() and
* never directly through
* g_type_create_instance() which doesn't handle things like singleton
* objects or object construction. Note: Do not
* use this function, unless you're implementing a fundamental
* type. Also language bindings should not use
* this function but g_object_new() instead.
* Params:
* type = An instantiatable type to create an instance for.
* Returns: An allocated and initialized instance, subject to further treatment by the fundamental type implementation.
*/
public static GTypeInstance* createInstance(GType type)
{
// GTypeInstance* g_type_create_instance (GType type);
return g_type_create_instance(type);
}
/**
* Frees an instance of a type, returning it to the instance pool for
* the type, if there is one.
* Like g_type_create_instance(), this function is reserved for
* implementors of fundamental types.
*/
public static void freeInstance(GTypeInstance* instanc)
{
// void g_type_free_instance (GTypeInstance *instance);
g_type_free_instance(instanc);
}
/**
* Adds a GTypeClassCacheFunc to be called before the reference count of a
* class goes from one to zero. This can be used to prevent premature class
* destruction. All installed GTypeClassCacheFunc functions will be chained
* until one of them returns TRUE. The functions have to check the class id
* passed in to figure whether they actually want to cache the class of this
* type, since all classes are routed through the same GTypeClassCacheFunc
* chain.
* Params:
* cacheData = data to be passed to cache_func
* cacheFunc = a GTypeClassCacheFunc
*/
public static void addClassCacheFunc(void* cacheData, GTypeClassCacheFunc cacheFunc)
{
// void g_type_add_class_cache_func (gpointer cache_data, GTypeClassCacheFunc cache_func);
g_type_add_class_cache_func(cacheData, cacheFunc);
}
/**
* Removes a previously installed GTypeClassCacheFunc. The cache
* maintained by cache_func has to be empty when calling
* g_type_remove_class_cache_func() to avoid leaks.
* Params:
* cacheData = data that was given when adding cache_func
* cacheFunc = a GTypeClassCacheFunc
*/
public static void removeClassCacheFunc(void* cacheData, GTypeClassCacheFunc cacheFunc)
{
// void g_type_remove_class_cache_func (gpointer cache_data, GTypeClassCacheFunc cache_func);
g_type_remove_class_cache_func(cacheData, cacheFunc);
}
/**
* A variant of g_type_class_unref() for use in GTypeClassCacheFunc
* implementations. It unreferences a class without consulting the chain
* of GTypeClassCacheFuncs, avoiding the recursion which would occur
* otherwise.
* Params:
* gClass = The GTypeClass structure to unreference.
*/
public static void classUnrefUncached(void* gClass)
{
// void g_type_class_unref_uncached (gpointer g_class);
g_type_class_unref_uncached(gClass);
}
/**
* Adds a function to be called after an interface vtable is
* initialized for any class (i.e. after the interface_init member of
* GInterfaceInfo has been called).
* This function is useful when you want to check an invariant that
* depends on the interfaces of a class. For instance, the
* implementation of GObject uses this facility to check that an
* object implements all of the properties that are defined on its
* interfaces.
* Since 2.4
* Params:
* checkData = data to pass to check_func
* checkFunc = function to be called after each interface
* is initialized.
*/
public static void addInterfaceCheck(void* checkData, GTypeInterfaceCheckFunc checkFunc)
{
// void g_type_add_interface_check (gpointer check_data, GTypeInterfaceCheckFunc check_func);
g_type_add_interface_check(checkData, checkFunc);
}
/**
* Removes an interface check function added with
* g_type_add_interface_check().
* Since 2.4
* Params:
* checkData = callback data passed to g_type_add_interface_check()
* checkFunc = callback function passed to g_type_add_interface_check()
*/
public static void removeInterfaceCheck(void* checkData, GTypeInterfaceCheckFunc checkFunc)
{
// void g_type_remove_interface_check (gpointer check_data, GTypeInterfaceCheckFunc check_func);
g_type_remove_interface_check(checkData, checkFunc);
}
/**
* Returns the location of the GTypeValueTable associated with type.
* Note that this function should only be used from source code
* that implements or has internal knowledge of the implementation of
* type.
* Params:
* type = A GType value.
* Returns: Location of the GTypeValueTable associated with type or NULL if there is no GTypeValueTable associated with type.
*/
public static GTypeValueTable* valueTablePeek(GType type)
{
// GTypeValueTable* g_type_value_table_peek (GType type);
return g_type_value_table_peek(type);
}
}
| D |
module UnrealScript.GFxUI.GFxAction_OpenMovie;
import ScriptClasses;
import UnrealScript.Helpers;
import UnrealScript.Engine.TextureRenderTarget2D;
import UnrealScript.GFxUI.GFxMoviePlayer;
import UnrealScript.Engine.SequenceAction;
import UnrealScript.GFxUI.SwfMovie;
extern(C++) interface GFxAction_OpenMovie : SequenceAction
{
public extern(D):
private static __gshared ScriptClass mStaticClass;
@property final static ScriptClass StaticClass() { mixin(MGSCC("Class GFxUI.GFxAction_OpenMovie")); }
private static __gshared GFxAction_OpenMovie mDefaultProperties;
@property final static GFxAction_OpenMovie DefaultProperties() { mixin(MGDPC("GFxAction_OpenMovie", "GFxAction_OpenMovie GFxUI.Default__GFxAction_OpenMovie")); }
static struct Functions
{
private static __gshared ScriptFunction mIsValidLevelSequenceObject;
public @property static final ScriptFunction IsValidLevelSequenceObject() { mixin(MGF("mIsValidLevelSequenceObject", "Function GFxUI.GFxAction_OpenMovie.IsValidLevelSequenceObject")); }
}
@property final
{
auto ref
{
ScriptArray!(ScriptName) CaptureKeys() { mixin(MGPC("ScriptArray!(ScriptName)", 256)); }
ScriptArray!(ScriptName) FocusIgnoreKeys() { mixin(MGPC("ScriptArray!(ScriptName)", 268)); }
TextureRenderTarget2D RenderTexture() { mixin(MGPC("TextureRenderTarget2D", 252)); }
GFxMoviePlayer.GFxRenderTextureMode RenderTextureMode() { mixin(MGPC("GFxMoviePlayer.GFxRenderTextureMode", 248)); }
GFxMoviePlayer MoviePlayer() { mixin(MGPC("GFxMoviePlayer", 240)); }
ScriptClass MoviePlayerClass() { mixin(MGPC("ScriptClass", 236)); }
SwfMovie Movie() { mixin(MGPC("SwfMovie", 232)); }
}
bool bDisplayWithHudOff() { mixin(MGBPC(244, 0x10)); }
bool bDisplayWithHudOff(bool val) { mixin(MSBPC(244, 0x10)); }
bool bEnableGammaCorrection() { mixin(MGBPC(244, 0x8)); }
bool bEnableGammaCorrection(bool val) { mixin(MSBPC(244, 0x8)); }
bool bStartPaused() { mixin(MGBPC(244, 0x4)); }
bool bStartPaused(bool val) { mixin(MSBPC(244, 0x4)); }
bool bCaptureInput() { mixin(MGBPC(244, 0x2)); }
bool bCaptureInput(bool val) { mixin(MSBPC(244, 0x2)); }
bool bTakeFocus() { mixin(MGBPC(244, 0x1)); }
bool bTakeFocus(bool val) { mixin(MSBPC(244, 0x1)); }
}
final bool IsValidLevelSequenceObject()
{
ubyte params[4];
params[] = 0;
(cast(ScriptObject)this).ProcessEvent(Functions.IsValidLevelSequenceObject, params.ptr, cast(void*)0);
return *cast(bool*)params.ptr;
}
}
| D |
//import std.stdio;
import gio.Application : GioApplication = Application;
import gtk.Application;
import designVisTool.mainWindow;
int main(string[] args)
{
auto application = new Application("org.design.tools.vistool", GApplicationFlags.FLAGS_NONE);
application.addOnActivate(delegate void(GioApplication app) { new MainWindow(application); });
return application.run(args);
}
| D |
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Port to the D programming language:
* Frank Benoit <[email protected]>
*******************************************************************************/
module dwtx.jface.text.link.ProposalPosition;
import dwtx.jface.text.link.LinkedModeModel; // packageimport
import dwtx.jface.text.link.LinkedPosition; // packageimport
import dwtx.jface.text.link.ILinkedModeListener; // packageimport
import dwtx.jface.text.link.TabStopIterator; // packageimport
import dwtx.jface.text.link.LinkedModeUI; // packageimport
import dwtx.jface.text.link.InclusivePositionUpdater; // packageimport
import dwtx.jface.text.link.LinkedPositionGroup; // packageimport
import dwtx.jface.text.link.LinkedModeManager; // packageimport
import dwtx.jface.text.link.LinkedPositionAnnotations; // packageimport
import dwt.dwthelper.utils;
import dwtx.dwtxhelper.Collection;
import dwtx.jface.text.IDocument;
import dwtx.jface.text.contentassist.ICompletionProposal;
/**
* LinkedPosition with added completion proposals.
* <p>
* Clients may instantiate or extend this class.
* </p>
*
* @since 3.0
*/
public class ProposalPosition : LinkedPosition {
/**
* The proposals
*/
private ICompletionProposal[] fProposals;
/**
* Creates a new instance.
*
* @param document the document
* @param offset the offset of the position
* @param length the length of the position
* @param sequence the iteration sequence rank
* @param proposals the proposals to be shown when entering this position
*/
public this(IDocument document, int offset, int length, int sequence, ICompletionProposal[] proposals) {
super(document, offset, length, sequence);
fProposals= copy(proposals);
}
/**
* Creates a new instance, with no sequence number.
*
* @param document the document
* @param offset the offset of the position
* @param length the length of the position
* @param proposals the proposals to be shown when entering this position
*/
public this(IDocument document, int offset, int length, ICompletionProposal[] proposals) {
super(document, offset, length, LinkedPositionGroup.NO_STOP);
fProposals= copy(proposals);
}
/*
* @since 3.1
*/
private ICompletionProposal[] copy(ICompletionProposal[] proposals) {
if (proposals !is null) {
ICompletionProposal[] copy= new ICompletionProposal[proposals.length];
SimpleType!(ICompletionProposal).arraycopy(proposals, 0, copy, 0, proposals.length);
return copy;
}
return null;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public override int opEquals(Object o) {
if ( cast(ProposalPosition)o ) {
if (super.opEquals(o)) {
return Arrays.equals(fProposals, (cast(ProposalPosition)o).fProposals);
}
}
return false;
}
/**
* Returns the proposals attached to this position. The returned array is owned by
* this <code>ProposalPosition</code> and may not be modified by clients.
*
* @return an array of choices, including the initial one. Callers must not
* modify it.
*/
public ICompletionProposal[] getChoices() {
return fProposals;
}
/*
* @see dwtx.jdt.internal.ui.text.link.LinkedPosition#hashCode()
*/
public override hash_t toHash() {
return super.toHash() | (fProposals is null ? 0 : (cast(hash_t)fProposals.ptr)/+.toHash()+/);
}
}
| D |
instance BDT_10022_Addon_Miguel(Npc_Default)
{
name[0] = "Мигель";
guild = GIL_BDT;
id = 10022;
voice = 11;
flags = 0;
npcType = npctype_main;
B_SetAttributesToChapter(self,3);
fight_tactic = FAI_HUMAN_NORMAL;
EquipItem(self,ItMw_Nagelknueppel);
B_CreateAmbientInv(self);
CreateInvItems(self,ItPo_Health_01,20);
CreateInvItems(self,ItPo_Health_02,8);
CreateInvItems(self,ItPo_Health_03,5);
CreateInvItems(self,ItPo_Mana_01,7);
B_SetNpcVisual(self,MALE,"Hum_Head_Thief",Face_P_OldMan_Gravo,BodyTex_P,ITAR_BDT_M);
Mdl_SetModelFatness(self,0);
Mdl_ApplyOverlayMds(self,"Humans_Tired.mds");
B_GiveNpcTalents(self);
B_SetFightSkills(self,30);
daily_routine = Rtn_Start_10022;
};
func void Rtn_Start_10022()
{
TA_Pick_FP(6,0,12,0,"ADW_PATH_TO_VP3_01");
TA_Pick_FP(12,0,18,0,"ADW_PATH_TO_VP3_02");
TA_Pick_FP(18,0,22,0,"ADW_PATH_TO_VP3_03");
TA_Sit_Bench(22,0,6,0,"ADW_SWAMP_SIT_BENCH_03");
};
| D |
/**
* Windows API header module
*
* Translated from MinGW Windows headers
*
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(DRUNTIMESRC src/core/sys/windows/_lmat.d)
*/
module core.sys.windows.lmat;
version (Windows):
@system:
pragma(lib, "netapi32");
import core.sys.windows.lmcons, core.sys.windows.windef;
enum JOB_RUN_PERIODICALLY = 1;
enum JOB_EXEC_ERROR = 2;
enum JOB_RUNS_TODAY = 4;
enum JOB_ADD_CURRENT_DATE = 8;
enum JOB_NONINTERACTIVE = 16;
enum JOB_INPUT_FLAGS = JOB_RUN_PERIODICALLY | JOB_ADD_CURRENT_DATE
| JOB_NONINTERACTIVE;
enum JOB_OUTPUT_FLAGS = JOB_RUN_PERIODICALLY | JOB_EXEC_ERROR
| JOB_RUNS_TODAY | JOB_NONINTERACTIVE;
struct AT_ENUM {
DWORD JobId;
DWORD_PTR JobTime;
DWORD DaysOfMonth;
UCHAR DaysOfWeek;
UCHAR Flags;
LPWSTR Command;
}
alias AT_ENUM* PAT_ENUM, LPAT_ENUM;
struct AT_INFO {
DWORD_PTR JobTime;
DWORD DaysOfMonth;
UCHAR DaysOfWeek;
UCHAR Flags;
LPWSTR Command;
}
alias AT_INFO* PAT_INFO, LPAT_INFO;
extern (Windows) {
NET_API_STATUS NetScheduleJobAdd(LPWSTR, PBYTE, LPDWORD);
NET_API_STATUS NetScheduleJobDel(LPWSTR, DWORD, DWORD);
NET_API_STATUS NetScheduleJobEnum(LPWSTR, PBYTE*, DWORD, PDWORD, PDWORD,
PDWORD);
NET_API_STATUS NetScheduleJobGetInfo(LPWSTR, DWORD, PBYTE*);
}
| D |
/Users/yq/Project/Swift/SwiftGroup/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/UILayoutSupport+Extensions.o : /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConfig.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Debugging.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelation.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDescription.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMaker.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Typealiases.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsets.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Constraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriority.swift /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit-umbrella.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/dyld.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/compact_unwind_encoding.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/Kingfisher/Kingfisher.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/yq/Project/Swift/SwiftGroup/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/UILayoutSupport+Extensions~partial.swiftmodule : /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConfig.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Debugging.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelation.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDescription.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMaker.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Typealiases.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsets.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Constraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriority.swift /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit-umbrella.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/dyld.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/compact_unwind_encoding.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/Kingfisher/Kingfisher.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/yq/Project/Swift/SwiftGroup/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/UILayoutSupport+Extensions~partial.swiftdoc : /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConfig.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Debugging.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelation.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDescription.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMaker.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Typealiases.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsets.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Constraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriority.swift /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit-umbrella.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/dyld.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/compact_unwind_encoding.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/Kingfisher/Kingfisher.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/yq/Project/Swift/SwiftGroup/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/UILayoutSupport+Extensions~partial.swiftsourceinfo : /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConfig.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Debugging.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraintItem.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelation.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintDescription.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMaker.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Typealiases.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutGuide+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsets.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/Constraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/LayoutConstraint.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintView.swift /Users/yq/Project/Swift/SwiftGroup/Pods/SnapKit/Source/ConstraintPriority.swift /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/ObjectiveC.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreImage.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Combine.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/QuartzCore.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Dispatch.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Metal.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Darwin.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Foundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreFoundation.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/CoreGraphics.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/ijiami.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/UIKit.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/SwiftOnoneSupport.swiftmodule/x86_64-apple-ios-simulator.swiftmodule /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit-umbrella.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/dyld.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/mach-o/compact_unwind_encoding.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/Kingfisher/Kingfisher.modulemap /Users/yq/Project/Swift/SwiftGroup/Pods/Headers/Public/SnapKit/SnapKit.modulemap /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/apinotes/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UserNotifications.framework/Headers/UserNotifications.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
| D |
module external.core.condition;
import core.sync.mutex;
import core.time;
class Condition
{
this(Mutex m, size_t capacity = 0) nothrow
{
assert(false, "Not implemented");
}
this(shared Mutex m, size_t capacity = 0) shared nothrow
{
assert(false, "Not implemented");
}
void wait() nothrow @nogc
{
assert(false, "Not implemented");
}
bool wait(Duration dur) nothrow @nogc
{
assert(false, "Not implemented");
}
bool wait(Duration dur) shared nothrow @nogc
{
assert(false, "Not implemented");
}
void wait() shared nothrow @nogc
{
assert(false, "Not implemented");
}
bool tryNotify()
{
assert(false, "Not implemented");
}
void notify() nothrow @nogc
{
assert(false, "Not implemented");
}
void notify() shared nothrow @nogc
{
assert(false, "Not implemented");
}
void notifyAll() nothrow @nogc
{
assert(false, "Not implemented");
}
void notifyAll() shared nothrow @nogc
{
assert(false, "Not implemented");
}
}
| D |
module examples.arsd;
import std.datetime : Clock;
import arsd.simpledisplay;
import arsd.nanovega;
import nanogui.arsdbackend : ArsdBackend;
class MyGui : ArsdBackend
{
this(int w, int h, string title)
{
super(w, h, title);
}
override void onVisibleForTheFirstTime()
{
import nanogui.screen : Screen;
import nanogui.widget, nanogui.theme, nanogui.checkbox, nanogui.label,
nanogui.common, nanogui.window, nanogui.layout, nanogui.button,
nanogui.popupbutton, nanogui.entypo, nanogui.popup, nanogui.vscrollpanel,
nanogui.combobox, nanogui.textbox;
{
auto window = new Window(screen, "Button demo");
window.position(Vector2i(15, 15));
window.size = Vector2i(screen.size.x - 30, screen.size.y - 30);
window.layout(new GroupLayout());
new Label(window, "Push buttons", "sans-bold");
auto checkbox = new CheckBox(window, "Checkbox #1", (bool value){ simple_window.redrawOpenGlSceneNow(); });
checkbox.position = Vector2i(100, 190);
checkbox.size = checkbox.preferredSize(nvg);
checkbox.checked = true;
auto label = new Label(window, "Label");
label.position = Vector2i(100, 300);
label.size = label.preferredSize(nvg);
Popup popup;
auto btn = new Button(window, "Button");
btn.callback = () {
popup.children[0].visible = !popup.children[0].visible;
label.caption = popup.children[0].visible ?
"Popup label is visible" : "Popup label isn't visible";
};
auto popupBtn = new PopupButton(window, "PopupButton", Entypo.ICON_EXPORT);
popup = popupBtn.popup;
popup.layout(new GroupLayout());
new Label(popup, "Arbitrary widgets can be placed here");
new CheckBox(popup, "A check box", null);
window.tooltip = "Button demo tooltip";
}
{
auto window = new Window(screen, "Button group example");
window.position(Vector2i(220, 15));
window.layout(new GroupLayout());
auto buttonGroup = ButtonGroup();
auto btn = new Button(window, "RadioButton1");
btn.flags = Button.Flags.RadioButton;
btn.buttonGroup = buttonGroup;
btn.tooltip = "Radio button ONE";
buttonGroup ~= btn;
btn = new Button(window, "RadioButton2");
btn.flags = Button.Flags.RadioButton;
btn.buttonGroup = buttonGroup;
btn.tooltip = "Radio button TWO";
buttonGroup ~= btn;
btn = new Button(window, "RadioButton3");
btn.flags = Button.Flags.RadioButton;
btn.buttonGroup = buttonGroup;
btn.tooltip = "Radio button THREE";
buttonGroup ~= btn;
window.tooltip = "Radio button group tooltip";
}
{
auto window = new Window(screen, "Button with image window");
window.position(Vector2i(400, 15));
window.layout(new GroupLayout());
auto image = nvg.createImage("resources/icons/start.jpeg", [NVGImageFlags.ClampToBorderX, NVGImageFlags.ClampToBorderY]);
auto btn = new Button(window, "Start", image);
// some optional height, not font size, not icon height
btn.fixedHeight = 130;
// yet another Button with the same image but default size
new Button(window, "Start", image);
window.tooltip = "Window with button that has image as an icon";
}
{
auto window = new Window(screen, "Combobox window");
window.position(Vector2i(600, 15));
window.layout(new GroupLayout());
new Label(window, "Message dialog", "sans-bold");
import std.algorithm : map;
import std.range : iota;
import std.array : array;
import std.conv : text;
auto items = 15.iota.map!(a=>text("items", a)).array;
new ComboBox(window, items);
window.tooltip = "Window with ComboBox tooltip";
auto tb = new TextBox(window, "Edit me!");
tb.editable = true;
}
{
int width = 400;
int half_width = width / 2;
int height = 200;
auto window = new Window(screen, "All Icons");
window.position(Vector2i(0, 400));
window.fixedSize(Vector2i(width, height));
// attach a vertical scroll panel
auto vscroll = new VScrollPanel(window);
vscroll.fixedSize(Vector2i(width, height));
// vscroll should only have *ONE* child. this is what `wrapper` is for
auto wrapper = new Widget(vscroll);
wrapper.fixedSize(Vector2i(width, height));
wrapper.layout(new GridLayout());// defaults: 2 columns
foreach(i; 0..100)
{
import std.conv : text;
auto item = new Button(wrapper, "item" ~ i.text, Entypo.ICON_AIRCRAFT_TAKE_OFF);
item.iconPosition(Button.IconPosition.Left);
item.fixedWidth(half_width);
}
}
// now we should do layout manually yet
screen.performLayout(nvg);
}
}
void main () {
auto gui = new MyGui(1000, 800, "Nanogui using arsd.simpledisplay");
gui.run();
} | D |
//////////////////////////////////////////////////////////////////////////
// ZS_HealSelf
// =======
// Wird angesprungen durch
//
// - ZS_Attack
// - ZS_Flee
// - ZS_Unconscious
// - ZS_AssessBody
//
// Folgende Voraussetzungen müssen erfüllt sein:
//
// - (keine)
//
// Macht folgendes:
// 1. Heilt den NSC vollständig mit Hilfe des FullHealth
// 2. Regeneriert die Mana so weit wie möglich und nutzt dabei:
// - Manatränke
// 3. Prüft ob der Sc sich in einem Portalraumbefindet, wenn ja überwacht er den Sc
//////////////////////////////////////////////////////////////////////////
func void ZS_HealSelf ()
{
PrintDebugNpc (PD_ZS_CHECK, "ZS_HealSelf");
Npc_PercEnable (self, PERC_ASSESSENEMY , B_AssessEnemy );
Npc_PercEnable (self, PERC_ASSESSFIGHTER , B_AssessFighter );
Npc_PercEnable (self, PERC_ASSESSDAMAGE , ZS_ReactToDamage );
Npc_PercEnable (self, PERC_ASSESSMAGIC , B_AssessMagic );
Npc_PercEnable (self, PERC_ASSESSCASTER , B_AssessCaster );
Npc_PercEnable (self, PERC_ASSESSTHREAT , B_AssessFighter );
Npc_PercEnable (self, PERC_DRAWWEAPON , B_AssessFighter );
Npc_PercEnable (self, PERC_ASSESSWARN , B_AssessWarn );
Npc_PercEnable (self, PERC_ASSESSMURDER , ZS_AssessMurder );
Npc_PercEnable (self, PERC_ASSESSDEFEAT , ZS_AssessDefeat );
Npc_PercEnable (self, PERC_ASSESSFIGHTSOUND , B_AssessFightSound );
Npc_PercEnable (self, PERC_CATCHTHIEF , ZS_CatchThief );
Npc_PercEnable (self, PERC_ASSESSTHEFT , B_AssessTheft );
PrintGlobals (PD_ZS_CHECK);
C_StopLookAt (self);
};
func int ZS_HealSelf_Loop ()
{
PrintDebugNpc (PD_ZS_LOOP, "ZS_HealSelf_Loop");
if (C_NpcHasFullPower (self))
|| (self.flags == NPC_FLAG_IMMORTAL)
{
PrintDebugNpc (PD_ZS_CHECK, "...vollständig geheilt!");
return LOOP_END;
}
else
{
CreateInvItem (self, ItFo_Potion_Health_03);
AI_UseItem (self, ItFo_Potion_Health_03);
};
if (C_NpcHasFullMana (self))
{
PrintDebugNpc (PD_ZS_CHECK, "...Mana voll regeneriert!");
return LOOP_END;
}
else
{
CreateInvItem (self, ItFo_Potion_Mana_03);
AI_UseItem (self, ItFo_Potion_Mana_03);
};
// JP: Hier wird über ein paar Tage getestet, ob es spieltechnisch ein Problem ist, wenn Nsc´s Heiltränke faken, deshalb erst mal nur auskommentiert
// else if (Npc_HasItems(self,ItFo_Potion_Health_03) >0)
// {
// PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Health_03.description);
// AI_UseItem (self, ItFo_Potion_Health_03);
// }
//
// else if (Npc_HasItems(self,ItFo_Potion_Health_02) >0)
// {
// PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Health_02.description);
// AI_UseItem (self, ItFo_Potion_Health_02);
// }
//
// else if (Npc_HasItems (self,ItFo_Potion_Health_01) >0)
// {
// PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Health_01.description);
// AI_UseItem (self, ItFo_Potion_Health_01);
// }
//
// else if (Npc_GetInvItemBySlot(self, INV_FOOD, 1) > 0) // Abfrage initialisiert 'item'
// {
// PrintDebugString(PD_ZS_CHECK, "...", item.description);
// AI_UseItem (self, item);
// }
// else
// {
// PrintDebugNpc (PD_ZS_CHECK, "...keine weiteren Heilmittel vorhanden!");
// return LOOP_END; // wenn keine 'Heilmittel' mehr vorhanden -> LOOP abbrechen
// };
//
// return LOOP_CONTINUE;
};
func void ZS_HealSelf_End ()
{
PrintDebugNpc (PD_ZS_FRAME, "ZS_HealSelf_End");
// JP: PlayerIsInRoom hat in manchen Fällen nicht gegriffen, z. Spieler schleicht in Raum und greift Schlafenden sofort an
if self.aivar[AIV_PLAYERISINROOM]
||( Wld_GetPlayerPortalGuild () != GIL_NONE)
{
PrintDebugNpc (PD_ZS_FRAME, "PlayerINRoom");
AI_StartState (self, ZS_ClearRoomWait, 1, "");
};
// Jp: Wird auch voll generiert
//AI_StartState (self, ZS_HealSelfMana, 1, "");
};
func void ZS_HealSelfMana ()
{
PrintDebugNpc (PD_ZS_CHECK, "ZS_HealSelfMana");
Npc_PercEnable (self, PERC_ASSESSENEMY , B_AssessEnemy );
Npc_PercEnable (self, PERC_ASSESSFIGHTER , B_AssessFighter );
Npc_PercEnable (self, PERC_ASSESSDAMAGE , ZS_ReactToDamage );
Npc_PercEnable (self, PERC_ASSESSMAGIC , B_AssessMagic );
Npc_PercEnable (self, PERC_ASSESSCASTER , B_AssessCaster );
Npc_PercEnable (self, PERC_ASSESSTHREAT , B_AssessFighter );
Npc_PercEnable (self, PERC_DRAWWEAPON , B_AssessFighter );
Npc_PercEnable (self, PERC_ASSESSWARN , B_AssessWarn );
Npc_PercEnable (self, PERC_ASSESSMURDER , ZS_AssessMurder );
Npc_PercEnable (self, PERC_ASSESSDEFEAT , ZS_AssessDefeat );
Npc_PercEnable (self, PERC_ASSESSFIGHTSOUND , B_AssessFightSound );
Npc_PercEnable (self, PERC_CATCHTHIEF , ZS_CatchThief );
Npc_PercEnable (self, PERC_ASSESSTHEFT , B_AssessTheft );
};
func int ZS_HealSelfMana_Loop ()
{
PrintDebugNpc (PD_ZS_LOOP, "ZS_HealSelfMana_Loop");
if (C_NpcHasFullMana (self))
{
PrintDebugNpc (PD_ZS_CHECK, "...Mana voll regeneriert!");
return LOOP_END;
}
else if (Npc_HasItems(self,ItFo_Potion_Mana_03) >0)
{
PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Mana_03.description);
AI_UseItem (self, ItFo_Potion_Mana_03);
}
else if (Npc_HasItems(self,ItFo_Potion_Mana_02) >0)
{
PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Mana_02.description);
AI_UseItem (self, ItFo_Potion_Mana_02);
}
else if (Npc_HasItems (self,ItFo_Potion_Mana_01) >0)
{
PrintDebugString(PD_ZS_CHECK, "...", ItFo_Potion_Mana_01.description);
AI_UseItem (self, ItFo_Potion_Mana_01);
}
else
{
PrintDebugNpc (PD_ZS_CHECK, "...keine 'Mana-Regenerierungs-Mittel' mehr vorhanden!");
return LOOP_END; // wenn keine 'Mana-Regenerierungs-Mittel' mehr vorhanden -> LOOP abbrechen
};
AI_Wait (self, 0.5);
return LOOP_CONTINUE;
};
func void ZS_HealSelfMana_End ()
{
PrintDebugNpc (PD_ZS_FRAME, "ZS_HealSelfMana_End");
};
| D |
instance DIA_GORNOW_EXIT(C_INFO)
{
npc = pc_fighter_ow;
nr = 999;
condition = dia_gornow_exit_condition;
information = dia_gornow_exit_info;
permanent = TRUE;
description = DIALOG_ENDE;
};
func int dia_gornow_exit_condition()
{
return TRUE;
};
func void dia_gornow_exit_info()
{
AI_StopProcessInfos(self);
};
instance DIA_GORNOW_HELLO(C_INFO)
{
npc = pc_fighter_ow;
nr = 2;
condition = dia_gornow_hello_condition;
information = dia_gornow_hello_info;
permanent = FALSE;
important = TRUE;
};
func int dia_gornow_hello_condition()
{
return TRUE;
};
func void dia_gornow_hello_info()
{
var C_NPC milten;
milten = Hlp_GetNpc(pc_mage_ow);
AI_Output(other,self,"DIA_GornOW_Hello_15_00"); //Konec s tím flákáním - jsi volný!
AI_Output(self,other,"DIA_GornOW_Hello_12_01"); //Už bylo na čase, aby mě odsud někdo dostal.
AI_Output(self,other,"DIA_GornOW_Hello_12_02"); //Rozhodně jsem ale nečekal, že bys to byl ty. Jsem sakra rád, že tě vidím.
AI_Output(other,self,"DIA_GornOW_Hello_15_03"); //(s úšklebkem) Garond říká, že moc jíš a že už si nemůže dovolit tě vykrmovat.
AI_Output(self,other,"DIA_GornOW_Hello_12_04"); //Když už o tom mluvíš, pár piv by se docela šiklo. Vypadněme odsud, ta cela mě začíná nudit.
if(other.guild == GIL_SLD)
{
AI_Output(self,other,"DIA_GornOW_Add_12_00"); //Počkej, mám tady něco, co by se ti mohlo hodit.
AI_Output(self,other,"DIA_GornOW_Add_12_01"); //Našel jsem tady v cele tohle brnění. Musel ho tu schovat nějaký vězeň.
b_giveinvitems(self,other,itar_sld_m,1);
AI_Output(self,other,"DIA_GornOW_Add_12_02"); //Na mě je moc malé, ale tobě by mohlo padnout.
AI_Output(other,self,"DIA_GornOW_Add_15_03"); //Díky! Uvidíme se u Miltena.
}
else
{
AI_Output(other,self,"DIA_GornOW_Hello_15_05"); //Fajn, u Miltena.
};
AI_Output(self,other,"DIA_GornOW_Hello_12_06"); //Jasná věc.
AI_StopProcessInfos(self);
Npc_ExchangeRoutine(self,"FREE");
b_startotherroutine(milten,"GORNFREE");
MIS_RESCUEGORN = LOG_SUCCESS;
b_giveplayerxp(XP_RESCUEGORN);
};
instance DIA_GORNOW_METMILTEN(C_INFO)
{
npc = pc_fighter_ow;
nr = 2;
condition = dia_gornow_metmilten_condition;
information = dia_gornow_metmilten_info;
permanent = FALSE;
important = TRUE;
};
func int dia_gornow_metmilten_condition()
{
if((MIS_RESCUEGORN == LOG_SUCCESS) && (Npc_GetDistToWP(self,"OC_MAGE_LIBRARY_IN") <= 500) && Npc_IsInState(self,zs_talk) && (KAPITEL == 2))
{
return TRUE;
};
};
func void dia_gornow_metmilten_info()
{
AI_Output(self,other,"DIA_GornOW_MetMilten_12_00"); //Poslouchej - tady jsem se matlal už dost dlouho. Je na čase, abych viděl také něco jiného než jen tohle údolí.
AI_Output(self,other,"DIA_GornOW_MetMilten_12_01"); //Jak ses dostal skrz průsmyk?
AI_Output(other,self,"DIA_GornOW_MetMilten_15_02"); //Skrz opuštěný důl vede cesta.
AI_Output(self,other,"DIA_GornOW_MetMilten_12_03"); //Dobrá. Počkám na tu pravou chvíli a pak odsud vypadnu.
if(other.guild != GIL_SLD)
{
AI_Output(other,self,"DIA_GornOW_MetMilten_15_04"); //A kam půjdeme?
AI_Output(self,other,"DIA_GornOW_MetMilten_12_05"); //Slyšel jsem, že Lee je ještě naživu. Chtěl bych se k němu znovu připojit.
}
else
{
AI_Output(other,self,"DIA_GornOW_MetMilten_15_06"); //V tom případě běž na Onarovu farmu. Lee a jeho chlapci jsou tam. Potřebuje dobré chlapy, jako jsi ty.
AI_Output(self,other,"DIA_GornOW_MetMilten_12_07"); //To zní dobře. Půjdu se podívat, jak se jim vede.
};
};
instance DIA_GORNOW_SEEYOU(C_INFO)
{
npc = pc_fighter_ow;
nr = 900;
condition = dia_gornow_seeyou_condition;
information = dia_gornow_seeyou_info;
permanent = TRUE;
description = "Ještě se uvidíme.";
};
func int dia_gornow_seeyou_condition()
{
if(Npc_KnowsInfo(other,dia_gornow_metmilten) && (KAPITEL == 2))
{
return TRUE;
};
};
func void dia_gornow_seeyou_info()
{
AI_Output(other,self,"DIA_GornOW_SeeYou_15_00"); //Ještě se uvidíme.
AI_Output(self,other,"DIA_GornOW_SeeYou_12_01"); //S tím počítej.
AI_StopProcessInfos(self);
};
| D |
module scaledint;
/** Author: Era Scarecrow <[email protected]>
Date: 11 June 2017
License: Undecided.
Description: A fixed-sized Arbitrary Int type of struct for D2. Includes x86 & x86_64 specific extentions and assembly language and optimization.
Done: UCent defined and passes all my basic tests. Still adding more tests and final debugging. Cent untested. Compatibility & generic D version completed.
Todo: Add further battery of tests and speed test, more documentation, more opBinary/opUnary, and other possible operations not yet covered by code.
Usage: UScaledInt!bits, it will upscale to a multiple of either 32 or 64 bits. so UScaled!bits 90 could give you 96 or 128 bits. If not x86 it will return a multiple of 32
*/
import std.stdio;
import std.conv;
import std.traits;
alias UCent = UScaledInt!128;
alias Cent = ScaledInt!128;
version(X86) {
// version = Intel;
enum OpPrefix = "E";
enum Ptr = "dword ptr";
}
version(X86_64) {
// version = Intel;
enum OpPrefix = "R";
enum Ptr = "qword ptr";
}
version(Intel) {
//largest natural type
alias Int = UnsignedTypeOf!size_t;
} else {
//need longs for calculations, so the storage is 32bit uints
alias Int = uint;
}
//returns how many size_t's needed to hold that many bits. Giving 100 will give you 128, etc
int calcSizeFromBits(int bits) {
return bits / (Int.sizeof * 8) + (bits % (Int.sizeof * 8) ? 1 : 0);
}
unittest {
assert(calcSizeFromBits(1) == 32 / (Int.sizeof*8));
assert(calcSizeFromBits(32) == 32 / (Int.sizeof*8));
assert(calcSizeFromBits(64) == 64 / (Int.sizeof*8));
assert(calcSizeFromBits(100) == 128 / (Int.sizeof*8));
assert(calcSizeFromBits(200) == 224 / (Int.sizeof*8));
}
version(Intel) {
//to handle 32 & 64bit code at the same time, no rewriting
import std.array : replace;
//^ = ptr type, &=multiplier value, @=reg prefix name, %=instruction
//# = numerical multiplier in loops, separate round.
//give a good basic translation, should allow the formula to work in 64bit and 32bit easily.
string translate(string src, string inst="", int mult=size_t.sizeof, string pre=OpPrefix, string ptr=Ptr, string head="asm pure nothrow @nogc {", string foot="}") {
return head ~ src.replace("^", ptr).replace("&", to!string(mult)).replace("@", pre).replace("%", inst) ~ foot;
}
//same as previous translate, except multiple instructions can be passed.
//good for add followed by adc, letting me drop instructions without adding complexity
//so ["add", "adc"] means %=add and %%=adc.
string translate(string src, string[] instlist, int mult=size_t.sizeof, string pre=OpPrefix, string ptr=Ptr, string head="asm pure nothrow @nogc {", string foot="}") {
string t = src;
string x = "%";
while (x.length <= instlist.length)
x ~= x;
//go largest to smallest, otherwise wouldn't work
foreach_reverse(i, inst; instlist) {
string y = x[0 .. i+1];
t = t.replace(y, inst);
}
return translate(t, "", mult, pre, ptr, head, foot);
}
string translate_cnt(string src, int count, int mult, int start=0, bool dir_forward=true) {
string t;
if (dir_forward) {
foreach(i; start .. count)
t ~= src.replace("#", to!string(i * mult));
} else {
foreach_reverse(i; start .. count)
t ~= src.replace("#", to!string(i * mult));
}
return t;
}
unittest {
assert(translate("% @SI, ^ [@SI+&];", "skipjump", 17, "F", "tweak ptr", "", "") ==
"skipjump FSI, tweak ptr [FSI+17];");
assert(translate("% @SI, ^ [@SI+&]; %%; %%%;", ["skipjump", "hoptrip", "hotsauce"], 17, "F", "tweak ptr", "", "") ==
"skipjump FSI, tweak ptr [FSI+17]; hoptrip; hotsauce;");
assert(translate_cnt("mov AX, [SI+#];", 4, 5, 1, true) ==
"mov AX, [SI+5];mov AX, [SI+10];mov AX, [SI+15];");
assert(translate_cnt("mov AX, [SI+#];", 4, 5, 1, false) ==
"mov AX, [SI+15];mov AX, [SI+10];mov AX, [SI+5];");
//header/footer
assert(translate("nop;") ==
"asm pure nothrow @nogc {nop;}");
}
//multiplication magic. res is the result output. fast means it will drop multiplication to work less
//since you're more interested in what will fit within UScaledInt, at which point it will shrink
//what needs to multiply to get the full result.
void mul_asm(Int[] res, const(Int)[] lhs, const(Int)[] rhs, bool faster=true) pure @nogc nothrow {
assert(res.length >= (rhs.length+lhs.length), "Needs an output/buffer able to hold the largest possible multiplied value from input");
res[] = 0;
//0 in either by no length means 0 for a result.
if (!lhs.length || !rhs.length)
return;
foreach(i, rhs_v; cast(Int[])rhs) {
if (!rhs_v)
continue;
//s & p pointers to get proper location
const(Int) *s = cast(const Int*) lhs.ptr;
Int* p = &res[i];
Int cnt = faster ? lhs.length - i : lhs.length;
enum x = translate("
mov @SI, s;
mov @CX, cnt;
mov @DI, p;
start: mov @AX, rhs_v;
mul ^ [@SI];
//?AX:?DX has the result
add [@DI], @AX;
adc [@DI+&], @DX;
//manage carry, if applicable
jnc nocarry;
push @DI;
carry: add @DI,&;
add ^ [@DI+&], 1;
jc carry;
pop @DI;
//advance
nocarry:add @DI,&;
add @SI,&;
loop start;");
mixin(x);
}
}
//like div above, but we know we can do it with simple division, along with simple returns
void div_asm_small(const Int[] n, Int d, Int[] q, out Int r) pure @nogc {
assert(n.length <= q.length);
//simple division, no guesswork
//make pointers here due to ASM issues trying to get it to work
Int *dividend = cast(Int *) n.ptr;
Int *quotent = q.ptr;
Int len = n.length;
enum x = translate("
mov @SI, dividend;
mov @DI, quotent;
mov @AX, &;
mul ^ len; //DX cleared? if it's a really really big num it isn't
sub @AX, &;
mov @BX, d; //get divisor
add @SI, @AX; //get to the last element
add @DI, @AX;
mov @CX, len; //counter for loop
xor @DX, @DX;
start: mov @AX, [@SI];
div @BX;
mov [@DI], @AX;
sub @SI, &;
sub @DI, &;
loop start;
mov @BX, r;
mov [@BX], @DX;");
mixin(x);
}
}
//determines how many you can shift/lower the data in order to fit the max number of bits in a single block
//intended for division to lower how many times it needs to be calculated and be faster overall
int bitsUsed(T)(T val) pure @safe
if (isUnsigned!T) {
T mask = -1;
int total=T.sizeof*8, bits=T.sizeof*8;
if (!val)
return 0;
do {
bits >>= 1;
mask <<= bits;
if (!(val & mask)) {
total -= bits;
val <<= bits;
}
} while (bits);
return total;
}
unittest {
assert(bitsUsed!uint(0) == 0);
assert(bitsUsed!uint(1) == 1);
assert(bitsUsed!uint(5) == 3);
assert(bitsUsed!uint(100) == 7);
assert(bitsUsed!uint(0xffffff) == 24);
assert(bitsUsed!uint(0x800000) == 24);
assert(bitsUsed!uint(0x700000) == 23);
assert(bitsUsed!uint(-1) == 32);
assert(bitsUsed!ulong(0) == 0);
assert(bitsUsed!ulong(1) == 1);
assert(bitsUsed!ulong(5) == 3);
assert(bitsUsed!ulong(100) == 7);
assert(bitsUsed!ulong(0xffffff) == 24);
assert(bitsUsed!ulong(0x800000) == 24);
assert(bitsUsed!ulong(0x700000) == 23);
assert(bitsUsed!ulong(-1) == 64);
}
struct UScaledInt(int Bits)
if (Bits > 1) { //the 128 limit due to loop opcode
enum Size = calcSizeFromBits(Bits);
Int[Size] val;
static immutable min = UScaledInt();
static immutable max = UScaledInt(-1);
//force a larger type if needed
this(T)(T i) pure @safe @nogc nothrow
if (isUnsigned!T) {
(cast(T[])val)[0] = i;
}
this(T)(T i) pure @safe @nogc nothrow
if (isSigned!T) {
(cast(T[])val)[0] = i;
if (i < 0) {
(cast(T[])val)[1 .. $] = -1;
}
}
this(string i) pure @nogc nothrow {
UScaledInt t;
foreach(ch; i) {
if (ch == '-' || ch == '_')
continue;
t *= 10;
t += ch - '0';
}
if (i.length && i[0] == '-')
t.applyNeg();
val[] = t.val[];
}
this(const void[] i) pure @nogc nothrow{
assert(i.length*8 <= Bits);
void[] t = this.val;
t[0 .. i.length] = i[];
}
bool opEquals(size_t rhs) const @safe pure @nogc nothrow {
return opEquals(UScaledInt(rhs));
}
bool opEquals(T)(T rhs) const @safe pure @nogc nothrow
if (isIntegral!T) {
return opEquals(UScaledInt(rhs));
}
bool opEquals(const UScaledInt rhs) const @safe pure @nogc nothrow {
return val[] == rhs.val[];
}
int opCmp(size_t rhs) const @safe pure @nogc nothrow {
return opCmp(UScaledInt(rhs));
}
int opCmp(const UScaledInt rhs) const @safe pure @nogc nothrow {
foreach_reverse(i, v; rhs.val) {
if (val[i] != v) {
return val[i] > v ? 1 : -1;
}
}
return 0;
}
//inc/dec
version(Intel) {
ref UScaledInt opUnary(string op)() pure @nogc nothrow
if (op == "++" || op == "--") {
static if (op == "++") {
enum Inst = ["add", "adc"];
} else {
enum Inst = ["sub", "sbb"];
}
enum x = translate("
mov @BX, this;
% ^ [@BX], 1;" ~ translate_cnt("
//the jnc is more useful when it gets really large...
jnc fin;
%% ^ [@BX+#], 0;", Size, Int.sizeof, 1) ~ "
fin:;", Inst);
mixin(x);
return this;
}
} else {
ref UScaledInt opUnary(string op)() pure @nogc nothrow
if (op == "++" || op == "--") {
foreach(ref v; val) {
static if (op == "++") {
++v;
if (v)
break;
} else {
--v;
if (!v)
break;
}
}
return this;
}
}
UScaledInt opBinary(string op)(const UScaledInt rhs) const pure @nogc nothrow
if (op == "+" || op == "-") {
UScaledInt t = this;
mixin("t"~op~"=rhs;");
return t;
}
version(Intel) {
ref UScaledInt opOpAssign(string op)(const UScaledInt rhs) pure @nogc nothrow
if (op == "+" || op == "-") {
static if (op == "+") {
enum Inst = ["add", "adc"];
} else {
enum Inst = ["sub", "sbb"];
}
enum x = translate("
lea @SI, rhs;
mov @DI, this;
mov @AX, [@SI];
% [@DI], @AX;" ~ translate_cnt("
mov @AX, [@SI+#];
%% [@DI+#], @AX;", Size, Int.sizeof, 1), Inst);
mixin(x);
return this;
}
} else {
ref UScaledInt opOpAssign(string op)(const UScaledInt rhs) pure @nogc nothrow
if (op == "+" || op == "-") {
long t; //temporary, doubles as carry
foreach(i, ref v; val) {
t += v;
static if (op == "+") {
t += rhs.val[i];
} else {
t -= rhs.val[i];
}
v = cast(Int) t;
//reset carry, will be 33rd bit
t >>= Int.sizeof*8;
}
return this;
}
}
UScaledInt opBinary(string op)(const UScaledInt rhs) const pure @nogc nothrow
if (op == "*") {
auto t = mul(rhs);
return UScaledInt(t[0 .. Size]);
}
ref UScaledInt opOpAssign(string op)(UScaledInt rhs) pure @nogc nothrow
if (op == "*") {
auto t = mul(rhs);
val[] = t[0 .. $/2];
return this;
}
ref UScaledInt opOpAssign(string op, T)(T rhs) pure @nogc nothrow
if (isIntegral!T && op == "*") {
auto t = mul(UScaledInt(rhs));
val[] = t[0 .. $/2];
return this;
}
//two's compliment
UScaledInt opNeg() const pure @nogc nothrow {
UScaledInt t = this;
t.val[] ^= Int.max;
return ++t;
}
//same only locally...
ref UScaledInt applyNeg() pure @nogc nothrow {
val[] ^= Int.max;
return ++this;
}
//merely returns what would be the sign bit
bool getSign() const pure @safe @nogc nothrow {
return (val[$-1] & 1 << (Int.sizeof*8-1)) != 0;
}
version(Intel) {
auto mul(UScaledInt rhs) const pure @nogc nothrow {
//UScaledInt!(Bits*2) n;
Int[Size*2] n = void; //raw type, otherwise this breaks (infinite template instantiation).
mul_asm(n, val[], rhs.val[]);
return n;
}
//for div
static void sub(Int[] lhs, const Int[] rhs) pure @nogc nothrow {
assert(lhs.length == Size*2);
assert(rhs.length == Size);
auto l = lhs.ptr,
r = rhs.ptr;
enum x = translate("
mov @SI, r;
mov @DI, l;
mov @AX, [@SI];
sub [@DI], @AX;" ~ translate_cnt("
mov @AX, [@SI+#];
sbb [@DI+#], @AX;", Size, Int.sizeof, 1) ~ translate_cnt("
jnc skip;
sbb ^ [@DI+#], 0;", Size*2, Int.sizeof, Size) ~ "
skip:;");
mixin(x);
}
} else {
static void mul(Int[] res, const(Int)[] lhs, const(Int)[] rhs, bool faster=true) pure @safe @nogc nothrow {
assert(res.length == Size*2);
assert(lhs.length == Size);
assert(rhs.length == Size);
//need some shifts
ulong t;
uint c;
res[]=0;
foreach(i, l; rhs) {
if (!l)
continue;
t=c=0;
foreach(i2, r; lhs[0 .. $]) { // faster ? lhs[0 .. $-i] :
t = (cast(ulong)l * r) + c + res[i+i2];
res[i+i2] = cast(uint) t;
c = t >> 32;
}
}
}
auto mul(UScaledInt rhs) const pure @safe @nogc nothrow {
uint[Size*2] n = void;
mul(n[], this.val[], rhs.val[]);
return n;
}
static void sub(Int[] lhs, const Int[] rhs) pure @nogc nothrow {
assert(lhs.length == Size*2);
assert(rhs.length == Size);
long t; //temporary, doubles as carry
foreach(i, ref v; lhs[0 .. Size]) {
t += v;
t -= rhs[i];
v = cast(Int) t;
//reset carry, will be 33rd bit
t >>= Int.sizeof*8;
}
if (t)
foreach(ref v; lhs[Size .. $]) {
--v;
if (v != -1)
break;
}
}
static void div_small(const Int[] n, Int d, Int[] result, ref Int remainder) pure @safe nothrow {
assert(n.length <= result.length);
ulong val;
foreach_reverse(i, v; n) {
val |= v;
Int t = cast(Int) (val / d);
result[i] = t;
val -= t * d;
val <<= 32;
}
remainder = val >> 32;
}
}
/* Perhaps the hardest part of this whole thing is the following function. Watched a video on a simple
arbitrary division using only the most significant digit, which then collapses easily enough with
div_asm_small where a number of passes are done each getting closer to the goal, taking the difference
and adjusting the next pass.
One key diference is i shift the divisor and dividend to fill a full 32/64 bit block first, my tests
showed it went from 8 passes to 2. */
static void div(const UScaledInt n, UScaledInt d, ref UScaledInt q, ref UScaledInt r) pure @nogc {
assert(d, "Divide by zero");
version(Intel) {
alias divcall = div_asm_small;
alias mulcall = mul_asm;
} else {
alias divcall = UScaledInt.div_small;
alias mulcall = mul;
}
foreach_reverse(i, divisor; d.val) {
if (!divisor)
continue;
//find most significant to divide by.
if (i == 0) {
//simple division, no guesswork
//call the simpler separated one once
r.val[1 .. $] = 0;
divcall(n.val[], divisor, q.val[], r.val[0]);
} else {
UScaledInt quotent_t;
Int[Size*2] mult_temp = void;
bool dividend_sign = true;
int reduceby = bitsUsed(divisor);
alias dividend = r;
q = UScaledInt();
dividend = n;
if (reduceby < (Int.sizeof*8)) {
--i;
divisor = (d>>reduceby).val[i]; //new divisor, should be fully filled
}
do {
if (reduceby < (Int.sizeof*8))
dividend >>= reduceby;
//divide
divcall(dividend.val[i .. $], divisor, quotent_t.val[], mult_temp[0]); //remainder is junk
//add/sub to our current total
if (dividend_sign)
q += quotent_t;
else
q -= quotent_t;
//multiply
mulcall(mult_temp, q.val[], d.val[], false);
//subtract the difference
//mult_temp -= n2;
UScaledInt.sub(mult_temp[], n.val[]);
dividend_sign = mult_temp[$-1] == -1; //quick dirty check
if (dividend_sign) {
dividend = -cast(UScaledInt) mult_temp[0 .. Size];
} else
dividend = cast(UScaledInt) mult_temp[0 .. Size];
} while(dividend > d);
//handle remainder
//handle off by one?
if (!dividend_sign) {
q -= 1;
r = d - dividend;
}
break;
}
}
}
UScaledInt opBinary(string op)(const UScaledInt rhs) const pure @nogc
if (op == "/" || op == "%") {
UScaledInt q = void, r = void;
div(this, rhs, q, r);
static if (op == "/")
return q;
else
return r;
}
ref UScaledInt opOpAssign(string op)(const UScaledInt rhs) pure @nogc
if (op == "/" || op == "%") {
UScaledInt n = this, r = void;
static if (op == "/")
div(n, rhs, this, r);
else
div(n, rhs, r, this);
return this;
}
auto opBinary(string op)(size_t rhs) const pure @nogc
if (op == "/" || op == "%") {
UScaledInt q = void;
size_t r = void;
div(this.val, rhs, q.val, r);
static if (op == "/")
return q;
else
return r;
}
ref UScaledInt opOpAssign(string op)(size_t rhs) pure @nogc
if (op == "/" || op == "%") {
UScaledInt n = this;
size_t r = void;
div(n.val, rhs, this.val, r);
static if (op == "%") {
this.val[0] = r;
this.val[1 .. $] = 0;
}
return this;
}
ref UScaledInt opOpAssign(string op)(const UScaledInt rhs) pure @safe @nogc nothrow
if (op == "&" || op == "|" || op == "^") {
mixin("val[]"~op~"=rhs.val[];");
return this;
}
UScaledInt opBinary(string op)(const UScaledInt rhs) const pure @safe @nogc nothrow
if (op == "&" || op == "|" || op == "^") {
UScaledInt t=this;
mixin("t.val[]"~op~"=rhs.val[];");
return t;
}
ref UScaledInt opOpAssign(string op)(const int shiftby) pure @nogc nothrow
if (op == "<<" || op == ">>" || op == ">>>") {
mixin("this = this"~op~"shiftby;");
return this;
}
version(Intel) {
UScaledInt opBinary(string op)(int shiftby) const pure @nogc nothrow
if (op == "<<") {
assert(shiftby >= 0, "negative shift-by");
assert(shiftby < Bits, "larger number of bits than the number holds, result would be 0");
UScaledInt t;
int skip = shiftby / (Int.sizeof*8); //how many whole blocks to move by
int offs = skip * Int.sizeof;
shiftby -= skip * Int.sizeof*8;
if(!shiftby) {
//no complicated shifting or masking needed
t.val[skip .. $] = val[0 .. $-skip];
} else {
Int* p = t.val.ptr;
enum x = translate("
mov @SI, this;
mov @DI, p;
add @DI, offs;
mov @CX, shiftby;
xor @DX, @DX; //prepare mask
inc @DX;
shl @DX, CL;
dec @DX;
xor @BX, @BX; //the flags carry forward
mov @CX, Size;
sub @CX, skip; //how many elements we won't have to worry about
start: push @CX;
mov @CX, shiftby; //only need CL
mov @AX, [@SI];
rol @AX, CL; //keep left of shift, right side junk now
not @DX; //what to keep
and @AX, @DX;
or @AX, @BX; //carryover bits from previous number
mov [@DI], @AX;
not @DX;
mov @AX, [@SI];
rol @AX, CL;
mov @BX, @AX; //get bits for carryover and keep only them
and @BX, @DX;
add @SI, &;
add @DI, &;
pop @CX;
loop start;");
mixin(x);
}
return t;
}
//note, setcarry is intended for being the -1 during shifting
//the signed component should set that when calling, nothing else.
UScaledInt opBinary(string op)(int shiftby, Int setcarry=0) const pure @nogc nothrow
if (op == ">>" || op == ">>>") {
assert(shiftby >= 0, "negative shift-by");
assert(shiftby < Bits, "larger number of bits than the number holds, result would be 0, or -1");
if (setcarry) {
assert(op != ">>>");
setcarry = Int.max;
}
UScaledInt t = void;
int skip = shiftby / (Int.sizeof*8); //how many whole blocks to move by
shiftby -= skip * Int.sizeof*8;
//set zero or negative flag status as appropriate, no need to be precise.
t.val[] = setcarry;
if(!shiftby) {
//no complicated shifting or masking needed
t.val[0 .. $-skip] = val[skip .. $];
} else {
Int* p = t.val.ptr;
enum x = translate("
mov @SI, this;
add @SI, Size*& - &;//last element
mov @DI, p; //p
add @DI, Size*& - &;
mov @AX, skip;
mov @DX, &;
mul @DX; //clears EDX/mask while we're at it
sub @DI, @AX;
mov @CX, shiftby;
// xor @DX, @DX; //prepare mask, mul already cleared this
inc @DX;
shl @DX, CL;
dec @DX;
ror @DX, CL; //swap right/left side
mov @BX, setcarry; //either 0 or max
and @BX, @DX; //keep, rather than set all of them accidently.
mov @CX, Size;
sub @CX, skip; //how many elements we won't have to worry about
start: push @CX;
mov @CX, shiftby; //only need CL
mov @AX, [@SI];
ror @AX, CL; //keep right of shift, left side junk now
not @DX; //what to keep
and @AX, @DX;
or @AX, @BX; //carryover bits from previous number
mov [@DI], @AX;
not @DX; //what carries over
mov @AX, [@SI];
ror @AX, CL;
mov @BX, @AX; //get bits for carryover and keep only them
and @BX, @DX;
sub @SI, &;
sub @DI, &;
pop @CX;
loop start;");
mixin(x);
}
return t;
}
} else {
enum uint32 = uint.sizeof * 8;
enum uint64 = ulong.sizeof * 8;
//the shifts
static void lshift(Int[] result, const(Int)[] value, int shiftby) pure @safe @nogc nothrow {
assert(result.length == value.length);
int skip = shiftby / uint32; //how many whole blocks to move by
shiftby -= skip * uint32;
ulong t;
result[0 .. skip] = 0;
if (!shiftby)
result[skip .. $] = value[0 .. $-skip];
else
foreach(i, ref v; result[skip .. $]) {
t |= (cast(ulong)value[i]) << shiftby;
v = cast(uint) t;
t >>= uint32;
}
}
static void rshift(Int[] result, const(Int)[] value, int shiftby, Int setcarry=0) pure @safe @nogc nothrow {
assert(value.length == result.length);
int skip = shiftby / uint32; //how many whole blocks to move by
shiftby -= skip * uint32;
int left = uint32 - shiftby;
ulong t = setcarry ? -1L << (left+uint32) : 0;
result[$-skip .. $] = setcarry ? -1 : 0;
if (!shiftby)
result[0 .. $-skip] = value[skip .. $];
else
foreach_reverse(i, ref v; result[0 .. $-skip]) {
t |= (cast(ulong)value[i+skip]) << left;
v = t >> uint32;
t <<= uint32;
}
}
UScaledInt opBinary(string op)(int shiftby) const pure @safe @nogc nothrow
if (op == "<<") {
UScaledInt t = void;
lshift(t.val[], this.val[], shiftby);
return t;
}
UScaledInt opBinary(string op)(int shiftby, Int setcarry=0) const pure @safe @nogc nothrow
if (op == ">>" || op == ">>>") {
static if (op == ">>>") {
assert(!setcarry);
}
UScaledInt t = void;
rshift(t.val[], this.val[], shiftby, setcarry);
return t;
}
}
UScaledInt opBinary(string op, T)(T rhs) const pure @nogc nothrow
if (isIntegral!(T) && (op == "+" || op == "-" || op == "*")) {
mixin("return this"~op~"UScaledInt(rhs);");
}
ref UScaledInt opOpAssign(string op, T)(T rhs) pure @nogc nothrow
if (isIntegral!(T) && (op == "+" || op == "-" )) {
mixin("this"~op~"=UScaledInt(rhs);");
return this;
}
UScaledInt opUnary(string op)() const pure @safe @nogc nothrow
if (op == "~" || op == "-" ) {
static if (op == "~") {
UScaledInt t = void;
t.val[] = val[] ^ -1;
}
static if (op == "-") {
UScaledInt t = val.opNeg;
}
return t;
}
T opCast(T)()
if (isIntegral!T || isSomeChar!T) {
return (cast(T[])(cast(void[])val)[0 .. T.sizeof])[0];
}
bool opCast(T)()
if (is(T == bool)) {
return this != UScaledInt.init;
}
T opCast(T)()
if (is(T == ScaledInt!Bits)) {
ScaledInt!Bits t;
t.val = this.val;
return t;
}
/*
//forcibly up/downcast
T opCast(T)()
if (is(TemplateOf!T == UScaledInt)) {
static if (T.Size > Size) {
//upcast, need more memory for it
return T(val);
} else {
//downcast, just use what's there...
return cast(UScaledInt!(T.Size)) this.val[0 .. T.Size];
}
}
*/
/*creates a string of base10 to represent the number
seeing as division is expensive, it's far faster to grab a bunch of digits and use a cheaper divides
every 32bit block can hold 9 digits and 64bit can hold 18 digits, makes a mighty simple algorighm then*/
string toString(bool honorSign=false) const pure {
version(Intel) {
//optimize for div_asm_small
version(X86) {
enum Digits = 9;
}
version(X86_64) {
enum Digits = 18;
}
} else {
enum Digits = 9;
}
enum DigitsMod = 10L^^Digits;
UScaledInt tmp = this;
Int tmod;
if (honorSign && getSign)
tmp.applyNeg;
char[Digits * (val.sizeof+1)] str;
foreach_reverse(i, ref ch; str) {
if ((i+1) % Digits == 0) {
//need both division and mod at the same time, so we'll use one function call
UScaledInt t = void;
version(Intel) {
div_asm_small(tmp.val, DigitsMod, t.val, tmod);
} else {
UScaledInt.div_small(tmp.val, DigitsMod, t.val, tmod);
}
tmp = t;
}
ch = cast(char)('0' + (tmod%10));
tmod /= 10;
if (!tmod && !tmp) {
//if signed, prepend that
if (honorSign && getSign) {
--i;
str[i] = '-';
}
return str[i .. $].dup;
}
}
assert(false); //shouldn't get here.
}
}
struct ScaledInt(int Bits)
if (Bits > 1) { //the 128 limit due to loop opcode
//getting a failure due to asm precense in code...
// enum min = UScaledInt!Bits(1)<<(Bits-1);
// enum max = min + 1;
enum Size = calcSizeFromBits(Bits);
private UScaledInt!Bits _val;
alias _val this;
//force a larger type if needed
this(T)(T i) pure @nogc nothrow
if (isIntegral!T) {
_val = UScaledInt!Bits(i);
}
this(string i) @nogc nothrow {
_val = UScaledInt!Bits(i);
}
/*
//not working...
this(const void[] i) pure @nogc nothrow {
_val = UScaledInt!Bits(i);
}
*/
bool opEquals(T)(T rhs) const @safe pure
if (isIntegral!T) {
return _val.opEquals(ScaledInt!Bits(rhs));
}
bool opEquals(UScaledInt!Bits rhs) const @safe pure {
//either highest bit is on, they can't be equal
if (_val.getSign() || rhs.getSign())
return false;
return _val.val[] == rhs.val[];
}
bool opEquals(ScaledInt rhs) const @safe pure {
return _val.val[] == rhs._val.val[];
}
int opCmp(T)(T rhs) const @safe pure
if (isIntegral!T) {
return opCmp(ScaledInt(rhs));
}
int opCmp(const UScaledInt!Bits rhs) const @safe pure {
if (_val.getSign())
return -1;
return _val.opCmp(rhs);
}
int opCmp(const ScaledInt rhs) const @safe pure {
int signs = (_val.getSign ? 2 : 0) | (rhs.getSign ? 1 : 0);
switch(signs) {
case 3:// return rhs._val.opCmp(_val);
case 0: return _val.opCmp(rhs._val);
case 1: return 1;
case 2: return -1;
default:
assert(false);
}
}
// >>
ScaledInt opBinary(string op)(int shiftby) const pure
if (op == ">>") {
return cast(ScaledInt!Bits) _val.opBinary!">>"(shiftby, -1);
}
ref ScaledInt opOpAssign(string op)(int shiftby) const pure
if (op == ">>") {
_val.opOpAssign!">>"(shiftby, -1);
return this;
}
// *, %, /
ScaledInt opBinary(string op, T)(T rhs) const pure
if ((op == "*" || op == "/" || op == "%") &&
(is(T == ScaledInt!Bits) || is(T == UScaledInt!Bits))) {
ScaledInt t = this;
mixin("t"~op~"=rhs;");
return t;
}
ref ScaledInt opOpAssign(string op, T)(T rhs) pure
if ((op == "*" || op == "/" || op == "%") &&
(is(T == ScaledInt) || is(T == UScaledInt!Bits))) {
static if (is(T == ScaledInt)) {
int signs = (getSign ? 2 : 0) | (rhs.getSign ? 1 : 0);
} else {
int signs = (getSign ? 2 : 0);
}
if (signs & 2)
applyNeg();
static if (is(T == ScaledInt!Bits)) {
if (signs & 1)
rhs.applyNeg();
mixin("_val "~op~"= rhs._val;");
} else {
mixin("_val "~op~"= rhs;");
}
switch(signs) {
//if mixed result is negative
case 1:
case 2: applyNeg();
goto case 3; //yes fallthrough is desired
//if both are signed/unsigned then it's positive
case 3:
case 0: break;
default:
assert(false);
}
return this;
}
//forward functions while keeping type for return
ref ScaledInt opOpAssign(string op, T)(T rhs) pure
if ((op == "&" || op == "|" || op == "^" || op == "<<") &&
(is(T == ScaledInt) || is(T == UScaledInt!Bits) || is(T==int))) {
mixin("_val"~op~"=rhs;");
return this;
}
ScaledInt opBinary(string op, T)(T rhs) const pure
if ((op == "&" || op == "|" || op == "^" || op == "<<") &&
(is(T == ScaledInt) || is(T == UScaledInt!Bits) || is(T==int))) {
ScaledInt tmp;
mixin("tmp._val = this._val"~op~"rhs;");
return tmp;
}
string toString() const pure {
return _val.toString(true);
}
}
unittest {
assert(cast(ulong[])UCent([0xFEDCBA9876543210L, 0x89ABCDEF01234567L]).val == [0xFEDCBA9876543210L, 0x89ABCDEF01234567L]);
assert(cast(ulong[])UCent([0x76543210, 0xFEDCBA98, 0x01234567, 0x89ABCDEF]).val == [0xFEDCBA9876543210L, 0x89ABCDEF01234567L]);
assert(UCent(cast(int)-1) == UCent([-1L, -1L]));
uint[4] x = [-1, 0, 0, 0];
assert(UCent(cast(uint)-1) == UCent(x));
x[1] = -1;
assert(UCent(cast(ulong)-1) == UCent(x));
}
//opcmp / opequal
unittest {
UCent l=1, l2=2, g = UCent([0,1]);
//l & l2 at the same level, g on a different 'greater' level.
//only test first two levels, on a 64bit machine there might only be 2 levels.
//opEquals
assert(l == l);
assert(l2 == l2);
assert(g == g);
assert(g != l);
assert(l != g);
assert(l != l2);
assert(l2 != g);
assert(l < g);
assert(g > l);
assert(l < l2);
assert(l2 > l);
assert(l2 < g);
assert(g > l2);
assert(l >= l);
assert(g <= g);
//size_t
assert(l == 1);
assert(l2 == 2);
assert(l2 != 1);
assert(l != 2);
assert(g != 1);
assert(g != 2);
assert(l2 > 1);
assert(l < 2);
assert(g > uint.max);
}
//need unittests for specific sizes/types otherwise testing this will likely fail for the wrong reasons later
// ++/--
unittest {
UCent zero, x, neg1, one, t;
neg1.val[] = Int.max;
one.val[0] = 1;
--x;
assert(x == neg1);
++x;
assert(x == zero);
++x;
assert(x == one);
--x;
assert(x == zero);
x.val[0] = Int.max;
t.val[1] = 1;
x = UCent(Int.max);
++x;
assert(x == t);
t.val[0] = Int.max;
t.val[1] = 0;
--x;
assert(x.val[0] == Int.max);
assert(x.val[1] == 0);
}
// +/-
unittest {
alias Int = uint;
UCent x256 = 256, x300=300, x556=556, zero, neg1, maxfirst=Int.max, t;
--neg1;
maxfirst.val[0] = Int.max;
//+, no carry
assert(x556 == x256+x300);
assert(x556 == x256+300);
assert(UCent(256+300) == x256+x300);
t = x256;
t += x300;
assert(t == x556);
//carry
assert(UCent([299,1]) == maxfirst + x300);
assert(UCent([299,1]) == maxfirst + 300);
//carry from neg (to positive)
assert(UCent(255) == neg1 + x256);
assert(UCent(255) == neg1 + 256);
//negative tests
//no carry
assert(UCent(44) == x300-x256);
assert(UCent(44) == x300-256);
t = x300;
t -= x256;
assert(t == UCent(44));
t = x300;
t -= 256;
assert(t == UCent(44));
//carry
t = UCent([256, 1]);
t -= 300;
assert(t == UCent(Int.max - 43));
//carry from pos (to neg)
t = neg1 - 43;
assert(t == UCent(256)-300);
}
// <<, >>, >>>
unittest {
UCent orig = UCent([0xFEDCBA9876543210L, 0x89ABCDEF01234567L]),
sh4l = UCent([0xEDCBA98765432100L, 0x9ABCDEF01234567FL]),
sh64l = UCent([0L, 0xFEDCBA9876543210L]),
sh68l = UCent([0L, 0xEDCBA98765432100L]),
sh4r = UCent([0x7FEDCBA987654321L, 0x089ABCDEF0123456L]),
sh64r = UCent([0x89ABCDEF01234567L, 0L]),
sh68r = UCent([0x089ABCDEF0123456L, 0L]),
sh4r_b = UCent([0x7FEDCBA987654321L, 0xF89ABCDEF0123456L]),
sh64r_b = UCent([0x89ABCDEF01234567L, 0xFFFFFFFFFFFFFFFFL]),
sh68r_b = UCent([0xF89ABCDEF0123456L, 0xFFFFFFFFFFFFFFFFL]);
assert(orig << 4 == sh4l); //simple shift
assert(orig << 64 == sh64l);//fixed no asm
assert(orig << 68 == sh68l);//skip & shift
assert(orig >> 4 == sh4r);
assert(orig >> 64 == sh64r);
assert(orig >> 68 == sh68r);
assert(orig >>> 4 == sh4r); //>> and >>> the same
assert(orig >>> 64 == sh64r);
assert(orig >>> 68 == sh68r);
//carry flag added intentionally (for signed shift)
assert(orig.opBinary!">>"(4, 1) == sh4r_b);
assert(orig.opBinary!">>"(64, 100) == sh64r_b);
assert(orig.opBinary!">>"(68, 0xffffffff) == sh68r_b);
}
// & | ^
unittest {
UCent orig = UCent([0xFEDCBA987654321UL, 0xFEDCBA987654321UL]),
rhs = UCent([0x123456789ABCDEFL, 0x55555555_55555555L]),
expected;
Cent corig = cast(Cent) orig,
crhs = cast(Cent) rhs;
// cexpected;
expected.val[] = orig.val[] & rhs.val[];
// cexpected._val.val[] = expected.val[];
assert((orig & rhs) == expected);
assert((corig & rhs) == expected);
assert((orig & crhs) == expected);
assert((corig & crhs) == expected);
expected.val[] = orig.val[] | rhs.val[];
assert((orig | rhs) == expected);
assert((corig | rhs) == expected);
assert((orig | crhs) == expected);
assert((corig | crhs) == expected);
expected.val[] = orig.val[] ^ rhs.val[];
assert((orig ^ rhs) == expected);
assert((corig ^ rhs) == expected);
assert((orig ^ crhs) == expected);
assert((corig ^ crhs) == expected);
}
// *
unittest {
UCent orig = UCent(0xFEDCBA987654321UL);
UCent[16] vals;
ulong x2;
foreach(i; 0 .. 16) {
ulong x = i;
x <<= 4*i;
x2 |= x;
vals[i] = orig * x;
UCent t, t2;
t = orig;
t <<= 4*i;
foreach(i2; 0 .. i) {
t2 += t;
}
assert(t2 == vals[i]); //check multiplication worked, remember 4bit x 128bit
}
UCent t;
foreach(i; vals)
t += i;
assert(t == orig*x2);
version(Intel) {
UScaledInt!256 x256, x256_b, x256_c;
//do a 128*128. Low will always be 1, high will always be F's, except the lowest of the high bits.
//alternatively will be off from a full max by a small margin.
t.val[] = -1;
mul_asm(x256.val, t.val, t.val, false);
x256_b.val[]=-1;
x256_c.val[0 .. $/2] = -1;
x256_b -= x256_c;
x256_b -= x256_c;
/*alright, x256 & x256_b should be idential now.
Here's the logic behind it:
ff*ff = fe01
+ff = ff00
+ff = ffff
*/
assert(x256 == x256_b);
//check fast, only lower half matters.
mul_asm(x256.val, t.val, t.val, true);
assert(x256.val[0 .. $/2] == x256_b.val[0 .. $/2]);
assert(x256 != x256_b); //upper half not calculated so it obviously doesn't match
//quick exit with no length
x256_b.val[]=0;
x256.val[]=-1;
mul_asm(x256.val, t.val, null);
assert(x256 == x256_b);
x256.val[]=-1;
mul_asm(x256.val, null, t.val);
assert(x256 == x256_b);
}
//check opassign
t = UCent(255);
t *= t;
assert(t == UCent(255*255));
t *= 100;
assert(t == UCent(255*255*100));
}
// this(string)
unittest {
//with multiply & add working, string assignment will work.
//can't seem to get opEqual to work with these...
assert(UCent("81985529216486895") == 81985529216486895L);
assert(UCent("81985529216486895") == UCent([0x123456789ABCDEFL]));
assert(UCent("-81985529216486895") == (UCent() - 81985529216486895));
assert(UCent("-81985529216486895") == -81985529216486895L);
}
// neg, applyNeg
unittest {
//should be 2's compliment, so...
UCent x;
x -= 100;
x.applyNeg();
assert(x == UCent(100));
x = UCent(0);
x.applyNeg();
assert(x == UCent());
assert(-UCent( 100) == UCent(-100));
assert(-UCent(-100) == UCent( 100));
}
// getSign
unittest {
UCent x = -1;
assert(x.getSign);
x.val[$-1] ^= 1<<(Int.sizeof*8-1);
assert(!x.getSign);
assert(x == UCent([0xffffffff_ffffffffL, 0x7fffffff_ffffffffL]));
}
//div_small div_asm_small
//this is needed for toString and other division based on it to work.
unittest {
UCent fact21 = "51090942171709440001",
d_res = "1626323163193042", res;
Int remainder;
version(Intel) {
alias dv = div_asm_small;
} else {
alias dv = UCent.div_small;
}
dv(fact21.val, 31415, res.val[], remainder);
assert(remainder == 25571);
assert(res == d_res);
}
// tostring
unittest {
UCent t = -1;
t >>= 1;
assert(t.toString() == "170141183460469231731687303715884105727");
assert((-t).toString(true) == "-170141183460469231731687303715884105727");
assert(UCent().toString() == "0");
}
// /
unittest {
//division, the one part that sucks more than the rest. Oh well.
//the simple division comes first. Simplest would have a test of a string to see what we expect.
static T factorial(T = UCent)(int n) {
T value = 1;
foreach(i; 2 .. n+1)
value *= i;
return value;
}
//calculate factorial 34
//https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic
UCent fact34 = factorial(34);
UCent fact21 = factorial(21);
//values confirmed using bc
assert(fact21.toString == "51090942171709440000");
assert(fact34.toString == "295232799039604140847618609643520000000", fact34.toString);
//for one level/size_t type that's fine. But now we need to go a bit bigger. At lest a 65bit number to ensure we're working
//good even on 64bit machines.
++fact21; //so we force a remainder.
assert((fact34 / fact21).toString == "5778574175582207999");
assert((fact34 % fact21).toString == "45312367996127232001");
//unique case for div_asm_small never gets called, need to ensure it does when a single small value is present.
UCent sm = 31415;
assert((fact21 / sm).toString == "1626323163193042");
assert((fact21 % sm).toString == "25571");
}
//signed specific tests
//assignments
unittest {
assert(Cent(100).toString == "100");
assert(Cent(-100).toString == "-100");
assert(Cent("-100").toString == "-100");
// assert(Cent([100,0]).toString == "100"); //not sure
}
//opcmp & opEquals
unittest {
UCent upos = 10, upos2 = 200, uneg = -100;
Cent spos = 100, spos2 = 1000,
sneg = -100, sneg2 = -1000;
//check immediates
assert(spos < 1000);
assert(sneg2 > -2000);
assert(spos == 100);
assert(sneg == -100);
//non-mixed Cents
assert(spos < spos2);
assert(sneg > sneg2);
assert(sneg < spos);
assert(spos == spos);
assert(spos != spos2);
//mixed same signs
assert(spos > upos);
assert(spos < upos2);
assert(spos != upos);
assert(spos == UCent(100));
//mixed with neg/high
assert(sneg < upos);
assert(sneg < uneg);
assert(spos < uneg);
assert(sneg != uneg);
assert(sneg != upos);
//rhs neg left positive hasn't been tested yet
assert(spos > sneg);
}
//ensure >> works right
unittest {
Cent v = -100;
assert(v == -100);
assert(v>>3 == -13);
//all other tests already done earlier
}
// * & /
unittest {
ScaledInt!160 fact21 = "51090942171709440000",
fact34 = "295232799039604140847618609643520000000";
UScaledInt!160 ufact21 = "51090942171709440000";
++fact21; //so we force a remainder.
++ufact21;
assert((fact34 / fact21).toString == "5778574175582207999");
assert((fact34 % fact21).toString == "45312367996127232001");
fact21.applyNeg;
assert((fact34 / fact21).toString == "-5778574175582207999");
assert((fact34 % fact21).toString == "-45312367996127232001");
fact34.applyNeg;
assert((fact34 / fact21).toString == "5778574175582207999");
assert((fact34 % fact21).toString == "45312367996127232001");
fact21.applyNeg;
assert((fact34 / fact21).toString == "-5778574175582207999");
assert((fact34 % fact21).toString == "-45312367996127232001");
//make sure mixed signs work.
assert((fact34 / ufact21).toString == "-5778574175582207999");
assert((fact34 % ufact21).toString == "-45312367996127232001");
fact34.applyNeg;
assert((fact34 / ufact21).toString == "5778574175582207999");
assert((fact34 % ufact21).toString == "45312367996127232001");
ufact21.applyNeg; //unsigned still positive, so it will be way too big.
assert(ufact21 > fact34);
assert((fact34 / ufact21).toString == "0");
assert((fact34 % ufact21) == fact34);
}
debug {
unittest {
int bitcount(Int[] v) {
int total = v.length * Int.sizeof * 8;
while (!v[$-1]) {
v = v[0 .. $-1];
total -= Int.sizeof * 8;
}
total -= Int.sizeof * 8;
Int tmp = v[$-1];
while (tmp) {
++total;
tmp >>= 1;
}
return total;
}
writeln("Time to show off! Factorial 1-98!\nFact!N\tbits\tResults");
UScaledInt!512 f = 1;
foreach(i; 1 .. 99) {
f *= i;
writefln("%s\t%s\t%s", i, bitcount(f.val), f);
}
}
} | D |
a slender and greatly elongated substance capable of being spun into yarn
any of several elongated, threadlike cells (especially a muscle fiber or a nerve fiber)
the inherent complex of attributes that determines a persons moral and ethical actions and reactions
a leatherlike material made by compressing layers of paper or cloth
| D |
/Users/prang/Desktop/AppDontForget2/build/AppDontForget.build/Debug-iphonesimulator/AppDontForget.build/Objects-normal/x86_64/AppDelegate.o : /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarHeaderView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LocationManager.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/RequestViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoList.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/Message.swift /Users/prang/Desktop/AppDontForget2/MapCurrentViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarView.swift /Users/prang/Desktop/AppDontForget2/AkiraTextField.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LoginViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoTableViewCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/UpdateTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SignupViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersInTableViewCell.swift /Users/prang/Desktop/AppDontForget2/SendText.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SCLAlertView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ResetPasswordViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/\ AddTodoTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarDayCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NewMessageController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomableImageView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/User.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomButton.swift /Users/prang/Desktop/AppDontForget2/TextFieldsEffects.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/MyprofileViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NetworkService.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ChatLogController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarFlowLayout.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDelegate.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoListTableViewController.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDontForget-Bridging-Header.h /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeTableCell.h /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeButton.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRLoggerLevel.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FirebaseCore.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRUserPropertyNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRParameterNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIREventNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics+AppDelegate.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FirebaseAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuthVersion.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUserInfo.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUser.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthCredential.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthErrors.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRTwitterAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGoogleAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGitHubAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRFacebookAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIREmailPasswordAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRServerValue.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRTransactionResult.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRMutableData.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataEventType.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseQuery.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FirebaseDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FIRInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FirebaseInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FIRMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FirebaseMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTaskSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageUploadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageMetadata.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageObservableTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageDownloadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageConstants.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FirebaseStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/Firebase.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreLocation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/MapKit.swiftmodule
/Users/prang/Desktop/AppDontForget2/build/AppDontForget.build/Debug-iphonesimulator/AppDontForget.build/Objects-normal/x86_64/AppDelegate~partial.swiftmodule : /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarHeaderView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LocationManager.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/RequestViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoList.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/Message.swift /Users/prang/Desktop/AppDontForget2/MapCurrentViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarView.swift /Users/prang/Desktop/AppDontForget2/AkiraTextField.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LoginViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoTableViewCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/UpdateTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SignupViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersInTableViewCell.swift /Users/prang/Desktop/AppDontForget2/SendText.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SCLAlertView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ResetPasswordViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/\ AddTodoTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarDayCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NewMessageController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomableImageView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/User.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomButton.swift /Users/prang/Desktop/AppDontForget2/TextFieldsEffects.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/MyprofileViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NetworkService.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ChatLogController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarFlowLayout.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDelegate.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoListTableViewController.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDontForget-Bridging-Header.h /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeTableCell.h /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeButton.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRLoggerLevel.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FirebaseCore.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRUserPropertyNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRParameterNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIREventNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics+AppDelegate.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FirebaseAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuthVersion.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUserInfo.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUser.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthCredential.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthErrors.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRTwitterAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGoogleAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGitHubAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRFacebookAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIREmailPasswordAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRServerValue.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRTransactionResult.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRMutableData.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataEventType.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseQuery.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FirebaseDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FIRInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FirebaseInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FIRMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FirebaseMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTaskSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageUploadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageMetadata.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageObservableTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageDownloadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageConstants.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FirebaseStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/Firebase.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreLocation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/MapKit.swiftmodule
/Users/prang/Desktop/AppDontForget2/build/AppDontForget.build/Debug-iphonesimulator/AppDontForget.build/Objects-normal/x86_64/AppDelegate~partial.swiftdoc : /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarHeaderView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LocationManager.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/RequestViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoList.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/Message.swift /Users/prang/Desktop/AppDontForget2/MapCurrentViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarView.swift /Users/prang/Desktop/AppDontForget2/AkiraTextField.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/LoginViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoTableViewCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/UpdateTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SignupViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AllUsersInTableViewCell.swift /Users/prang/Desktop/AppDontForget2/SendText.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/SCLAlertView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ResetPasswordViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/\ AddTodoTableViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarDayCell.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NewMessageController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomableImageView.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/User.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CustomButton.swift /Users/prang/Desktop/AppDontForget2/TextFieldsEffects.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/MyprofileViewController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/NetworkService.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/ChatLogController.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/CalendarFlowLayout.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDelegate.swift /Users/prang/Desktop/AppDontForget2/AppDontForget/TodoListTableViewController.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/AppDontForget-Bridging-Header.h /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeTableCell.h /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Users/prang/Desktop/AppDontForget2/AppDontForget/MGSwipeButton.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRLoggerLevel.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers/FirebaseCore.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRUserPropertyNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRParameterNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIREventNames.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics+AppDelegate.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIROptions.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRApp.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalyticsConfiguration.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FirebaseAnalytics.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuthVersion.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUserInfo.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRUser.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthCredential.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuthErrors.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRTwitterAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGoogleAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRGitHubAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIRFacebookAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FIREmailPasswordAuthProvider.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers/FirebaseAuth.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRServerValue.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRTransactionResult.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRMutableData.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDataEventType.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseQuery.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabaseReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FIRDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers/FirebaseDatabase.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FIRInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers/FirebaseInstanceID.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FIRMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers/FirebaseMessaging.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTaskSnapshot.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageUploadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageReference.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageMetadata.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageObservableTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageDownloadTask.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorageConstants.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FIRStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Headers/FirebaseStorage.h /Users/prang/Desktop/AppDontForget2/Pods/FirebaseStorage/Frameworks/FirebaseStorage.framework/Modules/module.modulemap /Users/prang/Desktop/AppDontForget2/Pods/Firebase/Core/Sources/Firebase.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreLocation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/MapKit.swiftmodule
| D |
/**
* Entry point for DMD.
*
* This modules defines the entry point (main) for DMD, as well as related
* utilities needed for arguments parsing, path manipulation, etc...
* This file is not shared with other compilers which use the DMD front-end.
*
* Copyright: Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/mars.d, _mars.d)
* Documentation: https://dlang.org/phobos/dmd_mars.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/mars.d
*/
module dmd.mars;
import core.stdc.ctype;
import core.stdc.limits;
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import dmd.arraytypes;
import dmd.astcodegen;
import dmd.astenums;
import dmd.builtin;
import dmd.cond;
import dmd.console;
import dmd.compiler;
import dmd.cpreprocess;
import dmd.dmdparams;
import dmd.dinifile;
import dmd.dinterpret;
import dmd.dmodule;
import dmd.doc;
import dmd.dsymbol;
import dmd.dsymbolsem;
import dmd.dtemplate;
import dmd.dtoh;
import dmd.errors;
import dmd.expression;
import dmd.file_manager;
import dmd.globals;
import dmd.hdrgen;
import dmd.id;
import dmd.identifier;
import dmd.inline;
import dmd.location;
import dmd.json;
version (NoMain) {} else
{
import dmd.glue : generateCodeAndWrite;
import dmd.dmsc : backend_init, backend_term;
import dmd.link;
import dmd.vsoptions;
}
import dmd.mtype;
import dmd.objc;
import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.root.man;
import dmd.common.outbuffer;
import dmd.root.response;
import dmd.root.rmem;
import dmd.root.string;
import dmd.root.stringtable;
import dmd.semantic2;
import dmd.semantic3;
import dmd.target;
import dmd.utils;
/**
* Print DMD's logo on stdout
*/
private void logo()
{
printf("DMD%llu D Compiler %.*s\n%.*s %.*s\n",
cast(ulong)size_t.sizeof * 8,
cast(int) global.versionString().length, global.versionString().ptr,
cast(int)global.copyright.length, global.copyright.ptr,
cast(int)global.written.length, global.written.ptr
);
}
/**
Print DMD's logo with more debug information and error-reporting pointers.
Params:
stream = output stream to print the information on
*/
private void printInternalFailure(FILE* stream)
{
fputs(("---\n" ~
"ERROR: This is a compiler bug.\n" ~
"Please report it via https://issues.dlang.org/enter_bug.cgi\n" ~
"with, preferably, a reduced, reproducible example and the information below.\n" ~
"DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the reduction.\n" ~
"---\n").ptr, stream);
stream.fprintf("DMD %.*s\n", cast(int) global.versionString().length, global.versionString().ptr);
stream.printPredefinedVersions;
stream.printGlobalConfigs();
fputs("---\n".ptr, stream);
}
/**
* Print DMD's usage message on stdout
*/
private void usage()
{
import dmd.cli : CLIUsage;
logo();
auto help = CLIUsage.usage;
const inifileCanon = FileName.canonicalName(global.inifilename);
printf("
Documentation: https://dlang.org/
Config file: %.*s
Usage:
dmd [<option>...] <file>...
dmd [<option>...] -run <file> [<arg>...]
Where:
<file> D source file
<arg> Argument to pass when running the resulting program
<option>:
@<cmdfile> read arguments from cmdfile
%.*s", cast(int)inifileCanon.length, inifileCanon.ptr, cast(int)help.length, &help[0]);
}
/**
* DMD's real entry point
*
* Parses command line arguments and config file, open and read all
* provided source file and do semantic analysis on them.
*
* Params:
* argc = Number of arguments passed via command line
* argv = Array of string arguments passed via command line
*
* Returns:
* Application return code
*/
version (NoMain) {} else
private int tryMain(size_t argc, const(char)** argv, ref Param params)
{
Strings files;
Strings libmodules;
global._init();
if (parseCommandlineAndConfig(argc, argv, params, files))
return EXIT_FAILURE;
global.compileEnv.previewIn = global.params.previewIn;
global.compileEnv.ddocOutput = global.params.ddoc.doOutput;
global.compileEnv.shortenedMethods = global.params.shortenedMethods;
if (params.usage)
{
usage();
return EXIT_SUCCESS;
}
if (params.logo)
{
logo();
return EXIT_SUCCESS;
}
/*
Prints a supplied usage text to the console and
returns the exit code for the help usage page.
Returns:
`EXIT_SUCCESS` if no errors occurred, `EXIT_FAILURE` otherwise
*/
static int printHelpUsage(string help)
{
printf("%.*s", cast(int)help.length, &help[0]);
return global.errors ? EXIT_FAILURE : EXIT_SUCCESS;
}
/*
Print a message to make it clear when warnings are treated as errors.
*/
static void errorOnWarning()
{
error(Loc.initial, "warnings are treated as errors");
errorSupplemental(Loc.initial, "Use -wi if you wish to treat warnings only as informational.");
}
/*
Generates code to check for all `params` whether any usage page
has been requested.
If so, the generated code will print the help page of the flag
and return with an exit code.
Params:
params = parameters with `Usage` suffices in `params` for which
their truthness should be checked.
Returns: generated code for checking the usage pages of the provided `params`.
*/
static string generateUsageChecks(string[] params)
{
string s;
foreach (n; params)
{
s ~= q{
if (params.}~n~q{Usage)
return printHelpUsage(CLIUsage.}~n~q{Usage);
};
}
return s;
}
import dmd.cli : CLIUsage;
mixin(generateUsageChecks(["mcpu", "transition", "check", "checkAction",
"preview", "revert", "externStd", "hc"]));
if (params.manual)
{
version (Windows)
{
browse("https://dlang.org/dmd-windows.html");
}
version (linux)
{
browse("https://dlang.org/dmd-linux.html");
}
version (OSX)
{
browse("https://dlang.org/dmd-osx.html");
}
version (FreeBSD)
{
browse("https://dlang.org/dmd-freebsd.html");
}
/*NOTE: No regular builds for openbsd/dragonflybsd (yet) */
/*
version (OpenBSD)
{
browse("https://dlang.org/dmd-openbsd.html");
}
version (DragonFlyBSD)
{
browse("https://dlang.org/dmd-dragonflybsd.html");
}
*/
return EXIT_SUCCESS;
}
if (params.color)
global.console = cast(void*) createConsole(core.stdc.stdio.stderr);
target.setCPU();
Loc.set(params.showColumns, params.messageStyle);
if (global.errors)
{
fatal();
}
if (files.length == 0)
{
if (params.jsonFieldFlags)
{
generateJson(null);
return EXIT_SUCCESS;
}
usage();
return EXIT_FAILURE;
}
reconcileCommands(params, target);
// Add in command line versions
if (params.versionids)
foreach (charz; *params.versionids)
VersionCondition.addGlobalIdent(charz.toDString());
if (params.debugids)
foreach (charz; *params.debugids)
DebugCondition.addGlobalIdent(charz.toDString());
setDefaultLibrary(params, target);
// Initialization
target._init(params);
Type._init();
Id.initialize();
Module._init();
Expression._init();
Objc._init();
reconcileLinkRunLib(params, files.length, target.obj_ext);
version(CRuntime_Microsoft)
{
import dmd.root.longdouble;
initFPU();
}
import dmd.root.ctfloat : CTFloat;
CTFloat.initialize();
// Predefined version identifiers
addDefaultVersionIdentifiers(params, target);
if (params.verbose)
{
stdout.printPredefinedVersions();
stdout.printGlobalConfigs();
}
//printf("%d source files\n", cast(int) files.length);
// Build import search path
static Strings* buildPath(Strings* imppath)
{
Strings* result = null;
if (imppath)
{
foreach (const path; *imppath)
{
Strings* a = FileName.splitPath(path);
if (a)
{
if (!result)
result = new Strings();
result.append(a);
}
}
}
return result;
}
if (params.mixinOut.doOutput)
{
params.mixinOut.buffer = cast(OutBuffer*)Mem.check(calloc(1, OutBuffer.sizeof));
atexit(&flushMixins); // see comment for flushMixins
}
scope(exit) flushMixins();
global.path = buildPath(params.imppath);
global.filePath = buildPath(params.fileImppath);
// Create Modules
Modules modules = createModules(files, libmodules, target);
// Read files
foreach (m; modules)
{
m.read(Loc.initial);
}
// Parse files
bool anydocfiles = false;
size_t filecount = modules.length;
for (size_t filei = 0, modi = 0; filei < filecount; filei++, modi++)
{
Module m = modules[modi];
if (params.verbose)
message("parse %s", m.toChars());
if (!Module.rootModule)
Module.rootModule = m;
m.importedFrom = m; // m.isRoot() == true
// if (!driverParams.oneobj || modi == 0 || m.isDocFile)
// m.deleteObjFile();
m.parse();
if (m.filetype == FileType.dhdr)
{
// Remove m's object file from list of object files
for (size_t j = 0; j < params.objfiles.length; j++)
{
if (m.objfile.toChars() == params.objfiles[j])
{
params.objfiles.remove(j);
break;
}
}
if (params.objfiles.length == 0)
driverParams.link = false;
}
if (m.filetype == FileType.ddoc)
{
anydocfiles = true;
gendocfile(m);
// Remove m from list of modules
modules.remove(modi);
modi--;
// Remove m's object file from list of object files
for (size_t j = 0; j < params.objfiles.length; j++)
{
if (m.objfile.toChars() == params.objfiles[j])
{
params.objfiles.remove(j);
break;
}
}
if (params.objfiles.length == 0)
driverParams.link = false;
}
}
if (anydocfiles && modules.length && (driverParams.oneobj || params.objname))
{
error(Loc.initial, "conflicting Ddoc and obj generation options");
fatal();
}
if (global.errors)
fatal();
if (params.dihdr.doOutput)
{
/* Generate 'header' import files.
* Since 'header' import files must be independent of command
* line switches and what else is imported, they are generated
* before any semantic analysis.
*/
foreach (m; modules)
{
if (m.filetype == FileType.dhdr)
continue;
if (params.verbose)
message("import %s", m.toChars());
genhdrfile(m);
}
}
if (global.errors)
removeHdrFilesAndFail(params, modules);
// load all unconditional imports for better symbol resolving
foreach (m; modules)
{
if (params.verbose)
message("importall %s", m.toChars());
m.importAll(null);
}
if (global.errors)
removeHdrFilesAndFail(params, modules);
backend_init();
// Do semantic analysis
foreach (m; modules)
{
if (params.verbose)
message("semantic %s", m.toChars());
m.dsymbolSemantic(null);
}
//if (global.errors)
// fatal();
Module.runDeferredSemantic();
if (Module.deferred.length)
{
for (size_t i = 0; i < Module.deferred.length; i++)
{
Dsymbol sd = Module.deferred[i];
sd.error("unable to resolve forward reference in definition");
}
//fatal();
}
// Do pass 2 semantic analysis
foreach (m; modules)
{
if (params.verbose)
message("semantic2 %s", m.toChars());
m.semantic2(null);
}
Module.runDeferredSemantic2();
if (global.errors)
removeHdrFilesAndFail(params, modules);
// Do pass 3 semantic analysis
foreach (m; modules)
{
if (params.verbose)
message("semantic3 %s", m.toChars());
m.semantic3(null);
}
if (includeImports)
{
// Note: DO NOT USE foreach here because Module.amodules.length can
// change on each iteration of the loop
for (size_t i = 0; i < compiledImports.length; i++)
{
auto m = compiledImports[i];
assert(m.isRoot);
if (params.verbose)
message("semantic3 %s", m.toChars());
m.semantic3(null);
modules.push(m);
}
}
Module.runDeferredSemantic3();
if (global.errors)
removeHdrFilesAndFail(params, modules);
// Scan for functions to inline
foreach (m; modules)
{
if (params.useInline || m.hasAlwaysInlines)
{
if (params.verbose)
message("inline scan %s", m.toChars());
inlineScanModule(m);
}
}
if (global.warnings)
errorOnWarning();
// Do not attempt to generate output files if errors or warnings occurred
if (global.errors || global.warnings)
removeHdrFilesAndFail(params, modules);
// inlineScan incrementally run semantic3 of each expanded functions.
// So deps file generation should be moved after the inlining stage.
if (OutBuffer* ob = params.moduleDeps.buffer)
{
foreach (i; 1 .. modules[0].aimports.length)
semantic3OnDependencies(modules[0].aimports[i]);
Module.runDeferredSemantic3();
const data = (*ob)[];
if (params.moduleDeps.name)
writeFile(Loc.initial, params.moduleDeps.name, data);
else
printf("%.*s", cast(int)data.length, data.ptr);
}
printCtfePerformanceStats();
printTemplateStats();
// Generate output files
if (params.json.doOutput)
{
generateJson(&modules);
}
if (!global.errors && params.ddoc.doOutput)
{
foreach (m; modules)
{
gendocfile(m);
}
}
if (params.vcg_ast)
{
import dmd.hdrgen;
foreach (mod; modules)
{
auto buf = OutBuffer();
buf.doindent = 1;
moduleToBuffer(&buf, mod);
// write the output to $(filename).cg
auto cgFilename = FileName.addExt(mod.srcfile.toString(), "cg");
File.write(cgFilename.ptr, buf[]);
}
}
if (global.params.cxxhdr.doOutput)
genCppHdrFiles(modules);
if (global.errors)
fatal();
if (driverParams.lib && params.objfiles.length == 0)
{
error(Loc.initial, "no input files");
return EXIT_FAILURE;
}
if (params.addMain && !global.hasMainFunction)
{
auto mainModule = moduleWithEmptyMain();
modules.push(mainModule);
if (!driverParams.oneobj || modules.length == 1)
params.objfiles.push(mainModule.objfile.toChars());
}
generateCodeAndWrite(modules[], libmodules[], params.libname, params.objdir,
driverParams.lib, params.obj, driverParams.oneobj, params.multiobj,
params.verbose);
backend_term();
if (global.errors)
fatal();
int status = EXIT_SUCCESS;
if (!params.objfiles.length)
{
if (driverParams.link)
error(Loc.initial, "no object files to link");
}
else
{
if (driverParams.link)
status = runLINK();
if (params.run)
{
if (!status)
{
status = runProgram();
/* Delete .obj files and .exe file
*/
foreach (m; modules)
{
m.deleteObjFile();
if (driverParams.oneobj)
break;
}
params.exefile.toCStringThen!(ef => File.remove(ef.ptr));
}
}
}
// Output the makefile dependencies
if (params.makeDeps.doOutput)
emitMakeDeps(params);
if (global.warnings)
errorOnWarning();
if (global.errors || global.warnings)
removeHdrFilesAndFail(params, modules);
return status;
}
/**
* Parses the command line arguments and configuration files
*
* Params:
* argc = Number of arguments passed via command line
* argv = Array of string arguments passed via command line
* params = parametes from argv
* files = files from argv
* Returns: true on faiure
*/
version(NoMain) {} else
bool parseCommandlineAndConfig(size_t argc, const(char)** argv, ref Param params, ref Strings files)
{
// Detect malformed input
static bool badArgs()
{
error(Loc.initial, "missing or null command line arguments");
return true;
}
if (argc < 1 || !argv)
return badArgs();
// Convert argc/argv into arguments[] for easier handling
Strings arguments = Strings(argc);
for (size_t i = 0; i < argc; i++)
{
if (!argv[i])
return badArgs();
arguments[i] = argv[i];
}
if (const(char)* missingFile = responseExpand(arguments)) // expand response files
error(Loc.initial, "cannot open response file '%s'", missingFile);
//for (size_t i = 0; i < arguments.length; ++i) printf("arguments[%d] = '%s'\n", i, arguments[i]);
files.reserve(arguments.length - 1);
// Set default values
params.argv0 = arguments[0].toDString;
version (Windows)
enum iniName = "sc.ini";
else version (Posix)
enum iniName = "dmd.conf";
else
static assert(0, "fix this");
global.inifilename = parse_conf_arg(&arguments);
if (global.inifilename)
{
// can be empty as in -conf=
if (global.inifilename.length && !FileName.exists(global.inifilename))
error(Loc.initial, "config file '%.*s' does not exist.",
cast(int)global.inifilename.length, global.inifilename.ptr);
}
else
{
global.inifilename = findConfFile(params.argv0, iniName);
}
// Read the configuration file
const iniReadResult = File.read(global.inifilename);
const inifileBuffer = iniReadResult.buffer.data;
/* Need path of configuration file, for use in expanding @P macro
*/
const(char)[] inifilepath = FileName.path(global.inifilename);
Strings sections;
StringTable!(char*) environment;
environment._init(7);
/* Read the [Environment] section, so we can later
* pick up any DFLAGS settings.
*/
sections.push("Environment");
parseConfFile(environment, global.inifilename, inifilepath, inifileBuffer, §ions);
const(char)[] arch = target.is64bit ? "64" : "32"; // use default
arch = parse_arch_arg(&arguments, arch);
// parse architecture from DFLAGS read from [Environment] section
{
Strings dflags;
getenv_setargv(readFromEnv(environment, "DFLAGS"), &dflags);
environment.reset(7); // erase cached environment updates
arch = parse_arch_arg(&dflags, arch);
}
bool is64bit = arch[0] == '6';
version(Windows) // delete LIB entry in [Environment] (necessary for optlink) to allow inheriting environment for MS-COFF
if (arch != "32omf")
environment.update("LIB", 3).value = null;
// read from DFLAGS in [Environment{arch}] section
char[80] envsection = void;
snprintf(envsection.ptr, envsection.length, "Environment%.*s", cast(int) arch.length, arch.ptr);
sections.push(envsection.ptr);
parseConfFile(environment, global.inifilename, inifilepath, inifileBuffer, §ions);
getenv_setargv(readFromEnv(environment, "DFLAGS"), &arguments);
updateRealEnvironment(environment);
environment.reset(1); // don't need environment cache any more
if (parseCommandLine(arguments, argc, params, files, target))
{
Loc loc;
errorSupplemental(loc, "run `dmd` to print the compiler manual");
errorSupplemental(loc, "run `dmd -man` to open browser on manual");
return true;
}
if (target.is64bit != is64bit)
error(Loc.initial, "the architecture must not be changed in the %s section of %.*s",
envsection.ptr, cast(int)global.inifilename.length, global.inifilename.ptr);
global.preprocess = &preprocess;
return false;
}
/// Emit the makefile dependencies for the -makedeps switch
version (NoMain) {} else
{
void emitMakeDeps(ref Param params)
{
assert(params.makeDeps.doOutput);
OutBuffer buf;
// start by resolving and writing the target (which is sometimes resolved during link phase)
if (driverParams.link && params.exefile)
{
buf.writeEscapedMakePath(¶ms.exefile[0]);
}
else if (driverParams.lib)
{
const(char)[] libname = params.libname ? params.libname : FileName.name(params.objfiles[0].toDString);
libname = FileName.forceExt(libname,target.lib_ext);
buf.writeEscapedMakePath(&libname[0]);
}
else if (params.objname)
{
buf.writeEscapedMakePath(¶ms.objname[0]);
}
else if (params.objfiles.length)
{
buf.writeEscapedMakePath(params.objfiles[0]);
foreach (of; params.objfiles[1 .. $])
{
buf.writestring(" ");
buf.writeEscapedMakePath(of);
}
}
else
{
assert(false, "cannot resolve makedeps target");
}
buf.writestring(":");
// then output every dependency
foreach (dep; params.makeDeps.files)
{
buf.writestringln(" \\");
buf.writestring(" ");
buf.writeEscapedMakePath(dep);
}
buf.writenl();
const data = buf[];
if (params.makeDeps.name)
writeFile(Loc.initial, params.makeDeps.name, data);
else
printf("%.*s", cast(int) data.length, data.ptr);
}
}
extern (C++) void generateJson(Modules* modules)
{
OutBuffer buf;
json_generate(&buf, modules);
// Write buf to file
const(char)[] name = global.params.json.name;
if (name == "-")
{
// Write to stdout; assume it succeeds
size_t n = fwrite(buf[].ptr, 1, buf.length, stdout);
assert(n == buf.length); // keep gcc happy about return values
}
else
{
/* The filename generation code here should be harmonized with Module.setOutfilename()
*/
const(char)[] jsonfilename;
if (name)
{
jsonfilename = FileName.defaultExt(name, json_ext);
}
else
{
if (global.params.objfiles.length == 0)
{
error(Loc.initial, "cannot determine JSON filename, use `-Xf=<file>` or provide a source file");
fatal();
}
// Generate json file name from first obj name
const(char)[] n = global.params.objfiles[0].toDString;
n = FileName.name(n);
//if (!FileName::absolute(name))
// name = FileName::combine(dir, name);
jsonfilename = FileName.forceExt(n, json_ext);
}
writeFile(Loc.initial, jsonfilename, buf[]);
}
}
version (DigitalMars)
{
private void installMemErrHandler()
{
// (only available on some platforms on DMD)
const shouldDoMemoryError = getenv("DMD_INSTALL_MEMERR_HANDLER");
if (shouldDoMemoryError !is null && *shouldDoMemoryError == '1')
{
import etc.linux.memoryerror;
static if (is(typeof(registerMemoryErrorHandler())))
{
registerMemoryErrorHandler();
}
else
{
printf("**WARNING** Memory error handler not supported on this platform!\n");
}
}
}
}
version (NoMain)
{
version (DigitalMars)
{
shared static this()
{
installMemErrHandler();
}
}
}
else
{
// in druntime:
alias MainFunc = extern(C) int function(char[][] args);
extern (C) int _d_run_main(int argc, char** argv, MainFunc dMain);
// When using a C main, host DMD may not link against host druntime by default.
version (DigitalMars)
{
version (Win64)
pragma(lib, "phobos64");
else version (Win32)
{
version (CRuntime_Microsoft)
pragma(lib, "phobos32mscoff");
else
pragma(lib, "phobos");
}
}
extern extern(C) __gshared string[] rt_options;
/**
* DMD's entry point, C main.
*
* Without `-lowmem`, we need to switch to the bump-pointer allocation scheme
* right from the start, before any module ctors are run, so we need this hook
* before druntime is initialized and `_Dmain` is called.
*
* Returns:
* Return code of the application
*/
extern (C) int main(int argc, char** argv)
{
bool lowmem = false;
foreach (i; 1 .. argc)
{
if (strcmp(argv[i], "-lowmem") == 0)
{
lowmem = true;
break;
}
}
if (!lowmem)
{
__gshared string[] disable_options = [ "gcopt=disable:1" ];
rt_options = disable_options;
mem.disableGC();
}
// initialize druntime and call _Dmain() below
return _d_run_main(argc, argv, &_Dmain);
}
/**
* Manual D main (for druntime initialization), which forwards to `tryMain`.
*
* Returns:
* Return code of the application
*/
extern (C) int _Dmain(char[][])
{
// possibly install memory error handler
version (DigitalMars)
{
installMemErrHandler();
}
import core.runtime;
version(D_Coverage)
{
// for now we need to manually set the source path
string dirName(string path, char separator)
{
for (size_t i = path.length - 1; i > 0; i--)
{
if (path[i] == separator)
return path[0..i];
}
return path;
}
version (Windows)
enum sourcePath = dirName(dirName(dirName(__FILE_FULL_PATH__, '\\'), '\\'), '\\');
else
enum sourcePath = dirName(dirName(dirName(__FILE_FULL_PATH__, '/'), '/'), '/');
dmd_coverSourcePath(sourcePath);
dmd_coverDestPath(sourcePath);
dmd_coverSetMerge(true);
}
scope(failure) stderr.printInternalFailure;
auto args = Runtime.cArgs();
return tryMain(args.argc, cast(const(char)**)args.argv, global.params);
}
} // !NoMain
/**
* Parses an environment variable containing command-line flags
* and append them to `args`.
*
* This function is used to read the content of DFLAGS.
* Flags are separated based on spaces and tabs.
*
* Params:
* envvalue = The content of an environment variable
* args = Array to append the flags to, if any.
*/
void getenv_setargv(const(char)* envvalue, Strings* args)
{
if (!envvalue)
return;
char* env = mem.xstrdup(envvalue); // create our own writable copy
//printf("env = '%s'\n", env);
while (1)
{
switch (*env)
{
case ' ':
case '\t':
env++;
break;
case 0:
return;
default:
{
args.push(env); // append
auto p = env;
auto slash = 0;
bool instring = false;
while (1)
{
auto c = *env++;
switch (c)
{
case '"':
p -= (slash >> 1);
if (slash & 1)
{
p--;
goto default;
}
instring ^= true;
slash = 0;
continue;
case ' ':
case '\t':
if (instring)
goto default;
*p = 0;
//if (wildcard)
// wildcardexpand(); // not implemented
break;
case '\\':
slash++;
*p++ = c;
continue;
case 0:
*p = 0;
//if (wildcard)
// wildcardexpand(); // not implemented
return;
default:
slash = 0;
*p++ = c;
continue;
}
break;
}
break;
}
}
}
}
/**
* Parse command line arguments for the last instance of -m32, -m64, -m32mscoff or -m32omfobj
* to detect the desired architecture.
*
* Params:
* args = Command line arguments
* arch = Default value to use for architecture.
* Should be "32" or "64"
*
* Returns:
* "32", "64" or "32omf" if the "-m32", "-m64", "-m32omf" flags were passed,
* respectively. If they weren't, return `arch`.
*/
const(char)[] parse_arch_arg(Strings* args, const(char)[] arch)
{
foreach (const p; *args)
{
const(char)[] arg = p.toDString;
if (arg.length && arg[0] == '-')
{
if (arg[1 .. $] == "m32" || arg[1 .. $] == "m32omf" || arg[1 .. $] == "m64")
arch = arg[2 .. $];
else if (arg[1 .. $] == "m32mscoff")
arch = "32";
else if (arg[1 .. $] == "run")
break;
}
}
return arch;
}
/**
* Parse command line arguments for the last instance of -conf=path.
*
* Params:
* args = Command line arguments
*
* Returns:
* The 'path' in -conf=path, which is the path to the config file to use
*/
const(char)[] parse_conf_arg(Strings* args)
{
const(char)[] conf;
foreach (const p; *args)
{
const(char)[] arg = p.toDString;
if (arg.length && arg[0] == '-')
{
if(arg.length >= 6 && arg[1 .. 6] == "conf="){
conf = arg[6 .. $];
}
else if (arg[1 .. $] == "run")
break;
}
}
return conf;
}
/**
* Set the default and debug libraries to link against, if not already set
*
* Must be called after argument parsing is done, as it won't
* override any value.
* Note that if `-defaultlib=` or `-debuglib=` was used,
* we don't override that either.
*/
private void setDefaultLibrary(ref Param params, const ref Target target)
{
if (driverParams.defaultlibname is null)
{
if (target.os == Target.OS.Windows)
{
if (target.is64bit)
driverParams.defaultlibname = "phobos64";
else if (!target.omfobj)
driverParams.defaultlibname = "phobos32mscoff";
else
driverParams.defaultlibname = "phobos";
}
else if (target.os & (Target.OS.linux | Target.OS.FreeBSD | Target.OS.OpenBSD | Target.OS.Solaris | Target.OS.DragonFlyBSD))
{
driverParams.defaultlibname = "libphobos2.a";
}
else if (target.os == Target.OS.OSX)
{
driverParams.defaultlibname = "phobos2";
}
else
{
assert(0, "fix this");
}
}
else if (!driverParams.defaultlibname.length) // if `-defaultlib=` (i.e. an empty defaultlib)
driverParams.defaultlibname = null;
if (driverParams.debuglibname is null)
driverParams.debuglibname = driverParams.defaultlibname;
}
private void printPredefinedVersions(FILE* stream)
{
if (global.versionids)
{
OutBuffer buf;
foreach (const str; *global.versionids)
{
buf.writeByte(' ');
buf.writestring(str.toChars());
}
stream.fprintf("predefs %s\n", buf.peekChars());
}
}
extern(C) void printGlobalConfigs(FILE* stream)
{
stream.fprintf("binary %.*s\n", cast(int)global.params.argv0.length, global.params.argv0.ptr);
stream.fprintf("version %.*s\n", cast(int) global.versionString().length, global.versionString().ptr);
const iniOutput = global.inifilename ? global.inifilename : "(none)";
stream.fprintf("config %.*s\n", cast(int)iniOutput.length, iniOutput.ptr);
// Print DFLAGS environment variable
{
StringTable!(char*) environment;
environment._init(0);
Strings dflags;
getenv_setargv(readFromEnv(environment, "DFLAGS"), &dflags);
environment.reset(1);
OutBuffer buf;
foreach (flag; dflags[])
{
bool needsQuoting;
foreach (c; flag.toDString())
{
if (!(isalnum(c) || c == '_'))
{
needsQuoting = true;
break;
}
}
if (flag.strchr(' '))
buf.printf("'%s' ", flag);
else
buf.printf("%s ", flag);
}
auto res = buf[] ? buf[][0 .. $ - 1] : "(none)";
stream.fprintf("DFLAGS %.*s\n", cast(int)res.length, res.ptr);
}
}
/**************************************
* we want to write the mixin expansion file also on error, but there
* are too many ways to terminate dmd (e.g. fatal() which calls exit(EXIT_FAILURE)),
* so we can't rely on scope(exit) ... in tryMain() actually being executed
* so we add atexit(&flushMixins); for those fatal exits (with the GC still valid)
*/
extern(C) void flushMixins()
{
if (!global.params.mixinOut.buffer)
return;
assert(global.params.mixinOut.name);
File.write(global.params.mixinOut.name, (*global.params.mixinOut.buffer)[]);
global.params.mixinOut.buffer.destroy();
global.params.mixinOut.buffer = null;
}
/****************************************************
* Parse command line arguments.
*
* Prints message(s) if there are errors.
*
* Params:
* arguments = command line arguments
* argc = argument count
* params = set to result of parsing `arguments`
* files = set to files pulled from `arguments`
* target = more things set to result of parsing `arguments`
* Returns:
* true if errors in command line
*/
bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param params, ref Strings files, ref Target target)
{
bool errors;
void error(Args ...)(const(char)* format, Args args)
{
dmd.errors.error(Loc.initial, format, args);
errors = true;
}
/**
* Print an error messsage about an invalid switch.
* If an optional supplemental message has been provided,
* it will be printed too.
*
* Params:
* p = 0 terminated string
* availableOptions = supplemental help message listing the available options
*/
void errorInvalidSwitch(const(char)* p, string availableOptions = null)
{
error("switch `%s` is invalid", p);
if (availableOptions !is null)
errorSupplemental(Loc.initial, "%.*s", cast(int)availableOptions.length, availableOptions.ptr);
}
enum CheckOptions { success, error, help }
/*
Checks whether the CLI options contains a valid argument or a help argument.
If a help argument has been used, it will set the `usageFlag`.
Params:
p = string as a D array
usageFlag = parameter for the usage help page to set (by `ref`)
missingMsg = error message to use when no argument has been provided
Returns:
`success` if a valid argument has been passed and it's not a help page
`error` if an error occurred (e.g. `-foobar`)
`help` if a help page has been request (e.g. `-flag` or `-flag=h`)
*/
CheckOptions checkOptions(const(char)[] p, ref bool usageFlag, string missingMsg)
{
// Checks whether a flag has no options (e.g. -foo or -foo=)
if (p.length == 0 || p == "=")
{
.error(Loc.initial, "%.*s", cast(int)missingMsg.length, missingMsg.ptr);
errors = true;
usageFlag = true;
return CheckOptions.help;
}
if (p[0] != '=')
return CheckOptions.error;
p = p[1 .. $];
/* Checks whether the option pointer supplied is a request
for the help page, e.g. -foo=j */
if ((p == "h" || p == "?") || // -flag=h || -flag=?
p == "help")
{
usageFlag = true;
return CheckOptions.help;
}
return CheckOptions.success;
}
static string checkOptionsMixin(string usageFlag, string missingMsg)
{
return q{
final switch (checkOptions(arg[len - 1 .. $], params.}~usageFlag~","~
`"`~missingMsg~`"`~q{))
{
case CheckOptions.error:
goto Lerror;
case CheckOptions.help:
return false;
case CheckOptions.success:
break;
}
};
}
import dmd.cli : Usage;
bool parseCLIOption(string name, Usage.Feature[] features)(ref Param params, const(char)[] p)
{
// Parse:
// -<name>=<feature>
const(char)[] ps = p[name.length + 1 .. $];
const(char)[] ident = ps[1 .. $];
if (Identifier.isValidIdentifier(ident))
{
string generateTransitionsText()
{
import dmd.cli : Usage;
string buf = `case "all":`;
foreach (t; features)
{
if (t.deprecated_)
continue;
buf ~= `setFlagFor(name, params.`~t.paramName~`);`;
}
buf ~= "return true;\n";
foreach (t; features)
{
buf ~= `case "`~t.name~`":`;
if (t.deprecated_)
buf ~= "deprecation(Loc.initial, \"`-"~name~"="~t.name~"` no longer has any effect.\"); ";
buf ~= `setFlagFor(name, params.`~t.paramName~`); return true;`;
}
return buf;
}
switch (ident)
{
mixin(generateTransitionsText());
default:
return false;
}
}
return false;
}
version (none)
{
for (size_t i = 0; i < arguments.length; i++)
{
printf("arguments[%d] = '%s'\n", i, arguments[i]);
}
}
for (size_t i = 1; i < arguments.length; i++)
{
const(char)* p = arguments[i];
const(char)[] arg = p.toDString();
if (*p != '-')
{
if (target.os == Target.OS.Windows)
{
const ext = FileName.ext(arg);
if (ext.length && FileName.equals(ext, "exe"))
{
params.objname = arg;
continue;
}
if (arg == "/?")
{
params.usage = true;
return false;
}
}
files.push(p);
continue;
}
if (arg == "-allinst") // https://dlang.org/dmd.html#switch-allinst
params.allInst = true;
else if (startsWith(p + 1, "cpp=")) // https://dlang.org/dmd.html#switch-cpp
{
if (p[5])
{
params.cpp = p + 5;
}
else
{
errorInvalidSwitch(p, "it must be followed by the filename of the desired C preprocessor");
return false;
}
}
else if (arg == "-de") // https://dlang.org/dmd.html#switch-de
params.useDeprecated = DiagnosticReporting.error;
else if (arg == "-d") // https://dlang.org/dmd.html#switch-d
params.useDeprecated = DiagnosticReporting.off;
else if (arg == "-dw") // https://dlang.org/dmd.html#switch-dw
params.useDeprecated = DiagnosticReporting.inform;
else if (arg == "-c") // https://dlang.org/dmd.html#switch-c
driverParams.link = false;
else if (startsWith(p + 1, "checkaction")) // https://dlang.org/dmd.html#switch-checkaction
{
/* Parse:
* -checkaction=D|C|halt|context
*/
enum len = "-checkaction=".length;
mixin(checkOptionsMixin("checkActionUsage",
"`-check=<behavior>` requires a behavior"));
switch (arg[len .. $])
{
case "D":
params.checkAction = CHECKACTION.D;
break;
case "C":
params.checkAction = CHECKACTION.C;
break;
case "halt":
params.checkAction = CHECKACTION.halt;
break;
case "context":
params.checkAction = CHECKACTION.context;
break;
default:
errorInvalidSwitch(p);
params.checkActionUsage = true;
return false;
}
}
else if (startsWith(p + 1, "check")) // https://dlang.org/dmd.html#switch-check
{
enum len = "-check=".length;
mixin(checkOptionsMixin("checkUsage",
"`-check=<action>` requires an action"));
/* Parse:
* -check=[assert|bounds|in|invariant|out|switch][=[on|off]]
*/
// Check for legal option string; return true if so
static bool check(const(char)[] checkarg, string name, ref CHECKENABLE ce)
{
if (checkarg.length >= name.length &&
checkarg[0 .. name.length] == name)
{
checkarg = checkarg[name.length .. $];
if (checkarg.length == 0 ||
checkarg == "=on")
{
ce = CHECKENABLE.on;
return true;
}
else if (checkarg == "=off")
{
ce = CHECKENABLE.off;
return true;
}
}
return false;
}
const(char)[] checkarg = arg[len .. $];
if (checkarg == "on")
{
params.useAssert = CHECKENABLE.on;
params.useArrayBounds = CHECKENABLE.on;
params.useIn = CHECKENABLE.on;
params.useInvariants = CHECKENABLE.on;
params.useOut = CHECKENABLE.on;
params.useSwitchError = CHECKENABLE.on;
}
else if (checkarg == "off")
{
params.useAssert = CHECKENABLE.off;
params.useArrayBounds = CHECKENABLE.off;
params.useIn = CHECKENABLE.off;
params.useInvariants = CHECKENABLE.off;
params.useOut = CHECKENABLE.off;
params.useSwitchError = CHECKENABLE.off;
}
else if (!(check(checkarg, "assert", params.useAssert) ||
check(checkarg, "bounds", params.useArrayBounds) ||
check(checkarg, "in", params.useIn ) ||
check(checkarg, "invariant", params.useInvariants ) ||
check(checkarg, "out", params.useOut ) ||
check(checkarg, "switch", params.useSwitchError)))
{
errorInvalidSwitch(p);
params.checkUsage = true;
return false;
}
}
else if (startsWith(p + 1, "color")) // https://dlang.org/dmd.html#switch-color
{
// Parse:
// -color
// -color=auto|on|off
if (p[6] == '=')
{
switch(arg[7 .. $])
{
case "on":
params.color = true;
break;
case "off":
params.color = false;
break;
case "auto":
break;
default:
errorInvalidSwitch(p, "Available options for `-color` are `on`, `off` and `auto`");
return true;
}
}
else if (p[6])
goto Lerror;
else
params.color = true;
}
else if (startsWith(p + 1, "conf=")) // https://dlang.org/dmd.html#switch-conf
{
// ignore, already handled above
}
else if (startsWith(p + 1, "cov")) // https://dlang.org/dmd.html#switch-cov
{
params.cov = true;
// Parse:
// -cov
// -cov=ctfe
// -cov=nnn
if (arg == "-cov=ctfe")
{
params.ctfe_cov = true;
}
else if (p[4] == '=')
{
if (!params.covPercent.parseDigits(p.toDString()[5 .. $], 100))
{
errorInvalidSwitch(p, "Only a number between 0 and 100 can be passed to `-cov=<num>`");
return true;
}
}
else if (p[4])
goto Lerror;
}
else if (arg == "-shared")
driverParams.dll = true;
else if (arg == "-fPIC")
{
driverParams.pic = PIC.pic;
}
else if (arg == "-fPIE")
{
driverParams.pic = PIC.pie;
}
else if (arg == "-map") // https://dlang.org/dmd.html#switch-map
driverParams.map = true;
else if (arg == "-multiobj")
params.multiobj = true;
else if (startsWith(p + 1, "mixin="))
{
auto tmp = p + 6 + 1;
if (!tmp[0])
goto Lnoarg;
params.mixinOut.doOutput = true;
params.mixinOut.name = mem.xstrdup(tmp).toDString;
}
else if (arg == "-g") // https://dlang.org/dmd.html#switch-g
driverParams.symdebug = true;
else if (startsWith(p + 1, "gdwarf")) // https://dlang.org/dmd.html#switch-gdwarf
{
if (driverParams.dwarf)
{
error("`-gdwarf=<version>` can only be provided once");
break;
}
driverParams.symdebug = true;
enum len = "-gdwarf=".length;
// Parse:
// -gdwarf=version
if (arg.length < len || !driverParams.dwarf.parseDigits(arg[len .. $], 5) || driverParams.dwarf < 3)
{
error("`-gdwarf=<version>` requires a valid version [3|4|5]", p);
return false;
}
}
else if (arg == "-gf")
{
driverParams.symdebug = true;
driverParams.symdebugref = true;
}
else if (arg == "-gs") // https://dlang.org/dmd.html#switch-gs
driverParams.alwaysframe = true;
else if (arg == "-gx") // https://dlang.org/dmd.html#switch-gx
driverParams.stackstomp = true;
else if (arg == "-lowmem") // https://dlang.org/dmd.html#switch-lowmem
{
// ignore, already handled in C main
}
else if (arg.length > 6 && arg[0..6] == "--DRT-")
{
continue; // skip druntime options, e.g. used to configure the GC
}
else if (arg == "-m32") // https://dlang.org/dmd.html#switch-m32
{
target.is64bit = false;
target.omfobj = false;
}
else if (arg == "-m64") // https://dlang.org/dmd.html#switch-m64
{
target.is64bit = true;
target.omfobj = false;
}
else if (arg == "-m32mscoff") // https://dlang.org/dmd.html#switch-m32mscoff
{
target.is64bit = false;
target.omfobj = false;
}
else if (arg == "-m32omf") // https://dlang.org/dmd.html#switch-m32omfobj
{
target.is64bit = false;
target.omfobj = true;
}
else if (startsWith(p + 1, "mscrtlib="))
{
driverParams.mscrtlib = arg[10 .. $];
}
else if (startsWith(p + 1, "profile")) // https://dlang.org/dmd.html#switch-profile
{
// Parse:
// -profile
// -profile=gc
if (p[8] == '=')
{
if (arg[9 .. $] == "gc")
params.tracegc = true;
else
{
errorInvalidSwitch(p, "Only `gc` is allowed for `-profile`");
return true;
}
}
else if (p[8])
goto Lerror;
else
params.trace = true;
}
else if (arg == "-v") // https://dlang.org/dmd.html#switch-v
params.verbose = true;
else if (arg == "-vcg-ast")
params.vcg_ast = true;
else if (arg == "-vasm") // https://dlang.org/dmd.html#switch-vasm
driverParams.vasm = true;
else if (arg == "-vtls") // https://dlang.org/dmd.html#switch-vtls
params.vtls = true;
else if (startsWith(p + 1, "vtemplates")) // https://dlang.org/dmd.html#switch-vtemplates
{
params.vtemplates = true;
if (p[1 + "vtemplates".length] == '=')
{
const(char)[] style = arg[1 + "vtemplates=".length .. $];
switch (style)
{
case "list-instances":
params.vtemplatesListInstances = true;
break;
default:
error("unknown vtemplates style '%.*s', must be 'list-instances'", cast(int) style.length, style.ptr);
}
}
}
else if (arg == "-vcolumns") // https://dlang.org/dmd.html#switch-vcolumns
params.showColumns = true;
else if (arg == "-vgc") // https://dlang.org/dmd.html#switch-vgc
params.vgc = true;
else if (startsWith(p + 1, "verrors")) // https://dlang.org/dmd.html#switch-verrors
{
if (p[8] != '=')
{
errorInvalidSwitch(p, "Expected argument following `-verrors , e.g. `-verrors=100`");
return true;
}
if (startsWith(p + 9, "spec"))
{
params.showGaggedErrors = true;
}
else if (startsWith(p + 9, "context"))
{
params.printErrorContext = true;
}
else if (!params.errorLimit.parseDigits(p.toDString()[9 .. $]))
{
errorInvalidSwitch(p, "Only number, `spec`, or `context` are allowed for `-verrors`");
return true;
}
}
else if (startsWith(p + 1, "verror-supplements"))
{
if (!params.errorSupplementLimit.parseDigits(p.toDString()[20 .. $]))
{
errorInvalidSwitch(p, "Only a number is allowed for `-verror-supplements`");
return true;
}
}
else if (startsWith(p + 1, "verror-style="))
{
const(char)[] style = arg["verror-style=".length + 1 .. $];
switch (style)
{
case "digitalmars":
params.messageStyle = MessageStyle.digitalmars;
break;
case "gnu":
params.messageStyle = MessageStyle.gnu;
break;
default:
error("unknown error style '%.*s', must be 'digitalmars' or 'gnu'", cast(int) style.length, style.ptr);
}
}
else if (startsWith(p + 1, "target"))
{
enum len = "-target=".length;
const triple = Triple(p + len);
target.setTriple(triple);
}
else if (startsWith(p + 1, "mcpu")) // https://dlang.org/dmd.html#switch-mcpu
{
enum len = "-mcpu=".length;
// Parse:
// -mcpu=identifier
mixin(checkOptionsMixin("mcpuUsage",
"`-mcpu=<architecture>` requires an architecture"));
if (Identifier.isValidIdentifier(p + len))
{
const ident = p + len;
switch (ident.toDString())
{
case "baseline":
target.cpu = CPU.baseline;
break;
case "avx":
target.cpu = CPU.avx;
break;
case "avx2":
target.cpu = CPU.avx2;
break;
case "native":
target.cpu = CPU.native;
break;
default:
errorInvalidSwitch(p, "Only `baseline`, `avx`, `avx2` or `native` are allowed for `-mcpu`");
params.mcpuUsage = true;
return false;
}
}
else
{
errorInvalidSwitch(p, "Only `baseline`, `avx`, `avx2` or `native` are allowed for `-mcpu`");
params.mcpuUsage = true;
return false;
}
}
else if (startsWith(p + 1, "os")) // https://dlang.org/dmd.html#switch-os
{
enum len = "-os=".length;
// Parse:
// -os=identifier
immutable string msg = "Only `host`, `linux`, `windows`, `osx`,`openbsd`, `freebsd`, `solaris`, `dragonflybsd` allowed for `-os`";
if (Identifier.isValidIdentifier(p + len))
{
const ident = p + len;
switch (ident.toDString())
{
case "host": target.os = defaultTargetOS(); break;
case "linux": target.os = Target.OS.linux; break;
case "windows": target.os = Target.OS.Windows; break;
case "osx": target.os = Target.OS.OSX; break;
case "openbsd": target.os = Target.OS.OpenBSD; break;
case "freebsd": target.os = Target.OS.FreeBSD; break;
case "solaris": target.os = Target.OS.Solaris; break;
case "dragonflybsd": target.os = Target.OS.DragonFlyBSD; break;
default:
errorInvalidSwitch(p, msg);
return false;
}
}
else
{
errorInvalidSwitch(p, msg);
return false;
}
}
else if (startsWith(p + 1, "extern-std")) // https://dlang.org/dmd.html#switch-extern-std
{
enum len = "-extern-std=".length;
// Parse:
// -extern-std=identifier
mixin(checkOptionsMixin("externStdUsage",
"`-extern-std=<standard>` requires a standard"));
const(char)[] cpprev = arg[len .. $];
switch (cpprev)
{
case "c++98":
params.cplusplus = CppStdRevision.cpp98;
break;
case "c++11":
params.cplusplus = CppStdRevision.cpp11;
break;
case "c++14":
params.cplusplus = CppStdRevision.cpp14;
break;
case "c++17":
params.cplusplus = CppStdRevision.cpp17;
break;
case "c++20":
params.cplusplus = CppStdRevision.cpp20;
break;
default:
error("switch `%s` is invalid", p);
params.externStdUsage = true;
return false;
}
}
else if (startsWith(p + 1, "transition")) // https://dlang.org/dmd.html#switch-transition
{
enum len = "-transition=".length;
// Parse:
// -transition=number
mixin(checkOptionsMixin("transitionUsage",
"`-transition=<name>` requires a name"));
if (!parseCLIOption!("transition", Usage.transitions)(params, arg))
{
// Legacy -transition flags
// Before DMD 2.085, DMD `-transition` was used for all language flags
// These are kept for backwards compatibility, but no longer documented
if (isdigit(cast(char)p[len]))
{
uint num;
if (!num.parseDigits(p.toDString()[len .. $]))
goto Lerror;
// Bugzilla issue number
switch (num)
{
case 3449:
params.vfield = true;
break;
case 14_246:
params.dtorFields = FeatureState.enabled;
break;
case 14_488:
break;
case 16_997:
deprecation(Loc.initial, "`-transition=16997` is now the default behavior");
break;
default:
error("transition `%s` is invalid", p);
params.transitionUsage = true;
return false;
}
}
else if (Identifier.isValidIdentifier(p + len))
{
const ident = p + len;
switch (ident.toDString())
{
case "dtorfields":
params.dtorFields = FeatureState.enabled;
break;
case "intpromote":
deprecation(Loc.initial, "`-transition=intpromote` is now the default behavior");
break;
default:
error("transition `%s` is invalid", p);
params.transitionUsage = true;
return false;
}
}
errorInvalidSwitch(p);
params.transitionUsage = true;
return false;
}
}
else if (startsWith(p + 1, "preview") ) // https://dlang.org/dmd.html#switch-preview
{
enum len = "-preview=".length;
// Parse:
// -preview=name
mixin(checkOptionsMixin("previewUsage",
"`-preview=<name>` requires a name"));
if (!parseCLIOption!("preview", Usage.previews)(params, arg))
{
error("preview `%s` is invalid", p);
params.previewUsage = true;
return false;
}
if (params.useDIP1021)
params.useDIP1000 = FeatureState.enabled; // dip1021 implies dip1000
// copy previously standalone flags from -transition
// -preview=dip1000 implies -preview=dip25 too
if (params.useDIP1000 == FeatureState.enabled)
params.useDIP25 = FeatureState.enabled;
}
else if (startsWith(p + 1, "revert") ) // https://dlang.org/dmd.html#switch-revert
{
enum len = "-revert=".length;
// Parse:
// -revert=name
mixin(checkOptionsMixin("revertUsage",
"`-revert=<name>` requires a name"));
if (!parseCLIOption!("revert", Usage.reverts)(params, arg))
{
error("revert `%s` is invalid", p);
params.revertUsage = true;
return false;
}
}
else if (arg == "-w") // https://dlang.org/dmd.html#switch-w
params.warnings = DiagnosticReporting.error;
else if (arg == "-wi") // https://dlang.org/dmd.html#switch-wi
params.warnings = DiagnosticReporting.inform;
else if (arg == "-O") // https://dlang.org/dmd.html#switch-O
driverParams.optimize = true;
else if (arg == "-o-") // https://dlang.org/dmd.html#switch-o-
params.obj = false;
else if (p[1] == 'o')
{
const(char)* path;
switch (p[2])
{
case 'd': // https://dlang.org/dmd.html#switch-od
if (!p[3])
goto Lnoarg;
path = p + 3 + (p[3] == '=');
version (Windows)
{
path = toWinPath(path);
}
params.objdir = path.toDString;
break;
case 'f': // https://dlang.org/dmd.html#switch-of
if (!p[3])
goto Lnoarg;
path = p + 3 + (p[3] == '=');
version (Windows)
{
path = toWinPath(path);
}
params.objname = path.toDString;
break;
case 'p': // https://dlang.org/dmd.html#switch-op
if (p[3])
goto Lerror;
params.preservePaths = true;
break;
case 0:
error("-o no longer supported, use -of or -od");
break;
default:
goto Lerror;
}
}
else if (p[1] == 'D') // https://dlang.org/dmd.html#switch-D
{
params.ddoc.doOutput = true;
switch (p[2])
{
case 'd': // https://dlang.org/dmd.html#switch-Dd
if (!p[3])
goto Lnoarg;
params.ddoc.dir = (p + 3 + (p[3] == '=')).toDString();
break;
case 'f': // https://dlang.org/dmd.html#switch-Df
if (!p[3])
goto Lnoarg;
params.ddoc.name = (p + 3 + (p[3] == '=')).toDString();
break;
case 0:
break;
default:
goto Lerror;
}
}
else if (p[1] == 'H' && p[2] == 'C') // https://dlang.org/dmd.html#switch-HC
{
params.cxxhdr.doOutput = true;
switch (p[3])
{
case 'd': // https://dlang.org/dmd.html#switch-HCd
if (!p[4])
goto Lnoarg;
params.cxxhdr.dir = (p + 4 + (p[4] == '=')).toDString;
break;
case 'f': // https://dlang.org/dmd.html#switch-HCf
if (!p[4])
goto Lnoarg;
params.cxxhdr.name = (p + 4 + (p[4] == '=')).toDString;
break;
case '=':
enum len = "-HC=".length;
mixin(checkOptionsMixin("hcUsage", "`-HC=<mode>` requires a valid mode"));
const mode = arg[len .. $];
switch (mode)
{
case "silent":
/* already set above */
break;
case "verbose":
params.cxxhdr.fullOutput = true;
break;
default:
errorInvalidSwitch(p);
params.hcUsage = true;
return false;
}
break;
case 0:
break;
default:
goto Lerror;
}
}
else if (p[1] == 'H') // https://dlang.org/dmd.html#switch-H
{
params.dihdr.doOutput = true;
switch (p[2])
{
case 'd': // https://dlang.org/dmd.html#switch-Hd
if (!p[3])
goto Lnoarg;
params.dihdr.dir = (p + 3 + (p[3] == '=')).toDString;
break;
case 'f': // https://dlang.org/dmd.html#switch-Hf
if (!p[3])
goto Lnoarg;
params.dihdr.name = (p + 3 + (p[3] == '=')).toDString;
break;
case 0:
break;
default:
goto Lerror;
}
}
else if (startsWith(p + 1, "Xcc="))
{
params.linkswitches.push(p + 5);
params.linkswitchIsForCC.push(true);
}
else if (p[1] == 'X') // https://dlang.org/dmd.html#switch-X
{
params.json.doOutput = true;
switch (p[2])
{
case 'f': // https://dlang.org/dmd.html#switch-Xf
if (!p[3])
goto Lnoarg;
params.json.name = (p + 3 + (p[3] == '=')).toDString;
break;
case 'i':
if (!p[3])
goto Lnoarg;
if (p[3] != '=')
goto Lerror;
if (!p[4])
goto Lnoarg;
{
auto flag = tryParseJsonField(p + 4);
if (!flag)
{
error("unknown JSON field `-Xi=%s`, expected one of " ~ jsonFieldNames, p + 4);
continue;
}
global.params.jsonFieldFlags |= flag;
}
break;
case 0:
break;
default:
goto Lerror;
}
}
else if (arg == "-ignore") // https://dlang.org/dmd.html#switch-ignore
params.ignoreUnsupportedPragmas = true;
else if (arg == "-inline") // https://dlang.org/dmd.html#switch-inline
{
params.useInline = true;
params.dihdr.fullOutput = true;
}
else if (arg == "-i")
includeImports = true;
else if (startsWith(p + 1, "i="))
{
includeImports = true;
if (!p[3])
{
error("invalid option '%s', module patterns cannot be empty", p);
}
else
{
// NOTE: we could check that the argument only contains valid "module-pattern" characters.
// Invalid characters doesn't break anything but an error message to the user might
// be nice.
includeModulePatterns.push(p + 3);
}
}
else if (arg == "-dip25") // https://dlang.org/dmd.html#switch-dip25
{
// @@@ DEPRECATION 2.112 @@@
deprecation(Loc.initial, "`-dip25` no longer has any effect");
params.useDIP25 = FeatureState.enabled;
}
else if (arg == "-dip1000")
{
params.useDIP25 = FeatureState.enabled;
params.useDIP1000 = FeatureState.enabled;
}
else if (arg == "-dip1008")
{
params.ehnogc = true;
}
else if (arg == "-lib") // https://dlang.org/dmd.html#switch-lib
driverParams.lib = true;
else if (arg == "-nofloat")
driverParams.nofloat = true;
else if (arg == "-quiet")
{
// Ignore
}
else if (arg == "-release") // https://dlang.org/dmd.html#switch-release
params.release = true;
else if (arg == "-betterC") // https://dlang.org/dmd.html#switch-betterC
params.betterC = true;
else if (arg == "-noboundscheck") // https://dlang.org/dmd.html#switch-noboundscheck
{
params.boundscheck = CHECKENABLE.off;
}
else if (startsWith(p + 1, "boundscheck")) // https://dlang.org/dmd.html#switch-boundscheck
{
// Parse:
// -boundscheck=[on|safeonly|off]
if (p[12] == '=')
{
const(char)[] boundscheck = arg[13 .. $];
switch (boundscheck)
{
case "on":
params.boundscheck = CHECKENABLE.on;
break;
case "safeonly":
params.boundscheck = CHECKENABLE.safeonly;
break;
case "off":
params.boundscheck = CHECKENABLE.off;
break;
default:
goto Lerror;
}
}
else
goto Lerror;
}
else if (arg == "-unittest")
params.useUnitTests = true;
else if (p[1] == 'I') // https://dlang.org/dmd.html#switch-I
{
if (!params.imppath)
params.imppath = new Strings();
params.imppath.push(p + 2 + (p[2] == '='));
}
else if (p[1] == 'm' && p[2] == 'v' && p[3] == '=') // https://dlang.org/dmd.html#switch-mv
{
if (p[4] && strchr(p + 5, '='))
{
params.modFileAliasStrings.push(p + 4);
}
else
goto Lerror;
}
else if (p[1] == 'J') // https://dlang.org/dmd.html#switch-J
{
if (!params.fileImppath)
params.fileImppath = new Strings();
params.fileImppath.push(p + 2 + (p[2] == '='));
}
else if (startsWith(p + 1, "debug") && p[6] != 'l') // https://dlang.org/dmd.html#switch-debug
{
// Parse:
// -debug
// -debug=number
// -debug=identifier
if (p[6] == '=')
{
if (isdigit(cast(char)p[7]))
{
if (!params.debuglevel.parseDigits(p.toDString()[7 .. $]))
goto Lerror;
// @@@DEPRECATED_2.111@@@
// Deprecated in 2.101, remove in 2.111
deprecation(Loc.initial, "`-debug=number` is deprecated, use debug identifiers instead");
}
else if (Identifier.isValidIdentifier(p + 7))
{
if (!params.debugids)
params.debugids = new Array!(const(char)*);
params.debugids.push(p + 7);
}
else
goto Lerror;
}
else if (p[6])
goto Lerror;
else
params.debuglevel = 1;
}
else if (startsWith(p + 1, "version")) // https://dlang.org/dmd.html#switch-version
{
// Parse:
// -version=number
// -version=identifier
if (p[8] == '=')
{
if (isdigit(cast(char)p[9]))
{
if (!params.versionlevel.parseDigits(p.toDString()[9 .. $]))
goto Lerror;
// @@@DEPRECATED_2.111@@@
// Deprecated in 2.101, remove in 2.111
deprecation(Loc.initial, "`-version=number` is deprecated, use version identifiers instead");
}
else if (Identifier.isValidIdentifier(p + 9))
{
if (!params.versionids)
params.versionids = new Array!(const(char)*);
params.versionids.push(p + 9);
}
else
goto Lerror;
}
else
goto Lerror;
}
else if (arg == "--b")
driverParams.debugb = true;
else if (arg == "--c")
driverParams.debugc = true;
else if (arg == "--f")
driverParams.debugf = true;
else if (arg == "--help" ||
arg == "-h")
{
params.usage = true;
return false;
}
else if (arg == "--r")
driverParams.debugr = true;
else if (arg == "--version")
{
params.logo = true;
return false;
}
else if (arg == "--x")
driverParams.debugx = true;
else if (arg == "--y")
driverParams.debugy = true;
else if (p[1] == 'L') // https://dlang.org/dmd.html#switch-L
{
params.linkswitches.push(p + 2 + (p[2] == '='));
params.linkswitchIsForCC.push(false);
}
else if (p[1] == 'P') // https://dlang.org/dmd.html#switch-P
{
params.cppswitches.push(p + 2 + (p[2] == '='));
}
else if (startsWith(p + 1, "defaultlib=")) // https://dlang.org/dmd.html#switch-defaultlib
{
driverParams.defaultlibname = (p + 1 + 11).toDString;
}
else if (startsWith(p + 1, "debuglib=")) // https://dlang.org/dmd.html#switch-debuglib
{
driverParams.debuglibname = (p + 1 + 9).toDString;
}
else if (startsWith(p + 1, "deps")) // https://dlang.org/dmd.html#switch-deps
{
if (params.moduleDeps.doOutput)
{
error("-deps[=file] can only be provided once!");
break;
}
if (p[5] == '=')
{
params.moduleDeps.name = (p + 1 + 5).toDString;
if (!params.moduleDeps.name[0])
goto Lnoarg;
}
else if (p[5] != '\0')
{
// Else output to stdout.
goto Lerror;
}
params.moduleDeps.buffer = new OutBuffer();
}
else if (startsWith(p + 1, "makedeps")) // https://dlang.org/dmd.html#switch-makedeps
{
if (params.makeDeps.name)
{
error("-makedeps[=file] can only be provided once!");
break;
}
if (p[9] == '=')
{
if (p[10] == '\0')
{
error("expected filename after -makedeps=");
break;
}
params.makeDeps.name = (p + 10).toDString;
}
else if (p[9] != '\0')
{
goto Lerror;
}
// Else output to stdout.
params.makeDeps.doOutput = true;
}
else if (arg == "-main") // https://dlang.org/dmd.html#switch-main
{
params.addMain = true;
}
else if (startsWith(p + 1, "man")) // https://dlang.org/dmd.html#switch-man
{
params.manual = true;
return false;
}
else if (arg == "-run") // https://dlang.org/dmd.html#switch-run
{
params.run = true;
size_t length = argc - i - 1;
if (length)
{
const(char)[] runarg = arguments[i + 1].toDString();
const(char)[] ext = FileName.ext(runarg);
if (ext &&
FileName.equals(ext, mars_ext) == 0 &&
FileName.equals(ext, hdr_ext) == 0 &&
FileName.equals(ext, i_ext) == 0 &&
FileName.equals(ext, c_ext) == 0)
{
error("-run must be followed by a source file, not '%s'", arguments[i + 1]);
break;
}
if (runarg == "-")
files.push("__stdin.d");
else
files.push(arguments[i + 1]);
params.runargs.setDim(length - 1);
for (size_t j = 0; j < length - 1; ++j)
{
params.runargs[j] = arguments[i + 2 + j];
}
i += length;
}
else
{
params.run = false;
goto Lnoarg;
}
}
else if (p[1] == '\0')
files.push("__stdin.d");
else
{
Lerror:
error("unrecognized switch '%s'", arguments[i]);
continue;
Lnoarg:
error("argument expected for switch '%s'", arguments[i]);
continue;
}
}
return errors;
}
/***********************************************
* Adjust gathered command line switches and reconcile them.
* Params:
* params = switches gathered from command line,
* and update in place
* target = more switches from the command line,
* update in place
* numSrcFiles = number of source files
*/
version (NoMain) {} else
private void reconcileCommands(ref Param params, ref Target target)
{
if (target.os == Target.OS.OSX)
{
driverParams.pic = PIC.pic;
}
else if (target.os == Target.OS.Windows)
{
if (driverParams.pic)
error(Loc.initial, "`-fPIC` and `-fPIE` cannot be used when targetting windows");
if (driverParams.dwarf)
error(Loc.initial, "`-gdwarf` cannot be used when targetting windows");
}
else if (target.os == Target.OS.DragonFlyBSD)
{
if (!target.is64bit)
error(Loc.initial, "`-m32` is not supported on DragonFlyBSD, it is 64-bit only");
}
if (target.os & (Target.OS.linux | Target.OS.FreeBSD | Target.OS.OpenBSD | Target.OS.Solaris | Target.OS.DragonFlyBSD))
{
if (driverParams.lib && driverParams.dll)
error(Loc.initial, "cannot mix `-lib` and `-shared`");
}
if (target.os == Target.OS.Windows)
{
foreach(b; params.linkswitchIsForCC[])
{
if (b)
{
// Linking code is guarded by version (Posix):
error(Loc.initial, "`Xcc=` link switches not available for this operating system");
break;
}
}
}
else
{
if (target.omfobj)
error(Loc.initial, "`-m32omf` can only be used when targetting windows");
if (driverParams.mscrtlib)
error(Loc.initial, "`-mscrtlib` can only be used when targetting windows");
}
if (params.boundscheck != CHECKENABLE._default)
{
if (params.useArrayBounds == CHECKENABLE._default)
params.useArrayBounds = params.boundscheck;
}
if (params.useUnitTests)
{
if (params.useAssert == CHECKENABLE._default)
params.useAssert = CHECKENABLE.on;
}
if (params.release)
{
if (params.useInvariants == CHECKENABLE._default)
params.useInvariants = CHECKENABLE.off;
if (params.useIn == CHECKENABLE._default)
params.useIn = CHECKENABLE.off;
if (params.useOut == CHECKENABLE._default)
params.useOut = CHECKENABLE.off;
if (params.useArrayBounds == CHECKENABLE._default)
params.useArrayBounds = CHECKENABLE.safeonly;
if (params.useAssert == CHECKENABLE._default)
params.useAssert = CHECKENABLE.off;
if (params.useSwitchError == CHECKENABLE._default)
params.useSwitchError = CHECKENABLE.off;
}
else
{
if (params.useInvariants == CHECKENABLE._default)
params.useInvariants = CHECKENABLE.on;
if (params.useIn == CHECKENABLE._default)
params.useIn = CHECKENABLE.on;
if (params.useOut == CHECKENABLE._default)
params.useOut = CHECKENABLE.on;
if (params.useArrayBounds == CHECKENABLE._default)
params.useArrayBounds = CHECKENABLE.on;
if (params.useAssert == CHECKENABLE._default)
params.useAssert = CHECKENABLE.on;
if (params.useSwitchError == CHECKENABLE._default)
params.useSwitchError = CHECKENABLE.on;
}
if (params.betterC)
{
if (params.checkAction != CHECKACTION.halt)
params.checkAction = CHECKACTION.C;
params.useModuleInfo = false;
params.useTypeInfo = false;
params.useExceptions = false;
}
}
/***********************************************
* Adjust link, run and lib line switches and reconcile them.
* Params:
* params = switches gathered from command line,
* and update in place
* numSrcFiles = number of source files
* obj_ext = object file extension
*/
version (NoMain) {} else
private void reconcileLinkRunLib(ref Param params, size_t numSrcFiles, const char[] obj_ext)
{
if (!params.obj || driverParams.lib)
driverParams.link = false;
if (target.os == Target.OS.Windows)
{
if (!driverParams.mscrtlib)
{
version (Windows)
{
VSOptions vsopt;
vsopt.initialize();
driverParams.mscrtlib = vsopt.defaultRuntimeLibrary(target.is64bit).toDString;
}
else
{
if (driverParams.link)
error(Loc.initial, "must supply `-mscrtlib` manually when cross compiling to windows");
}
}
}
if (driverParams.link)
{
params.exefile = params.objname;
driverParams.oneobj = true;
if (params.objname)
{
/* Use this to name the one object file with the same
* name as the exe file.
*/
params.objname = FileName.forceExt(params.objname, obj_ext);
/* If output directory is given, use that path rather than
* the exe file path.
*/
if (params.objdir)
{
const(char)[] name = FileName.name(params.objname);
params.objname = FileName.combine(params.objdir, name);
}
}
}
else if (params.run)
{
error(Loc.initial, "flags conflict with -run");
fatal();
}
else if (driverParams.lib)
{
params.libname = params.objname;
params.objname = null;
// Haven't investigated handling these options with multiobj
if (!params.cov && !params.trace)
params.multiobj = true;
}
else
{
if (params.objname && numSrcFiles)
{
driverParams.oneobj = true;
//error("multiple source files, but only one .obj name");
//fatal();
}
}
}
/// Sets the boolean for a flag with the given name
private static void setFlagFor(string name, ref bool b)
{
b = name != "revert";
}
/// Sets the FeatureState for a flag with the given name
private static void setFlagFor(string name, ref FeatureState s)
{
s = name != "revert" ? FeatureState.enabled : FeatureState.disabled;
}
/**
Creates the module based on the file provided
The file is dispatched in one of the various arrays
(global.params.{ddoc.files,dllfiles,jsonfiles,etc...})
according to its extension.
If it is a binary file, it is added to libmodules.
Params:
file = File name to dispatch
libmodules = Array to which binaries (shared/static libs and object files)
will be appended
target = target system
Returns:
A D module
*/
private
Module createModule(const(char)* file, ref Strings libmodules, const ref Target target)
{
const(char)[] name;
version (Windows)
{
file = toWinPath(file);
}
const(char)[] p = file.toDString();
p = FileName.name(p); // strip path
const(char)[] ext = FileName.ext(p);
if (!ext)
{
if (!p.length)
{
error(Loc.initial, "invalid file name '%s'", file);
fatal();
}
auto id = Identifier.idPool(p);
return new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
}
/* Deduce what to do with a file based on its extension
*/
if (FileName.equals(ext, target.obj_ext))
{
global.params.objfiles.push(file);
libmodules.push(file);
return null;
}
if (FileName.equals(ext, target.lib_ext))
{
global.params.libfiles.push(file);
libmodules.push(file);
return null;
}
if (target.os & (Target.OS.linux | Target.OS.OSX| Target.OS.FreeBSD | Target.OS.OpenBSD | Target.OS.Solaris | Target.OS.DragonFlyBSD))
{
if (FileName.equals(ext, target.dll_ext))
{
global.params.dllfiles.push(file);
libmodules.push(file);
return null;
}
}
if (FileName.equals(ext, ddoc_ext))
{
global.params.ddoc.files.push(file);
return null;
}
if (FileName.equals(ext, json_ext))
{
global.params.json.doOutput = true;
global.params.json.name = file.toDString;
return null;
}
if (FileName.equals(ext, map_ext))
{
global.params.mapfile = file.toDString;
return null;
}
if (target.os == Target.OS.Windows)
{
if (FileName.equals(ext, "res"))
{
global.params.resfile = file.toDString;
return null;
}
if (FileName.equals(ext, "def"))
{
global.params.deffile = file.toDString;
return null;
}
if (FileName.equals(ext, "exe"))
{
assert(0); // should have already been handled
}
}
/* Examine extension to see if it is a valid
* D, Ddoc or C source file extension
*/
if (FileName.equals(ext, mars_ext) ||
FileName.equals(ext, hdr_ext ) ||
FileName.equals(ext, dd_ext ) ||
FileName.equals(ext, c_ext ) ||
FileName.equals(ext, i_ext ))
{
name = FileName.removeExt(p);
if (!name.length || name == ".." || name == ".")
{
error(Loc.initial, "invalid file name '%s'", file);
fatal();
}
}
else
{
error(Loc.initial, "unrecognized file extension %.*s", cast(int)ext.length, ext.ptr);
fatal();
}
/* At this point, name is the D source file name stripped of
* its path and extension.
*/
auto id = Identifier.idPool(name);
return new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
}
/**
Creates the list of modules based on the files provided
Files are dispatched in the various arrays
(global.params.{ddocfiles,dllfiles,jsonfiles,etc...})
according to their extension.
Binary files are added to libmodules.
Params:
files = File names to dispatch
libmodules = Array to which binaries (shared/static libs and object files)
will be appended
target = target system
Returns:
An array of path to D modules
*/
private
Modules createModules(ref Strings files, ref Strings libmodules, const ref Target target)
{
Modules modules;
modules.reserve(files.length);
bool firstmodule = true;
foreach(file; files)
{
auto m = createModule(file, libmodules, target);
if (m is null)
continue;
modules.push(m);
if (firstmodule)
{
global.params.objfiles.push(m.objfile.toChars());
firstmodule = false;
}
}
return modules;
}
/// Returns: a compiled module (semantic3) containing an empty main() function, for the -main flag
Module moduleWithEmptyMain()
{
auto result = new Module("__main.d", Identifier.idPool("__main"), false, false);
// need 2 trailing nulls for sentinel and 2 for lexer
auto data = arraydup("version(D_BetterC)extern(C)int main(){return 0;}else int main(){return 0;}\0\0\0\0");
result.src = cast(ubyte[]) data[0 .. $-4];
result.parse();
result.importedFrom = result;
result.importAll(null);
result.dsymbolSemantic(null);
result.semantic2(null);
result.semantic3(null);
return result;
}
| D |
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (c) 1999-2017 by Digital Mars, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(DMDSRC _target.d)
*/
module ddmd.target;
import ddmd.dmodule;
import ddmd.expression;
import ddmd.globals;
import ddmd.identifier;
import ddmd.mtype;
import ddmd.root.ctfloat;
import ddmd.root.outbuffer;
/***********************************************************
*/
struct Target
{
extern (C++) static __gshared int ptrsize;
extern (C++) static __gshared int realsize; // size a real consumes in memory
extern (C++) static __gshared int realpad; // 'padding' added to the CPU real size to bring it up to realsize
extern (C++) static __gshared int realalignsize; // alignment for reals
extern (C++) static __gshared bool realislongdouble; // distinguish between C 'long double' and '__float128'
extern (C++) static __gshared bool reverseCppOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order
extern (C++) static __gshared bool cppExceptions; // set if catching C++ exceptions is supported
extern (C++) static __gshared int c_longsize; // size of a C 'long' or 'unsigned long' type
extern (C++) static __gshared int c_long_doublesize; // size of a C 'long double'
extern (C++) static __gshared int classinfosize; // size of 'ClassInfo'
extern (C++) static __gshared ulong maxStaticDataSize; // maximum size of static data
template FPTypeProperties(T)
{
enum : real_t
{
max = T.max,
min_normal = T.min_normal,
nan = T.nan,
snan = T.init,
infinity = T.infinity,
epsilon = T.epsilon
}
enum : long
{
dig = T.dig,
mant_dig = T.mant_dig,
max_exp = T.max_exp,
min_exp = T.min_exp,
max_10_exp = T.max_10_exp,
min_10_exp = T.min_10_exp
}
}
alias FloatProperties = FPTypeProperties!float;
alias DoubleProperties = FPTypeProperties!double;
alias RealProperties = FPTypeProperties!real;
extern (C++) static void _init()
{
// These have default values for 32 bit code, they get
// adjusted for 64 bit code.
ptrsize = 4;
classinfosize = 0x4C; // 76
/* gcc uses int.max for 32 bit compilations, and long.max for 64 bit ones.
* Set to int.max for both, because the rest of the compiler cannot handle
* 2^64-1 without some pervasive rework. The trouble is that much of the
* front and back end uses 32 bit ints for sizes and offsets. Since C++
* silently truncates 64 bit ints to 32, finding all these dependencies will be a problem.
*/
maxStaticDataSize = int.max;
if (global.params.isLP64)
{
ptrsize = 8;
classinfosize = 0x98; // 152
}
if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isSolaris)
{
realsize = 12;
realpad = 2;
realalignsize = 4;
c_longsize = 4;
}
else if (global.params.isOSX)
{
realsize = 16;
realpad = 6;
realalignsize = 16;
c_longsize = 4;
}
else if (global.params.isWindows)
{
realsize = 10;
realpad = 0;
realalignsize = 2;
reverseCppOverloads = true;
c_longsize = 4;
if (ptrsize == 4)
{
/* Optlink cannot deal with individual data chunks
* larger than 16Mb
*/
maxStaticDataSize = 0x100_0000; // 16Mb
}
}
else
assert(0);
if (global.params.is64bit)
{
if (global.params.isLinux || global.params.isFreeBSD || global.params.isSolaris)
{
realsize = 16;
realpad = 6;
realalignsize = 16;
c_longsize = 8;
}
else if (global.params.isOSX)
{
c_longsize = 8;
}
}
realislongdouble = true;
c_long_doublesize = realsize;
if (global.params.is64bit && global.params.isWindows)
c_long_doublesize = 8;
cppExceptions = global.params.isLinux || global.params.isFreeBSD ||
global.params.isOSX;
}
/******************************
* Return memory alignment size of type.
*/
extern (C++) static uint alignsize(Type type)
{
assert(type.isTypeBasic());
switch (type.ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
return Target.realalignsize;
case Tcomplex32:
if (global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isSolaris)
return 4;
break;
case Tint64:
case Tuns64:
case Tfloat64:
case Timaginary64:
case Tcomplex64:
if (global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isSolaris)
return global.params.is64bit ? 8 : 4;
break;
default:
break;
}
return cast(uint)type.size(Loc());
}
/******************************
* Return field alignment size of type.
*/
extern (C++) static uint fieldalign(Type type)
{
const size = type.alignsize();
if ((global.params.is64bit || global.params.isOSX) && (size == 16 || size == 32))
return size;
return (8 < size) ? 8 : size;
}
/***********************************
* Return size of OS critical section.
* NOTE: can't use the sizeof() calls directly since cross compiling is
* supported and would end up using the host sizes rather than the target
* sizes.
*/
extern (C++) static uint critsecsize()
{
if (global.params.isWindows)
{
// sizeof(CRITICAL_SECTION) for Windows.
return global.params.isLP64 ? 40 : 24;
}
else if (global.params.isLinux)
{
// sizeof(pthread_mutex_t) for Linux.
if (global.params.is64bit)
return global.params.isLP64 ? 40 : 32;
else
return global.params.isLP64 ? 40 : 24;
}
else if (global.params.isFreeBSD)
{
// sizeof(pthread_mutex_t) for FreeBSD.
return global.params.isLP64 ? 8 : 4;
}
else if (global.params.isOpenBSD)
{
// sizeof(pthread_mutex_t) for OpenBSD.
return global.params.isLP64 ? 8 : 4;
}
else if (global.params.isOSX)
{
// sizeof(pthread_mutex_t) for OSX.
return global.params.isLP64 ? 64 : 44;
}
else if (global.params.isSolaris)
{
// sizeof(pthread_mutex_t) for Solaris.
return 24;
}
assert(0);
}
/***********************************
* Returns a Type for the va_list type of the target.
* NOTE: For Posix/x86_64 this returns the type which will really
* be used for passing an argument of type va_list.
*/
extern (C++) static Type va_listType()
{
if (global.params.isWindows)
{
return Type.tchar.pointerTo();
}
else if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isSolaris || global.params.isOSX)
{
if (global.params.is64bit)
{
return (new TypeIdentifier(Loc(), Identifier.idPool("__va_list_tag"))).pointerTo();
}
else
{
return Type.tchar.pointerTo();
}
}
else
{
assert(0);
}
}
/**
* Checks whether the target supports a vector type with total size `sz`
* (in bytes) and element type `type`.
*
* Returns: 0 if the type is supported, or else: 1 if vector types are not
* supported on the target at all, 2 if the given size isn't, or 3 if
* the element type isn't.
*/
extern (C++) static int checkVectorType(int sz, Type type)
{
if (!global.params.is64bit && !global.params.isOSX)
return 1; // not supported
if (sz != 16 && sz != 32)
return 2; // wrong size
switch (type.ty)
{
case Tvoid:
case Tint8:
case Tuns8:
case Tint16:
case Tuns16:
case Tint32:
case Tuns32:
case Tfloat32:
case Tint64:
case Tuns64:
case Tfloat64:
break;
default:
return 3; // wrong base type
}
return 0;
}
/******************************
* Encode the given expression, which is assumed to be an rvalue literal
* as another type for use in CTFE.
* This corresponds roughly to the idiom *(Type *)&e.
*/
extern (C++) static Expression paintAsType(Expression e, Type type)
{
// We support up to 512-bit values.
ubyte[64] buffer;
assert(e.type.size() == type.size());
// Write the expression into the buffer.
switch (e.type.ty)
{
case Tint32:
case Tuns32:
case Tint64:
case Tuns64:
encodeInteger(e, buffer.ptr);
break;
case Tfloat32:
case Tfloat64:
encodeReal(e, buffer.ptr);
break;
default:
assert(0);
}
// Interpret the buffer as a new type.
switch (type.ty)
{
case Tint32:
case Tuns32:
case Tint64:
case Tuns64:
return decodeInteger(e.loc, type, buffer.ptr);
case Tfloat32:
case Tfloat64:
return decodeReal(e.loc, type, buffer.ptr);
default:
assert(0);
}
}
/******************************
* For the given module, perform any post parsing analysis.
* Certain compiler backends (ie: GDC) have special placeholder
* modules whose source are empty, but code gets injected
* immediately after loading.
*/
extern (C++) static void loadModule(Module m)
{
}
/******************************
* For the given symbol written to the OutBuffer, apply any
* target-specific prefixes based on the given linkage.
*/
extern (C++) static void prefixName(OutBuffer* buf, LINK linkage)
{
switch (linkage)
{
case LINKcpp:
if (global.params.isOSX)
buf.prependbyte('_');
break;
default:
break;
}
}
}
/******************************
* Private helpers for Target::paintAsType.
*/
// Write the integer value of 'e' into a unsigned byte buffer.
extern (C++) static void encodeInteger(Expression e, ubyte* buffer)
{
dinteger_t value = e.toInteger();
int size = cast(int)e.type.size();
for (int p = 0; p < size; p++)
{
int offset = p; // Would be (size - 1) - p; on BigEndian
buffer[offset] = ((value >> (p * 8)) & 0xFF);
}
}
// Write the bytes encoded in 'buffer' into an integer and returns
// the value as a new IntegerExp.
extern (C++) static Expression decodeInteger(Loc loc, Type type, ubyte* buffer)
{
dinteger_t value = 0;
int size = cast(int)type.size();
for (int p = 0; p < size; p++)
{
int offset = p; // Would be (size - 1) - p; on BigEndian
value |= (cast(dinteger_t)buffer[offset] << (p * 8));
}
return new IntegerExp(loc, value, type);
}
// Write the real_t value of 'e' into a unsigned byte buffer.
extern (C++) static void encodeReal(Expression e, ubyte* buffer)
{
switch (e.type.ty)
{
case Tfloat32:
{
float* p = cast(float*)buffer;
*p = cast(float)e.toReal();
break;
}
case Tfloat64:
{
double* p = cast(double*)buffer;
*p = cast(double)e.toReal();
break;
}
default:
assert(0);
}
}
// Write the bytes encoded in 'buffer' into a real_t and returns
// the value as a new RealExp.
extern (C++) static Expression decodeReal(Loc loc, Type type, ubyte* buffer)
{
real_t value;
switch (type.ty)
{
case Tfloat32:
{
float* p = cast(float*)buffer;
value = real_t(*p);
break;
}
case Tfloat64:
{
double* p = cast(double*)buffer;
value = real_t(*p);
break;
}
default:
assert(0);
}
return new RealExp(loc, value, type);
}
| D |
/++
A module containing the LandingReporter
This is an example of how this reporter looks
<script type="text/javascript" src="https://asciinema.org/a/ar2qel0uzunpjmfzkg7xtvsa1.js" id="asciicast-ar2qel0uzunpjmfzkg7xtvsa1" async></script>
Copyright: © 2017 Szabo Bogdan
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Szabo Bogdan
+/
module trial.reporters.landing;
import std.stdio;
import std.array;
import std.conv;
import std.datetime;
import std.string;
import std.algorithm;
import trial.interfaces;
import trial.reporters.writer;
/// The Landing Strip (landing) reporter is a gimmicky test reporter simulating a plane landing unicode ftw
class LandingReporter : ITestCaseLifecycleListener, ILifecycleListener
{
private
{
ReportWriter writer;
const
{
string plane = "✈";
string margin = "━";
string lane = "⋅";
}
ulong testCount;
ulong currentTest;
bool success = true;
}
this()
{
writer = defaultWriter;
}
this(ReportWriter writer)
{
this.writer = writer;
}
void begin(ulong testCount)
{
this.testCount = testCount;
writer.writeln("\n\n");
drawLane;
}
void update()
{
}
void end(SuiteResult[])
{
}
void begin(string suite, ref TestResult test)
{
}
void end(string suite, ref TestResult test)
{
currentTest++;
success = success && test.status == TestResult.Status.success;
drawLane;
}
private void drawLane()
{
size_t size = (writer.width / 4) * 3;
size_t position = ((cast(double) currentTest / cast(double) testCount) * size).to!size_t;
writer.goTo(3);
writer.writeln(margin.replicate(size), ReportWriter.Context.inactive);
if (currentTest < testCount)
{
writer.write(lane.replicate(position), ReportWriter.Context.inactive);
writer.write(plane, success ? ReportWriter.Context.active : ReportWriter.Context.danger);
writer.writeln(lane.replicate(size - position - 1), ReportWriter.Context.inactive);
}
else
{
writer.write(lane.replicate(size), ReportWriter.Context.inactive);
writer.writeln(plane, success ? ReportWriter.Context.active : ReportWriter.Context.danger);
}
writer.writeln(margin.replicate(size), ReportWriter.Context.inactive);
}
}
version (unittest)
{
import fluent.asserts;
}
@("it should print 10 success tests")
unittest
{
auto writer = new BufferedWriter;
auto reporter = new LandingReporter(writer);
auto suite = SuiteResult("some suite");
auto test = new TestResult("some test");
test.status = TestResult.Status.success;
reporter.begin(10);
writer.buffer.should.equal("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" ~ "✈⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅\n" ~ "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
auto position = [18, 36, 54, 72, 90, 108, 126, 144, 162, 180];
foreach (i; 0 .. 10)
{
reporter.begin("some suite", test);
reporter.end("some suite", test);
auto lines = writer.buffer.split("\n");
lines.length.should.equal(4);
lines[1].indexOf("✈").should.equal(position[i]);
}
}
| D |
module mir.pybind;
/** CODING GUIDE
D or Python:
When we can implement something both in D or Python, we do everything in D.
D has less overhead than Python (the reason why we use D from Python).
Error Handling:
D function should raise exception for python by PyErr_SetString(PyObject* type, const char* message)
The type can be PyExc_RuntimeError, PyExc_TypeError, etc
see also https://docs.python.org/3/c-api/exceptions.html#standard-exceptions
*/
private import deimos.python.Python : PyMethodDef, METH_VARARGS;
private import mir.pybind.conv : toPyFunction;
/// template to define python function (wrapper of PyMethodDef)
/// TODO insert type signature and args in docstring automatically
enum def(alias dfunc, string doc = "", string name = __traits(identifier, dfunc))
= PyMethodDef(name, &toPyFunction!dfunc, METH_VARARGS, doc);
/// template to define python module (wrapper of PyModuleDef)
mixin template defModule(string modName, string modDoc, PyMethodDef[] defs)
{
private import deimos.python.Python : PyModuleDef, PyModuleDef_Base, PyMethodDef;
private import std.string : replace;
extern (C):
enum PyModuleDef_Base PyModuleDef_HEAD_INIT = {{1, null}, null, 0, null};
enum PyMethodDef PyMethodDef_SENTINEL = {null, null, 0, null};
alias exitFunc = extern(C) void function();
enum exitFunc rtAtExit = ()
{
import core.runtime : rt_term;
rt_term();
};
extern(D) static PyModuleDef mod = {PyModuleDef_HEAD_INIT, m_name: modName, m_doc: modDoc, m_size: -1};
extern(D) static methods = defs ~ [PyMethodDef_SENTINEL];
mixin(
q{
pragma(mangle, __traits(identifier, PyInit_$))
auto PyInit_$()
{
import deimos.python.Python : Py_AtExit, PyModule_Create;
import core.runtime : rt_init;
rt_init();
Py_AtExit(rtAtExit);
mod.m_methods = methods.ptr;
// TODO import_array(); // enable numpy API
return PyModule_Create(&mod);
}
}.replace("$", modName));
}
| D |
/home/ukasha/Desktop/Quarter-1_3.30-6.30/week_10_29th-September,2019/part4/part6/target/debug/part6: /home/ukasha/Desktop/Quarter-1_3.30-6.30/week_10_29th-September,2019/part4/part6/src/main.rs
| D |
module ast.properties;
import ast.base, ast.parse, ast.casting, ast.tuples: AstTuple = Tuple;
TLS!(PropArgs) propcfg;
static this() { New(propcfg); }
TLS!(char*) rawmode_loc;
static this() { New(rawmode_loc); }
bool rawmode(string s) {
return s.ptr == *rawmode_loc.ptr();
}
// placed here to break import cycle
import ast.vardecl;
Object gotLVize(ref string text, ParseCb cont, ParseCb rest) {
Expr ex;
auto t2 = text;
// behaves like a fun call
auto backup = *propcfg.ptr();
scope(exit) *propcfg.ptr() = backup;
propcfg.ptr().withTuple = false;
if (!rest(t2, "tree.expr _tree.expr.bin"[], &ex))
t2.failparse("Expected expression for lvize"[]);
text = t2;
return fastcast!(Object) (lvize(ex));
}
mixin DefaultParser!(gotLVize, "tree.expr.lvize"[], "24071"[], "lvize"[]);
| D |
module runnable;
import std.stdio;
import std.string;
import std.conv;
import std.getopt;
import std.format;
string filename = "input.txt";
void main(string[] args)
{
//check command line arguments for filename (use input.txt if not specified)
auto info = getopt(args, "file", "Specify file that contains input data", &filename);
if (info.helpWanted)
{
defaultGetoptPrinter("This program solves Day 8 of Advent Of Code 2017", info.options);
return;
}
//get the file and iterator for each line
auto file = File(filename);
auto range = file.byLine();
//instantiate our registers that will store our values
Registers registers = new Registers();
//parse each line of the input into an instruction
//and execute that instruction on our registers
foreach (line; range)
{
Instruction instruction = Parser.GetInstruction(line.dup);
registers.Execute(instruction);
}
//get the current max value in the registers after executing all the lines
Register maxRegister = registers.GetMax();
writeln(format("Max (Value): %s", maxRegister.ToString()));
//get the max allocated register
Register maxAllocatedRegister = registers.GetMaxAllocated();
writeln(format("Max (Allocated): %s", maxAllocatedRegister.ToString()));
}
/+++++++++++++++++++++++++++++++++++++++
+ The Registers class contains all the
+ registers, keyed by their name.
+
+ Registers can be used to execute instructions,
+ which will update the registers accordingly.
+/
public class Registers
{
private static const int DEFAULT_VALUE = 0;
private Register[string] registers;
/*********************************
* Perform an instruction on the registers, updating them
*/
public void Execute(Instruction instruction)
{
//check if the condition is true
int conditionValue = this.Get(instruction.Condition.Key).Value;
bool condition = instruction.Condition.Execute(conditionValue);
if (condition)
{
Register current = this.Get(instruction.Operation.Key);
int newValue = instruction.Operation.Execute(current.Value);
this.Set(instruction.Operation.Key, newValue);
}
}
/*********************************
* Safely gets a register by key from the registers
*/
private Register Get(string key)
{
if (!this.registers.get(key, null))
{
this.Set(key, DEFAULT_VALUE);
}
return this.registers[key];
}
/*********************************
* Safely set a registerto value by key
* (without overwriting a register)
*/
private void Set(string key, int value)
{
//check if key doesnt have a register
if (!this.registers.get(key, null))
{
//instantiate the register since it doesnt exist
this.registers[key] = new Register(key, value);
}
else
{
//update the register's value since it already exists
this.registers[key].Update(value);
}
}
/*********************************
* Find the first register that currently has the highest value
*/
public Register GetMax()
{
immutable string firstKey = this.registers.keys[DEFAULT_VALUE];
Register maxRegister = this.registers[firstKey];
foreach (key; this.registers.byKey)
{
Register register = this.registers[key];
if (register.Value > maxRegister.Value)
{
maxRegister = register;
}
}
return maxRegister;
}
/*********************************
* Find the first register that has the highest allocation
*/
public Register GetMaxAllocated()
{
immutable string firstKey = this.registers.keys[DEFAULT_VALUE];
Register maxAllocatedRegister = this.registers[firstKey];
foreach (key; this.registers.byKey)
{
Register register = this.registers[key];
if (register.Allocated > maxAllocatedRegister.Allocated)
{
maxAllocatedRegister = register;
}
}
return maxAllocatedRegister;
}
}
/+++++++++++++++++++++++++++++++++++++++
+ The Register class contains information
+ about a register. Its name, current value,
+ and space allocated for it.
+
+ (Values require allocation, which the registers
+ do not free up when a lower value is introduced)
+/
public class Register
{
public immutable string Name;
public int Value;
public int Allocated;
public this(string name, int value)
{
this.Name = name;
this.Value = value;
this.Allocated = value;
}
/*********************************
* Update this register with a new value
*/
public void Update(int value)
{
this.Value = value;
//if the new value is higher than the registers allocation,
//increase the registers allocated memory
if (value > this.Allocated)
{
this.Allocated = value;
}
}
/*********************************
* Convert this Register into a human-readable string
*/
public string ToString()
{
return format("%s (Value = %d, Allocated = %d)", this.Name, this.Value, this.Allocated);
}
}
/+++++++++++++++++++++++++++++++++++++++
+ The Instruction class pairs an Operation with a condition.
+/
public class Instruction
{
public Operational Operation;
public Conditional Condition;
public this(Operational operation, Conditional condition)
{
this.Operation = operation;
this.Condition = condition;
}
}
/+++++++++++++++++++++++++++++++++++++++
+ The Operational class stores an operation that can be
+ executed on a given input.
+/
public class Operational
{
private static const string INCREMENT = "inc";
private static const string DECREMENT = "dec";
public immutable string Key;
public immutable int delegate(int value) Execute;
public this(string key, string operator, int value)
{
this.Key = key;
this.Execute = this.GetOperation(operator, value);
}
/*********************************
* Brute force function that creates a function
* based on such: '(int x) => x operator value'
* where operator is a relational operator (<, >, ==, etc)
*/
private int delegate(int) GetOperation(string operator, int value)
{
switch (operator)
{
case INCREMENT:
return (int x) => x + value;
case DECREMENT:
default:
return (int x) => x - value;
}
}
}
/+++++++++++++++++++++++++++++++++++++++
+ The Conditional class stores a condition
+ operator that evaluates a given input.
+/
public class Conditional
{
private static const string EQUIVALENT = "==";
private static const string NOT_EQUIVALENT = "!=";
private static const string GREATER = ">";
private static const string GREATER_OR_EQUAL = ">=";
private static const string LESSER = "<";
private static const string LESSER_OR_EQUAL = "<=";
public immutable string Key;
public immutable bool delegate(int value) Execute;
public this(string key, string operator, int value)
{
this.Key = key;
this.Execute = this.GetOperation(operator, value);
}
/*********************************
* Brute force function that creates a function
* based on such: '(int x) => x operator value'
* where operator is a relational operator (<, >, ==, etc)
*/
public bool delegate(int) GetOperation(string operator, int value)
{
switch (operator)
{
case EQUIVALENT:
return (int x) => x == value;
case NOT_EQUIVALENT:
return (int x) => x != value;
case GREATER:
return (int x) => x > value;
case GREATER_OR_EQUAL:
return (int x) => x >= value;
case LESSER:
return (int x) => x < value;
case LESSER_OR_EQUAL:
default:
return (int x) => x <= value;
}
}
}
/+++++++++++++++++++++++++++++++++++++++
+ The Parser class is used to parse the
+ input lines into instructions for the
+ the registers.
+/
public static class Parser
{
private static const int KEY_INDEX = 0;
private static const int OPERATOR_INDEX = 1;
private static const int VALUE_INDEX = 2;
private static const int OPERATION_INDEX = 0;
private static const int CONDITION_INDEX = 1;
private static const string SEPARATOR = " if ";
private static const string SPACE = " ";
/*********************************
* Parses input (like -> "xn dec -181 if cp >= -4748")
* into an instruction that can be executed on the registers.
*/
public static GetInstruction(string line)
{
string[] parts = line.split(SEPARATOR);
Operational operation = Parser.GetOperation(parts[OPERATION_INDEX]);
Conditional condition = Parser.GetCondition(parts[CONDITION_INDEX]);
return new Instruction(operation, condition);
}
/*********************************
* Parses operation input (like -> xn dec -181)
* into an operation that can be executed on a register
*/
private static Operational GetOperation(string operationLine)
{
string[] parts = operationLine.split(SPACE);
auto key = parts[KEY_INDEX];
auto operator = parts[OPERATOR_INDEX];
immutable int value = to!int(parts[VALUE_INDEX]);
return new Operational(key, operator, value);
}
/*********************************
* Parses condition input (like -> xcp >= -4748")
* into an operation that can be executed on a register
*/
private static Conditional GetCondition(string conditionLine)
{
string[] parts = conditionLine.split(SPACE);
auto key = parts[KEY_INDEX];
auto operator = parts[OPERATOR_INDEX];
immutable int value = to!int(parts[VALUE_INDEX]);
return new Conditional(key, operator, value);
}
}
| D |
/**
* D header file for C99.
*
* $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_stdint.h.html, _stdint.h)
*
* Copyright: Copyright Sean Kelly 2005 - 2018
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Sean Kelly
* Source: $(DRUNTIMESRC core/stdc/_stdint.d)
* Standards: ISO/IEC 9899:1999 (E)
*/
module core.stdc.stdint;
import core.stdc.config;
import core.stdc.stddef; // for wchar_t
import core.stdc.signal; // for sig_atomic_t
import core.stdc.wchar_; // for wint_t
version (OSX)
version = Darwin;
else version (iOS)
version = Darwin;
else version (TVOS)
version = Darwin;
else version (WatchOS)
version = Darwin;
// Can't be `private` because of @@@BUG11173@@@.
T _typify(T)(T val) @safe pure nothrow { return val; }
extern (C):
@trusted: // Types and constants only.
nothrow:
@nogc:
static if (is(ucent))
{
alias int128_t = cent; ///
alias uint128_t = ucent; ///
}
version (Windows)
{
alias int8_t = byte; ///
alias int16_t = short; ///
alias uint8_t = ubyte; ///
alias uint16_t = ushort; ///
version (CRuntime_DigitalMars)
{
alias int32_t = cpp_long; ///
alias uint32_t = cpp_ulong; ///
}
else
{
alias int32_t = int; ///
alias uint32_t = uint; ///
}
alias int64_t = long; ///
alias uint64_t = ulong; ///
alias int_least8_t = byte; ///
alias uint_least8_t = ubyte; ///
alias int_least16_t = short; ///
alias uint_least16_t = ushort; ///
alias int_least32_t = int32_t; ///
alias uint_least32_t = uint32_t; ///
alias int_least64_t = long; ///
alias uint_least64_t = ulong; ///
alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = int; ///
alias uint_fast16_t = uint; ///
alias int_fast32_t = int32_t; ///
alias uint_fast32_t = uint32_t; ///
alias int_fast64_t = long; ///
alias uint_fast64_t = ulong; ///
alias intptr_t = ptrdiff_t; ///
alias uintptr_t = size_t; ///
alias intmax_t = long; ///
alias uintmax_t = ulong; ///
}
else version (Darwin)
{
alias int8_t = byte; ///
alias int16_t = short; ///
alias uint8_t = ubyte; ///
alias uint16_t = ushort; ///
alias int32_t = int; ///
alias uint32_t = uint; ///
alias int64_t = cpp_longlong; ///
alias uint64_t = cpp_ulonglong; ///
alias int_least8_t = byte; ///
alias uint_least8_t = ubyte; ///
alias int_least16_t = short; ///
alias uint_least16_t = ushort; ///
alias int_least32_t = int; ///
alias uint_least32_t = uint; ///
alias int_least64_t = int64_t; ///
alias uint_least64_t = uint64_t; ///
alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = short; ///
alias uint_fast16_t = ushort; ///
alias int_fast32_t = int; ///
alias uint_fast32_t = uint; ///
alias int_fast64_t = int64_t; ///
alias uint_fast64_t = uint64_t; ///
alias intptr_t = cpp_long; ///
alias uintptr_t = cpp_ulong; ///
alias intmax_t = long; ///
alias uintmax_t = ulong; ///
}
else version (Posix)
{
alias int8_t = byte; ///
alias int16_t = short; ///
alias uint8_t = ubyte; ///
alias uint16_t = ushort; ///
alias int32_t = int; ///
alias uint32_t = uint; ///
alias int64_t = long; ///
alias uint64_t = ulong; ///
alias int_least8_t = byte; ///
alias uint_least8_t = ubyte; ///
alias int_least16_t = short; ///
alias uint_least16_t = ushort; ///
alias int_least32_t = int; ///
alias uint_least32_t = uint; ///
alias int_least64_t = long; ///
alias uint_least64_t = ulong; ///
version (FreeBSD)
{
alias int_fast8_t = int; ///
alias uint_fast8_t = uint; ///
alias int_fast16_t = int; ///
alias uint_fast16_t = uint; ///
alias int_fast32_t = int; ///
alias uint_fast32_t = uint; ///
}
else version (CRuntime_Musl)
{
alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = int; ///
alias uint_fast16_t = uint; ///
alias int_fast32_t = int; ///
alias uint_fast32_t = uint; ///
}
else
{
alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = ptrdiff_t; ///
alias uint_fast16_t = size_t; ///
alias int_fast32_t = ptrdiff_t; ///
alias uint_fast32_t = size_t; ///
}
alias int_fast64_t = long; ///
alias uint_fast64_t = ulong; ///
alias intptr_t = ptrdiff_t; ///
alias uintptr_t = size_t; ///
alias intmax_t = long; ///
alias uintmax_t = ulong; ///
}
else
{
static assert(0);
}
///
enum int8_t INT8_MIN = int8_t.min;
///
enum int8_t INT8_MAX = int8_t.max;
///
enum int16_t INT16_MIN = int16_t.min;
///
enum int16_t INT16_MAX = int16_t.max;
///
enum int32_t INT32_MIN = int32_t.min;
///
enum int32_t INT32_MAX = int32_t.max;
///
enum int64_t INT64_MIN = int64_t.min;
///
enum int64_t INT64_MAX = int64_t.max;
///
enum uint8_t UINT8_MAX = uint8_t.max;
///
enum uint16_t UINT16_MAX = uint16_t.max;
///
enum uint32_t UINT32_MAX = uint32_t.max;
///
enum uint64_t UINT64_MAX = uint64_t.max;
///
enum int_least8_t INT_LEAST8_MIN = int_least8_t.min;
///
enum int_least8_t INT_LEAST8_MAX = int_least8_t.max;
///
enum int_least16_t INT_LEAST16_MIN = int_least16_t.min;
///
enum int_least16_t INT_LEAST16_MAX = int_least16_t.max;
///
enum int_least32_t INT_LEAST32_MIN = int_least32_t.min;
///
enum int_least32_t INT_LEAST32_MAX = int_least32_t.max;
///
enum int_least64_t INT_LEAST64_MIN = int_least64_t.min;
///
enum int_least64_t INT_LEAST64_MAX = int_least64_t.max;
///
enum uint_least8_t UINT_LEAST8_MAX = uint_least8_t.max;
///
enum uint_least16_t UINT_LEAST16_MAX = uint_least16_t.max;
///
enum uint_least32_t UINT_LEAST32_MAX = uint_least32_t.max;
///
enum uint_least64_t UINT_LEAST64_MAX = uint_least64_t.max;
///
enum int_fast8_t INT_FAST8_MIN = int_fast8_t.min;
///
enum int_fast8_t INT_FAST8_MAX = int_fast8_t.max;
///
enum int_fast16_t INT_FAST16_MIN = int_fast16_t.min;
///
enum int_fast16_t INT_FAST16_MAX = int_fast16_t.max;
///
enum int_fast32_t INT_FAST32_MIN = int_fast32_t.min;
///
enum int_fast32_t INT_FAST32_MAX = int_fast32_t.max;
///
enum int_fast64_t INT_FAST64_MIN = int_fast64_t.min;
///
enum int_fast64_t INT_FAST64_MAX = int_fast64_t.max;
///
enum uint_fast8_t UINT_FAST8_MAX = uint_fast8_t.max;
///
enum uint_fast16_t UINT_FAST16_MAX = uint_fast16_t.max;
///
enum uint_fast32_t UINT_FAST32_MAX = uint_fast32_t.max;
///
enum uint_fast64_t UINT_FAST64_MAX = uint_fast64_t.max;
///
enum intptr_t INTPTR_MIN = intptr_t.min;
///
enum intptr_t INTPTR_MAX = intptr_t.max;
///
enum uintptr_t UINTPTR_MIN = uintptr_t.min;
///
enum uintptr_t UINTPTR_MAX = uintptr_t.max;
///
enum intmax_t INTMAX_MIN = intmax_t.min;
///
enum intmax_t INTMAX_MAX = intmax_t.max;
///
enum uintmax_t UINTMAX_MAX = uintmax_t.max;
///
enum ptrdiff_t PTRDIFF_MIN = ptrdiff_t.min;
///
enum ptrdiff_t PTRDIFF_MAX = ptrdiff_t.max;
///
enum sig_atomic_t SIG_ATOMIC_MIN = sig_atomic_t.min;
///
enum sig_atomic_t SIG_ATOMIC_MAX = sig_atomic_t.max;
///
enum size_t SIZE_MAX = size_t.max;
///
enum wchar_t WCHAR_MIN = wchar_t.min;
///
enum wchar_t WCHAR_MAX = wchar_t.max;
///
enum wint_t WINT_MIN = wint_t.min;
///
enum wint_t WINT_MAX = wint_t.max;
///
alias INT8_C = _typify!int8_t ;
///
alias INT16_C = _typify!int16_t;
///
alias INT32_C = _typify!int32_t;
///
alias INT64_C = _typify!int64_t;
///
alias UINT8_C = _typify!uint8_t ;
///
alias UINT16_C = _typify!uint16_t;
///
alias UINT32_C = _typify!uint32_t;
///
alias UINT64_C = _typify!uint64_t;
///
alias INTMAX_C = _typify!intmax_t ;
///
alias UINTMAX_C = _typify!uintmax_t;
| D |
/Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/ConstraintViewDSL.o : /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Constraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConfig.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDescription.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsets.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintItem.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMaker.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelation.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Debugging.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/LayoutConstraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutGuide+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/Target\ Support\ Files/SnapKit/SnapKit-umbrella.h /Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule
/Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/ConstraintViewDSL~partial.swiftmodule : /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Constraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConfig.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDescription.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsets.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintItem.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMaker.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelation.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Debugging.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/LayoutConstraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutGuide+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/Target\ Support\ Files/SnapKit/SnapKit-umbrella.h /Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule
/Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/Objects-normal/x86_64/ConstraintViewDSL~partial.swiftdoc : /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Constraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintAttributes.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConfig.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintConstantTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDescription.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsets.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintInsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintItem.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuide.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutGuideDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupport.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintLayoutSupportDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMaker.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerEditable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerExtendable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerFinalizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerPriortizable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMakerRelatable.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintMultiplierTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintOffsetTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintPriorityTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelatableTarget.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintRelation.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintView.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/ConstraintViewDSL.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/Debugging.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/LayoutConstraint.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutGuide+Extensions.swift /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/SnapKit/Source/UILayoutSupport+Extensions.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Users/Vishnu/QBurst/Internal/Pod/QAHelper/Pods/Target\ Support\ Files/SnapKit/SnapKit-umbrella.h /Users/Vishnu/QBurst/Internal/Pod/QAHelper/DerivedData/QAHelper/Build/Intermediates/Pods.build/Debug-iphonesimulator/SnapKit.build/unextended-module.modulemap /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule
| D |
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Port to the D programming language:
* Frank Benoit <[email protected]>
*******************************************************************************/
module dwtx.jface.text.rules.IWhitespaceDetector;
import dwtx.jface.text.rules.FastPartitioner; // packageimport
import dwtx.jface.text.rules.ITokenScanner; // packageimport
import dwtx.jface.text.rules.Token; // packageimport
import dwtx.jface.text.rules.RuleBasedScanner; // packageimport
import dwtx.jface.text.rules.EndOfLineRule; // packageimport
import dwtx.jface.text.rules.WordRule; // packageimport
import dwtx.jface.text.rules.WhitespaceRule; // packageimport
import dwtx.jface.text.rules.WordPatternRule; // packageimport
import dwtx.jface.text.rules.IPredicateRule; // packageimport
import dwtx.jface.text.rules.DefaultPartitioner; // packageimport
import dwtx.jface.text.rules.NumberRule; // packageimport
import dwtx.jface.text.rules.SingleLineRule; // packageimport
import dwtx.jface.text.rules.PatternRule; // packageimport
import dwtx.jface.text.rules.RuleBasedDamagerRepairer; // packageimport
import dwtx.jface.text.rules.ICharacterScanner; // packageimport
import dwtx.jface.text.rules.IRule; // packageimport
import dwtx.jface.text.rules.DefaultDamagerRepairer; // packageimport
import dwtx.jface.text.rules.IToken; // packageimport
import dwtx.jface.text.rules.IPartitionTokenScanner; // packageimport
import dwtx.jface.text.rules.MultiLineRule; // packageimport
import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport
import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport
import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport
import dwt.dwthelper.utils;
/**
* Defines the interface by which <code>WhitespaceRule</code>
* determines whether a given character is to be considered
* whitespace in the current context.
*/
public interface IWhitespaceDetector {
/**
* Returns whether the specified character is whitespace.
*
* @param c the character to be checked
* @return <code>true</code> if the specified character is a whitespace char
*/
bool isWhitespace(char c);
}
| D |
someone who attacks in search of booty
| D |
import std.stdio : writeln;
import dmods.generators : Fibgen;
void main() {
Fibgen gen;
ulong cur, sum;
while ((cur = gen.next()) < 4_000_000)
if (cur % 2 == 0)
sum += cur;
writeln(sum);
}
| D |
module mutils.linalg.algorithm;
T mix(T)(T a, T b, float blend) {
return cast(T)(a + (b - a) * blend);
}
unittest {
assert(mix(3, 5, 0.5) == 4);
}
| D |
module android.java.android.media.MediaCasException_UnsupportedCasException_d_interface;
import arsd.jni : IJavaObjectImplementation, JavaPackageId, JavaName, IJavaObject, ImportExportImpl, JavaInterfaceMembers;
static import arsd.jni;
import import1 = android.java.java.io.PrintStream_d_interface;
import import4 = android.java.java.lang.Class_d_interface;
import import3 = android.java.java.lang.StackTraceElement_d_interface;
import import2 = android.java.java.io.PrintWriter_d_interface;
import import0 = android.java.java.lang.JavaThrowable_d_interface;
@JavaName("MediaCasException$UnsupportedCasException")
final class MediaCasException_UnsupportedCasException : IJavaObject {
static immutable string[] _d_canCastTo = [
];
@Import string getMessage();
@Import string getLocalizedMessage();
@Import import0.JavaThrowable getCause();
@Import import0.JavaThrowable initCause(import0.JavaThrowable);
@Import @JavaName("toString") string toString_();
override string toString() { return arsd.jni.javaObjectToString(this); }
@Import void printStackTrace();
@Import void printStackTrace(import1.PrintStream);
@Import void printStackTrace(import2.PrintWriter);
@Import import0.JavaThrowable fillInStackTrace();
@Import import3.StackTraceElement[] getStackTrace();
@Import void setStackTrace(import3.StackTraceElement[]);
@Import void addSuppressed(import0.JavaThrowable);
@Import import0.JavaThrowable[] getSuppressed();
@Import import4.Class getClass();
@Import int hashCode();
@Import bool equals(IJavaObject);
@Import void notify();
@Import void notifyAll();
@Import void wait(long);
@Import void wait(long, int);
@Import void wait();
mixin IJavaObjectImplementation!(false);
public static immutable string _javaParameterString = "Landroid/media/MediaCasException$UnsupportedCasException;";
}
| D |
private
{
void privF() {}
class privC {}
struct privS {}
union privU {}
interface privI {}
enum privE { foo }
mixin template privMT() {}
void privTF(T)() {}
class privTC(T) {}
struct privTS(T) {}
union privTU(T) {}
interface privTI(T) {}
}
void publF(T)() {}
void publFA(alias A)() {}
private alias privC privA;
public mixin template publMT() {}
/***************************************************/
// 14169
template GetName14169(TemplateParam)
{
enum GetName14169 = TemplateParam.Name;
}
| D |
/*
File: CircularSeq.d
Originally written by Doug Lea and released into the public domain.
Thanks for the assistance and support of Sun Microsystems Labs, Agorics
Inc, Loral, and everyone contributing, testing, and using this code.
History:
Date Who What
24Sep95 [email protected] Create from store.d working file
13Oct95 dl Changed protection statuses
*/
module tango.util.collection.CircularSeq;
private import tango.util.collection.model.Iterator,
tango.util.collection.model.GuardIterator;
private import tango.util.collection.impl.CLCell,
tango.util.collection.impl.SeqCollection,
tango.util.collection.impl.AbstractIterator;
/**
* Circular linked lists. Publically Implement only those
* methods defined in interfaces.
* author: Doug Lea
**/
deprecated public class CircularSeq(T) : SeqCollection!(T)
{
alias CLCell!(T) CLCellT;
alias SeqCollection!(T).remove remove;
alias SeqCollection!(T).removeAll removeAll;
// instance variables
/**
* The head of the list. Null if empty
**/
package CLCellT list;
// constructors
/**
* Make an empty list with no element screener
**/
public this ()
{
this(null, null, 0);
}
/**
* Make an empty list with supplied element screener
**/
public this (Predicate screener)
{
this(screener, null, 0);
}
/**
* Special version of constructor needed by clone()
**/
protected this (Predicate s, CLCellT h, int c)
{
super(s);
list = h;
count = c;
}
/**
* Make an independent copy of the list. Elements themselves are not cloned
**/
public final CircularSeq!(T) duplicate()
{
if (list is null)
return new CircularSeq!(T) (screener, null, 0);
else
return new CircularSeq!(T) (screener, list.copyList(), count);
}
// Collection methods
/**
* Implements tango.util.collection.impl.Collection.Collection.contains
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.contains
**/
public final bool contains(T element)
{
if (!isValidArg(element) || list is null)
return false;
return list.find(element) !is null;
}
/**
* Implements tango.util.collection.impl.Collection.Collection.instances
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.instances
**/
public final uint instances(T element)
{
if (!isValidArg(element) || list is null)
return 0;
return list.count(element);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.elements
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.Collection.Collection.elements
**/
public final GuardIterator!(T) elements()
{
return new CellIterator!(T)(this);
}
/**
* Implements tango.util.collection.model.View.View.opApply
* Time complexity: O(n).
* See_Also: tango.util.collection.model.View.View.opApply
**/
int opApply (int delegate (inout T value) dg)
{
auto scope iterator = new CellIterator!(T)(this);
return iterator.opApply (dg);
}
// Seq methods
/**
* Implements tango.util.collection.model.Seq.Seq.head.
* Time complexity: O(1).
* See_Also: tango.util.collection.model.Seq.Seq.head
**/
public final T head()
{
return firstCell().element();
}
/**
* Implements tango.util.collection.model.Seq.Seq.tail.
* Time complexity: O(1).
* See_Also: tango.util.collection.model.Seq.Seq.tail
**/
public final T tail()
{
return lastCell().element();
}
/**
* Implements tango.util.collection.model.Seq.Seq.get.
* Time complexity: O(n).
* See_Also: tango.util.collection.model.Seq.Seq.get
**/
public final T get(int index)
{
return cellAt(index).element();
}
/**
* Implements tango.util.collection.model.Seq.Seq.first.
* Time complexity: O(n).
* See_Also: tango.util.collection.model.Seq.Seq.first
**/
public final int first(T element, int startingIndex = 0)
{
if (startingIndex < 0)
startingIndex = 0;
CLCellT p = list;
if (p is null || !isValidArg(element))
return -1;
for (int i = 0; true; ++i)
{
if (i >= startingIndex && p.element() == (element))
return i;
p = p.next();
if (p is list)
break;
}
return -1;
}
/**
* Implements tango.util.collection.model.Seq.Seq.last.
* Time complexity: O(n).
* See_Also: tango.util.collection.model.Seq.Seq.last
**/
public final int last(T element, int startingIndex = 0)
{
if (!isValidArg(element) || count is 0)
return -1;
if (startingIndex >= size())
startingIndex = size() - 1;
if (startingIndex < 0)
startingIndex = 0;
CLCellT p = cellAt(startingIndex);
int i = startingIndex;
for (;;)
{
if (p.element() == (element))
return i;
else
if (p is list)
break;
else
{
p = p.prev();
--i;
}
}
return -1;
}
/**
* Implements tango.util.collection.model.Seq.Seq.subseq.
* Time complexity: O(length).
* See_Also: tango.util.collection.model.Seq.Seq.subseq
**/
public final CircularSeq subset (int from, int _length)
{
if (_length > 0)
{
checkIndex(from);
CLCellT p = cellAt(from);
CLCellT newlist = new CLCellT(p.element());
CLCellT current = newlist;
for (int i = 1; i < _length; ++i)
{
p = p.next();
if (p is null)
checkIndex(from + i); // force exception
current.addNext(p.element());
current = current.next();
}
return new CircularSeq (screener, newlist, _length);
}
else
return new CircularSeq ();
}
// MutableCollection methods
/**
* Implements tango.util.collection.impl.Collection.Collection.clear.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.Collection.Collection.clear
**/
public final void clear()
{
list = null;
setCount(0);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.exclude.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.exclude
**/
public final void removeAll (T element)
{
remove_(element, true);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.removeOneOf.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.removeOneOf
**/
public final void remove (T element)
{
remove_(element, false);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.replaceOneOf
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.replaceOneOf
**/
public final void replace (T oldElement, T newElement)
{
replace_(oldElement, newElement, false);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.replaceAllOf.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.Collection.Collection.replaceAllOf
**/
public final void replaceAll (T oldElement, T newElement)
{
replace_(oldElement, newElement, true);
}
/**
* Implements tango.util.collection.impl.Collection.Collection.take.
* Time complexity: O(1).
* takes the last element on the list.
* See_Also: tango.util.collection.impl.Collection.Collection.take
**/
public final T take()
{
auto v = tail();
removeTail();
return v;
}
// MutableSeq methods
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.prepend.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.prepend
**/
public final void prepend(T element)
{
checkElement(element);
if (list is null)
list = new CLCellT(element);
else
list = list.addPrev(element);
incCount();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.replaceHead.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.replaceHead
**/
public final void replaceHead(T element)
{
checkElement(element);
firstCell().element(element);
incVersion();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.removeHead.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.removeHead
**/
public final void removeHead()
{
if (firstCell().isSingleton())
list = null;
else
{
auto n = list.next();
list.unlink();
list = n;
}
decCount();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.append.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.append
**/
public final void append(T element)
{
if (list is null)
prepend(element);
else
{
checkElement(element);
list.prev().addNext(element);
incCount();
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.replaceTail.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.replaceTail
**/
public final void replaceTail(T element)
{
checkElement(element);
lastCell().element(element);
incVersion();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.removeTail.
* Time complexity: O(1).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.removeTail
**/
public final void removeTail()
{
auto l = lastCell();
if (l is list)
list = null;
else
l.unlink();
decCount();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.addAt.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.addAt
**/
public final void addAt(int index, T element)
{
if (index is 0)
prepend(element);
else
{
checkElement(element);
cellAt(index - 1).addNext(element);
incCount();
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.replaceAt.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.replaceAt
**/
public final void replaceAt(int index, T element)
{
checkElement(element);
cellAt(index).element(element);
incVersion();
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.removeAt.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.removeAt
**/
public final void removeAt(int index)
{
if (index is 0)
removeHead();
else
{
cellAt(index - 1).unlinkNext();
decCount();
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.prepend.
* Time complexity: O(number of elements in e).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.prepend
**/
public final void prepend(Iterator!(T) e)
{
CLCellT hd = null;
CLCellT current = null;
while (e.more())
{
auto element = e.get();
checkElement(element);
incCount();
if (hd is null)
{
hd = new CLCellT(element);
current = hd;
}
else
{
current.addNext(element);
current = current.next();
}
}
if (list is null)
list = hd;
else
if (hd !is null)
{
auto tl = list.prev();
current.next(list);
list.prev(current);
tl.next(hd);
hd.prev(tl);
list = hd;
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.append.
* Time complexity: O(number of elements in e).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.append
**/
public final void append(Iterator!(T) e)
{
if (list is null)
prepend(e);
else
{
CLCellT current = list.prev();
while (e.more())
{
T element = e.get();
checkElement(element);
incCount();
current.addNext(element);
current = current.next();
}
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.addAt.
* Time complexity: O(size() + number of elements in e).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.addAt
**/
public final void addAt(int index, Iterator!(T) e)
{
if (list is null || index is 0)
prepend(e);
else
{
CLCellT current = cellAt(index - 1);
while (e.more())
{
T element = e.get();
checkElement(element);
incCount();
current.addNext(element);
current = current.next();
}
}
}
/**
* Implements tango.util.collection.impl.SeqCollection.SeqCollection.removeFromTo.
* Time complexity: O(n).
* See_Also: tango.util.collection.impl.SeqCollection.SeqCollection.removeFromTo
**/
public final void removeRange (int fromIndex, int toIndex)
{
checkIndex(toIndex);
CLCellT p = cellAt(fromIndex);
CLCellT last = list.prev();
for (int i = fromIndex; i <= toIndex; ++i)
{
decCount();
CLCellT n = p.next();
p.unlink();
if (p is list)
{
if (p is last)
{
list = null;
return ;
}
else
list = n;
}
p = n;
}
}
// helper methods
/**
* return the first cell, or throw exception if empty
**/
private final CLCellT firstCell()
{
if (list !is null)
return list;
checkIndex(0);
return null; // not reached!
}
/**
* return the last cell, or throw exception if empty
**/
private final CLCellT lastCell()
{
if (list !is null)
return list.prev();
checkIndex(0);
return null; // not reached!
}
/**
* return the index'th cell, or throw exception if bad index
**/
private final CLCellT cellAt(int index)
{
checkIndex(index);
return list.nth(index);
}
/**
* helper for remove/exclude
**/
private final void remove_(T element, bool allOccurrences)
{
if (!isValidArg(element) || list is null)
return;
CLCellT p = list;
for (;;)
{
CLCellT n = p.next();
if (p.element() == (element))
{
decCount();
p.unlink();
if (p is list)
{
if (p is n)
{
list = null;
break;
}
else
list = n;
}
if (! allOccurrences)
break;
else
p = n;
}
else
if (n is list)
break;
else
p = n;
}
}
/**
* helper for replace *
**/
private final void replace_(T oldElement, T newElement, bool allOccurrences)
{
if (!isValidArg(oldElement) || list is null)
return;
CLCellT p = list;
do {
if (p.element() == (oldElement))
{
checkElement(newElement);
incVersion();
p.element(newElement);
if (! allOccurrences)
return;
}
p = p.next();
} while (p !is list);
}
// ImplementationCheckable methods
/**
* Implements tango.util.collection.model.View.View.checkImplementation.
* See_Also: tango.util.collection.model.View.View.checkImplementation
**/
public override void checkImplementation()
{
super.checkImplementation();
assert(((count is 0) is (list is null)));
assert((list is null || list._length() is count));
if (list is null)
return;
int c = 0;
CLCellT p = list;
do {
assert(p.prev().next() is p);
assert(p.next().prev() is p);
assert(allows(p.element()));
assert(instances(p.element()) > 0);
assert(contains(p.element()));
p = p.next();
++c;
} while (p !is list);
assert(c is count);
}
/***********************************************************************
opApply() has migrated here to mitigate the virtual call
on method get()
************************************************************************/
static class CellIterator(T) : AbstractIterator!(T)
{
private CLCellT cell;
public this (CircularSeq seq)
{
super (seq);
cell = seq.list;
}
public final T get()
{
decRemaining();
auto v = cell.element();
cell = cell.next();
return v;
}
int opApply (int delegate (inout T value) dg)
{
int result;
for (auto i=remaining(); i--;)
{
auto value = get();
if ((result = dg(value)) != 0)
break;
}
return result;
}
}
}
debug (Test)
{
import tango.io.Console;
void main()
{
auto array = new CircularSeq!(char[]);
array.append ("foo");
array.append ("bar");
array.append ("wumpus");
foreach (value; array.elements) {}
auto elements = array.elements();
while (elements.more)
auto v = elements.get();
foreach (value; array)
Cout (value).newline;
array.checkImplementation();
}
}
| D |
module mach.range.asarray;
private:
import mach.text : text;
import mach.types : KeyValuePair;
import mach.traits : isArray, isArrayOf, isIterable, isFiniteIterable, ElementType;
import mach.traits : hasNumericLength, LengthType, canCast;
import mach.traits : isAssociativeArray, ArrayKeyType, ArrayValueType;
public:
/// Can an array be made from the iterable without providing an explicit length?
enum canMakeArray(Iter) = (
!isAssociativeArray!Iter && (
isArray!Iter || canMakeFiniteLengthArray!Iter
)
);
/// ditto
enum canMakeArrayOf(Element, Iter) = (
isArrayOf!(Element, Iter) || canMakeFiniteLengthArrayOf!(Element, Iter)
);
/// Can an array be made from the iterable, deriving length from the iterable itself?
enum canMakeKnownLengthArray(Iter) = (
canMakeMaxLengthArray!Iter && isFiniteIterable!Iter && hasNumericLength!Iter
);
/// ditto
enum canMakeKnownLengthArrayOf(Element, Iter) = (
canMakeKnownLengthArray!Iter &&
canMakeMaxLengthArrayOf!(Element, Iter)
);
/// Can an array of a default maximum length be made from the iterable?
/// Requires that an iterable be definitely finite.
enum canMakeFiniteLengthArray(Iter) = (
canMakeMaxLengthArray!Iter && isFiniteIterable!Iter
);
/// ditto
enum canMakeFiniteLengthArrayOf(Element, Iter) = (
canMakeFiniteLengthArray!Iter &&
canMakeMaxLengthArrayOf!(Element, Iter)
);
/// Can an array of some given maximum length be made from the iterable?
enum canMakeMaxLengthArray(Iter) = (
isIterable!Iter
);
/// ditto
template canMakeMaxLengthArrayOf(Element, Iter){
static if(canMakeMaxLengthArray!Iter){
enum bool canMakeMaxLengthArrayOf = canCast!(ElementType!Iter, Element);
}else{
enum bool canMakeMaxLengthArrayOf = false;
}
};
/// Create an array of up to the first maxlength items from an iterable of
/// unknown length. If enforce is true, an AssertError is raised when the
/// length of the iterable to convert is found to be longer than the given
/// maxlength.
auto asarray(bool enforce = false, Iter)(auto ref Iter iter, size_t maxlength) if(
canMakeMaxLengthArray!Iter
){
return asarray!(ElementType!Iter, enforce, Iter)(iter, maxlength);
}
// ditto
auto asarray(Element, bool enforce = false, Iter)(auto ref Iter iter, size_t maxlength) if(
canMakeMaxLengthArrayOf!(Element, Iter)
){
Element[] array;
foreach(item; iter){
if(array.length >= maxlength){
static if(enforce) assert(false,
text("Iterable exceeded maximum expected length ", maxlength, ".")
);
else break;
}
array ~= item;
}
return array;
}
/// Create an array from an arbitrary finite iterable.
auto asarray(Iter)(auto ref Iter iter) if(
canMakeArray!Iter
){
return asarray!(ElementType!Iter, Iter)(iter);
}
/// ditto
auto asarray(Element, Iter)(auto ref Iter iter) if(
canMakeArrayOf!(Element, Iter)
){
static if(isArrayOf!(Element, Iter)){
return iter;
}else static if(canMakeKnownLengthArrayOf!(Element, Iter)){
return asknownlengtharray!(Element, Iter)(iter, cast(size_t) iter.length);
}else static if(canMakeFiniteLengthArrayOf!(Element, Iter)){
return asarray!(Element, false, Iter)(iter, size_t.max);
}else{
static assert(false); // This shouldn't happen
}
}
/// Create array from an iterable where exact length is known at runtime.
auto asknownlengtharray(Element, Iter)(auto ref Iter iter, size_t length) if(
canMakeMaxLengthArrayOf!(Element, Iter)
){
Element[] array;
array.reserve(length);
foreach(item; iter){
assert(array.length < length,
text("Iterable is longer than assumed length ", length, ".")
);
array ~= item;
}
assert(array.length == length,
text("Iterable is shorter than assumed length ", length, ".")
);
return array;
}
/// Create array from an iterable where exact length is known at compile time.
auto asarray(size_t length, Iter)(auto ref Iter iter) if(canMakeArray!(Iter)){
return asarray!(ElementType!Iter, length, Iter)(iter);
}
/// ditto
auto asarray(Element, size_t length, Iter)(auto ref Iter iter) if(
canMakeMaxLengthArrayOf!(Element, Iter)
){
Element[length] array;
size_t index = 0;
foreach(item; iter){
assert(index < array.length,
text("Iterable is longer than assumed length ", length, ".")
);
array[index++] = item;
}
assert(index == array.length,
text("Iterable is shorter than assumed length ", length, ".")
);
return array;
}
/// Create an array of key, value pairs from an associative array.
auto asarray(T)(auto ref T input) if(isAssociativeArray!T){
alias Pair = KeyValuePair!(ArrayKeyType!T, ArrayValueType!T);
Pair[] array;
array.reserve(input.length);
foreach(key, value; input){
array ~= Pair(key, value);
}
return array;
}
version(unittest){
private:
import mach.test;
struct KnownLengthTest{
size_t start;
size_t length;
size_t index;
this(size_t start, size_t length, size_t index = 0){
this.start = start;
this.length = length;
this.index = index;
}
@property auto front(){
return this.start + index;
}
void popFront(){
this.index++;
}
@property bool empty(){
return this.index >= this.length;
}
}
struct InfiniteRangeTest{
size_t start;
size_t index;
this(size_t start, size_t index = 0){
this.start = start;
this.index = index;
}
@property auto front(){
return this.start + index;
}
void popFront(){
this.index++;
}
enum bool empty = false;
}
}
unittest{
tests("As array", {
{
// Basic use case
testeq(KnownLengthTest(0, 4).asarray, [0, 1, 2, 3]);
// Finite range with max length
testeq(KnownLengthTest(0, 4).asarray(2), [0, 1]);
// With ct length
testeq(KnownLengthTest(0, 4).asarray!4, [0, 1, 2, 3]);
// With incorrect ct length
testfail({KnownLengthTest(0, 4).asarray!6;});
// Infinite range with max length
testeq(InfiniteRangeTest(0).asarray(4), [0, 1, 2, 3]);
testfail({InfiniteRangeTest(0).asarray!true(4);});
// Specify element type
auto im = KnownLengthTest(0, 4).asarray!(immutable size_t);
static assert(is(typeof(im[0]) == immutable size_t));
testeq(im, [0, 1, 2, 3]);
// Call for array
auto ints = [1, 2, 3, 4, 5, 6];
testis(ints.asarray, ints);
}
tests("Associative array", {
auto array = asarray(["a": "aardvark", "b": "bear", "c": "crow"]);
testeq(array.length, 3);
foreach(pair; array){
testeq(pair.key[0], pair.value[0]);
}
});
});
}
| D |
with official authorization
in a formal manner
| D |
instance GUR_1210_BaalTyon(Npc_Default)
{
name[0] = "Baal Tyon";
npcType = npctype_friend;
guild = GIL_GUR;
level = 28;
flags = NPC_FLAG_IMMORTAL;
voice = 11;
id = 1210;
attribute[ATR_STRENGTH] = 70;
attribute[ATR_DEXTERITY] = 50;
attribute[ATR_MANA_MAX] = 60;
attribute[ATR_MANA] = 60;
attribute[ATR_HITPOINTS_MAX] = 418;
attribute[ATR_HITPOINTS] = 418;
Mdl_SetVisual(self,"HUMANS.MDS");
Mdl_ApplyOverlayMds(self,"Humans_Mage.mds");
Mdl_SetVisualBody(self,"hum_body_Naked0",1,1,"Hum_Head_Psionic",24,2,gur_armor_m);
B_Scale(self);
Mdl_SetModelFatness(self,-1);
Npc_SetTalentSkill(self,NPC_TALENT_MAGE,6);
CreateInvItem(self,ItArRuneWindfist);
daily_routine = Rtn_start_1210;
fight_tactic = FAI_HUMAN_MAGE;
};
func void Rtn_start_1210()
{
TA_Teaching(16,0,23,0,"PSI_TEMPLE_COURT_GURU");
TA_Teaching(23,0,16,0,"PSI_TEMPLE_COURT_GURU");
};
func void rtn_ritual_1210()
{
TA_Stay(5,0,1,0,"GURU_RITUAL_05");
TA_Stay(1,0,5,0,"GURU_RITUAL_05");
};
func void Rtn_PrepareRitual_1210()
{
TA_SitAround(16,0,23,0,"PSI_TEMPLE_IN_05");
TA_SitAround(23,0,16,0,"PSI_TEMPLE_IN_05");
};
func void Rtn_OMFull_1210()
{
TA_SitAround(16,0,23,0,"PSI_TEMPLE_SITTING_PRIEST");
TA_SitAround(23,0,16,0,"PSI_TEMPLE_SITTING_PRIEST");
};
func void Rtn_FMTaken_1210()
{
TA_SitAround(16,0,23,0,"PSI_TEMPLE_SITTING_PRIEST");
TA_SitAround(23,0,16,0,"PSI_TEMPLE_SITTING_PRIEST");
};
func void Rtn_OrcAssault_1210()
{
TA_SitAround(16,0,23,0,"PSI_TEMPLE_SITTING_PRIEST");
TA_SitAround(23,0,16,0,"PSI_TEMPLE_SITTING_PRIEST");
};
| D |
module sceneparser.shapes.Plane;
import raytracer.Colors;
import raytracer.Materials;
import raytracer.MathShapes;
import raytracer.RTObject;
import raytracer.Transformation;
import raytracer.Vector;
import sceneparser.general.Context;
import sceneparser.general.Expression;
import sceneparser.general.ParameterList;
import sceneparser.general.Value;
import sceneparser.shapes.Shape;
import tango.io.Stdout;
import tango.text.convert.Format;
class Plane: Shape
{
Vector normal;
double distance;
Colors color = {0, 0, 0};
double reflectivity = 0, transparency = 0;
Expression parameters;
bool init = false;
public this(Context con, Expression expr)
{
super(con);
parameters = expr;
}
private void checkParameters()
{
try
{
ParameterList p_list = cast(ParameterList)parameters;
int i = 0;
normal = p_list[i++].toVector;
distance = p_list[i++].toNumber;
if (p_list.length >= i + 1)
color = p_list[i++].toColor();
if (p_list.length >= i + 1)
reflectivity = p_list[i++].toNumber;
if (p_list.length >= i + 1)
transparency = p_list[i++].toNumber;
}
catch (TypeMismatchException)
{
Stdout("Error handling parameters to plane.").newline;
}
}
private RTObject createRTObject()
{
checkParameters();
RTObject object = new RTObject(new MathPlane(normal, distance),
new SolidColorMaterial(color, reflectivity, transparency));
context.rt.applyCurrentTransformation(object);
return object;
}
public override ObjectReference getValue()
{
return new ObjectReference(createRTObject());
}
}
| D |
/mnt/c/Users/zeliwang/hello_world/digital_signature/target/release/deps/serde-25d9675be6ba1493.rmeta: /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/lib.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/integer128.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/value.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/from_primitive.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/ignored_any.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/utf8.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impossible.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/export.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/de.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/ser.rs
/mnt/c/Users/zeliwang/hello_world/digital_signature/target/release/deps/libserde-25d9675be6ba1493.rlib: /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/lib.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/integer128.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/value.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/from_primitive.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/ignored_any.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/utf8.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impossible.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/export.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/de.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/ser.rs
/mnt/c/Users/zeliwang/hello_world/digital_signature/target/release/deps/serde-25d9675be6ba1493.d: /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/lib.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/integer128.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/value.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/from_primitive.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/ignored_any.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/utf8.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impls.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impossible.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/export.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/mod.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/macros.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/de.rs /home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/ser.rs
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/lib.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/macros.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/integer128.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/mod.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/value.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/from_primitive.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/ignored_any.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/impls.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/de/utf8.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/mod.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impls.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/ser/impossible.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/export.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/mod.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/macros.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/de.rs:
/home/zeliwang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/serde-1.0.99/src/private/ser.rs:
| D |
// This file is part of Visual D
//
// Visual D integrates the D programming language into Visual Studio
// Copyright (c) 2010-2011 by Rainer Schuetze, All Rights Reserved
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
module vdc.ast.mod;
import vdc.util;
import vdc.semantic;
import vdc.lexer;
import vdc.ast.node;
import vdc.ast.decl;
import vdc.ast.expr;
import vdc.ast.misc;
import vdc.ast.aggr;
import vdc.ast.tmpl;
import vdc.ast.writer;
import vdc.parser.engine;
import vdc.interpret;
import stdext.util;
import std.conv;
import std.path;
import std.array;
import std.algorithm;
////////////////////////////////////////////////////////////////
//Module:
// [ModuleDeclaration_opt DeclDef...]
class Module : Node
{
mixin ForwardCtor!();
string filename;
bool imported;
Options options;
override Module clone()
{
Module n = static_cast!Module(super.clone());
n.filename = filename;
n.imported = imported;
return n;
}
override bool compare(const(Node) n) const
{
if(!super.compare(n))
return false;
auto tn = static_cast!(typeof(this))(n);
return tn.filename == filename
&& tn.imported == imported;
}
Project getProject() { return static_cast!Project(parent); }
override void toD(CodeWriter writer)
{
foreach(m; members)
writer(m);
}
override void toC(CodeWriter writer)
{
if(members.length > 0 && cast(ModuleDeclaration) getMember(0))
{
auto fqn = getMember(0).getMember!ModuleFullyQualifiedName(0);
foreach(m; fqn.members)
{
writer("namespace ", m, " {");
writer.nl;
}
writer.nl;
foreach(m; members[1..$])
writer(m);
writer.nl(false);
foreach_reverse(m; fqn.members)
{
writer("} // namespace ", m);
writer.nl;
}
}
else
{
writer("namespace ", baseName(filename), " {");
writer.nl;
foreach(m; members)
writer(m);
writer.nl(false);
writer("} // namespace ", baseName(filename));
writer.nl;
}
}
void writeNamespace(CodeWriter writer)
{
if(members.length > 0 && cast(ModuleDeclaration) getMember(0))
{
auto fqn = getMember(0).getMember!ModuleFullyQualifiedName(0);
foreach(m; fqn.members)
writer("::", m);
}
else
writer("::", baseName(filename));
writer("::");
}
string getModuleName()
{
if(auto md = cast(ModuleDeclaration) getMember(0))
{
auto mfqn = md.getMember!ModuleFullyQualifiedName(0);
string name = mfqn.getName();
return name;
}
return stripExtension(baseName(filename));
}
override bool createsScope() const { return true; }
override Scope enterScope(Scope sc)
{
initScope();
return super.enterScope(sc);
}
override Scope getScope()
{
initScope();
return scop;
}
void initScope()
{
if(!scop)
{
scop = new Scope;
scop.mod = this;
scop.node = this;
// add implicite import of module object
if(auto prj = getProject())
if(auto objmod = prj.getObjectModule(this))
if(objmod !is this)
{
auto imp = Import.create(objmod); // only needs module name
scop.addImport(imp);
}
super.addMemberSymbols(scop);
}
}
override void addMemberSymbols(Scope sc)
{
initScope();
}
Scope.SearchSet search(string ident)
{
initScope();
return scop.search(ident, false, false, true);
}
override void _semantic(Scope sc)
{
if(imported) // no full semantic on imports
return;
// the order in which lazy semantic analysis takes place:
// - evaluate/expand version/debug
// - evaluate mixins and static if conditionals in lexical order
// - analyze declarations:
// - instantiate templates
// - evaluate compile time expression
// to resolve identifiers:
// look in current scope, module
// if not found, search all imports
initScope();
sc = sc.push(scop);
scope(exit) sc.pop();
foreach(m; members)
{
m.semantic(scop);
}
}
public /* debug & version handling */ {
VersionDebug debugIds;
VersionDebug versionIds;
Options getOptions()
{
if(options)
return options;
if(auto prj = getProject())
return prj.options;
return null;
}
void specifyVersion(string ident, TextPos pos)
{
if(Options opt = getOptions())
if(opt.versionPredefined(ident) != 0)
semanticError("cannot define predefined version identifier " ~ ident);
versionIds.define(ident, pos);
}
void specifyVersion(int level)
{
versionIds.level = max(level, versionIds.level);
}
bool versionEnabled(string ident, TextPos pos)
{
if(Options opt = getOptions())
if(opt.versionEnabled(ident))
return true;
if(versionIds.defined(ident, pos))
return true;
return false;
}
bool versionEnabled(int level)
{
if(Options opt = getOptions())
if(opt.versionEnabled(level))
return true;
return level <= versionIds.level;
}
void specifyDebug(string ident, TextPos pos)
{
debugIds.define(ident, pos);
}
void specifyDebug(int level)
{
debugIds.level = max(level, debugIds.level);
}
bool debugEnabled(string ident, TextPos pos)
{
if(Options opt = getOptions())
{
if(!opt.debugOn)
return false;
if(opt.debugEnabled(ident))
return true;
}
if(debugIds.defined(ident, pos))
return true;
return false;
}
bool debugEnabled(int level)
{
if(Options opt = getOptions())
{
if(!opt.debugOn)
return false;
if(opt.debugEnabled(level))
return true;
}
return level <= debugIds.level;
}
bool debugEnabled()
{
if(Options opt = getOptions())
return opt.debugOn;
return false;
}
}
}
//ModuleDeclaration:
// [ModuleFullyQualifiedName]
class ModuleDeclaration : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer("module ", getMember(0), ";");
writer.nl;
}
}
class PackageIdentifier : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
assert(false);
}
}
//ModuleFullyQualifiedName:
// [Identifier...]
class ModuleFullyQualifiedName : Node
{
PackageIdentifier[] pkgs;
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer.writeArray(members, ".");
}
override bool createsScope() const { return true; }
override void addSymbols(Scope sc)
{
for(int m = 0; m < members.length; m++)
{
auto id = getMember!Identifier(m);
string name = id.ident;
Scope.SearchSet syms = sc.search(name, false, false, false);
if(syms.length > 1)
{
semanticError("ambiguous use of package/module name ", name);
break;
}
else if(syms.length == 1)
{
Node n = syms.first();
if(auto pkg = cast(PackageIdentifier)n)
{
sc = pkg.enterScope(sc);
pkgs ~= pkg;
}
else
{
semanticError("package/module name ", name, " also used as ", n);
break;
}
}
else
{
auto pkg = new PackageIdentifier(id.span);
sc.addSymbol(name, pkg);
sc = pkg.enterScope(sc);
pkgs ~= pkg;
}
}
}
string getName()
{
string name = getMember!Identifier(0).ident;
foreach(m; 1..members.length)
name ~= "." ~ getMember!Identifier(m).ident;
return name;
}
}
//EmptyDeclDef:
// []
class EmptyDeclDef : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer(";");
writer.nl;
}
}
//AttributeSpecifier:
// attributes annotations [DeclarationBlock_opt]
class AttributeSpecifier : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer.writeAttributesAndAnnotations(attr, annotation);
switch(id)
{
case TOK_colon:
assert(members.length == 0);
writer(":");
writer.nl;
break;
case TOK_lcurly:
writer.nl;
//writer("{");
//writer.nl;
//{
// CodeIndenter indent = CodeIndenter(writer);
writer(getMember(0));
//}
//writer("}");
//writer.nl;
break;
default:
writer(getMember(0));
break;
}
}
void applyAttributes(Node m)
{
m.attr = combineAttributes(attr, m.attr);
m.annotation = combineAnnotations(annotation, m.annotation);
}
override Node[] expandNonScopeBlock(Scope sc, Node[] athis)
{
switch(id)
{
case TOK_colon:
combineAttributes(sc.attributes, attr);
combineAnnotations(sc.attributes, annotation);
return [];
case TOK_lcurly:
auto db = getMember!DeclarationBlock(0);
foreach(m; db.members)
applyAttributes(m);
return db.removeAll();
default:
applyAttributes(getMember(0));
return removeAll();
}
}
}
//UserAttributeSpecifier:
// ident [ArgumentList_opt]
class UserAttributeSpecifier : Node
{
mixin ForwardCtor!();
string ident;
ArgumentList getArgumentList() { return getMember!ArgumentList(0); }
override void toD(CodeWriter writer)
{
writer(ident);
if(members.length)
{
writer("(");
writer.writeArray(members);
writer(")");
}
}
override void addSymbols(Scope sc)
{
addMemberSymbols(sc);
}
override void _semantic(Scope sc)
{
}
}
//DeclarationBlock:
// [DeclDef...]
class DeclarationBlock : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
if(id == TOK_lcurly)
{
writer("{");
writer.nl;
{
CodeIndenter indent = CodeIndenter(writer);
foreach(m; members)
writer(m);
}
writer("}");
writer.nl;
}
else
foreach(m; members)
writer(m);
}
override Node[] expandNonScopeBlock(Scope sc, Node[] athis)
{
return removeAll();
}
}
//LinkageAttribute:
// attribute
class LinkageAttribute : AttributeSpecifier
{
mixin ForwardCtor!();
override Node[] expandNonScopeBlock(Scope sc, Node[] athis)
{
return super.expandNonScopeBlock(sc, athis);
}
}
//AlignAttribute:
// attribute
class AlignAttribute : AttributeSpecifier
{
mixin ForwardCtor!();
}
//Pragma:
// ident [TemplateArgumentList]
class Pragma : Node
{
mixin ForwardCtor!();
string ident;
TemplateArgumentList getTemplateArgumentList() { return getMember!TemplateArgumentList(0); }
override Pragma clone()
{
Pragma n = static_cast!Pragma(super.clone());
n.ident = ident;
return n;
}
override bool compare(const(Node) n) const
{
if(!super.compare(n))
return false;
auto tn = static_cast!(typeof(this))(n);
return tn.ident == ident;
}
override void toD(CodeWriter writer)
{
writer("pragma(", ident, ", ", getMember(0), ")");
}
override void _semantic(Scope sc)
{
if(ident == "msg")
{
string msg;
auto alst = getTemplateArgumentList();
alst.semantic(sc);
foreach(m; alst.members)
{
Value val = m.interpretCatch(nullContext);
msg ~= val.toMixin();
}
semanticMessage(msg);
}
}
}
//ImportDeclaration:
// [ImportList]
class ImportDeclaration : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer("import ", getMember(0), ";");
writer.nl();
}
override void toC(CodeWriter writer)
{
}
override void _semantic(Scope sc)
{
getMember(0).annotation = annotation; // copy protection attributes
getMember(0).semantic(sc);
}
override void addSymbols(Scope sc)
{
getMember(0).addSymbols(sc);
}
}
//ImportList:
// [Import...]
class ImportList : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer.writeArray(members);
}
override void _semantic(Scope sc)
{
foreach(m; members)
{
m.annotation = annotation; // copy protection attributes
m.semantic(sc);
}
}
override void addSymbols(Scope sc)
{
foreach(m; members)
m.addSymbols(sc);
}
}
//Import:
// aliasIdent_opt [ModuleFullyQualifiedName ImportBindList_opt]
class Import : Node
{
mixin ForwardCtor!();
string aliasIdent;
ImportBindList getImportBindList() { return members.length > 1 ? getMember!ImportBindList(1) : null; }
Annotation getProtection()
{
if(parent && parent.parent)
return parent.parent.annotation & Annotation_ProtectionMask;
return Annotation_Private;
}
// semantic data
Module mod;
int countLookups;
int countFound;
override Import clone()
{
Import n = static_cast!Import(super.clone());
n.aliasIdent = aliasIdent;
return n;
}
override bool compare(const(Node) n) const
{
if(!super.compare(n))
return false;
auto tn = static_cast!(typeof(this))(n);
return tn.aliasIdent == aliasIdent;
}
override void toD(CodeWriter writer)
{
if(aliasIdent.length)
writer(aliasIdent, " = ");
writer(getMember(0));
if(auto bindList = getImportBindList())
writer(" : ", bindList);
}
override void addSymbols(Scope sc)
{
sc.addImport(this);
if(aliasIdent.length > 0)
sc.addSymbol(aliasIdent, this);
auto mfqn = getMember!ModuleFullyQualifiedName(0);
mfqn.addSymbols(sc);
}
Scope.SearchSet search(Scope sc, string ident)
{
if(!mod)
if(auto prj = sc.mod.getProject())
mod = prj.importModule(getModuleName(), this);
if(!mod)
return Scope.SearchSet();
return mod.search(ident);
}
string getModuleName()
{
auto mfqn = getMember!ModuleFullyQualifiedName(0);
return mfqn.getName();
}
static Import create(Module mod)
{
// TODO: no location info
auto id = new Identifier;
id.ident = mod.getModuleName(); // TODO: incorrect for modules in packages
auto mfqm = new ModuleFullyQualifiedName;
mfqm.addMember(id);
auto imp = new Import;
imp.addMember(mfqm);
return imp;
}
}
unittest
{
verifyParseWrite(q{ import test; });
verifyParseWrite(q{ import ntest = pkg.test; });
verifyParseWrite(q{ import io = std.stdio : writeln, write; });
}
//ImportBindList:
// ImportBind
// ImportBind , ImportBindList
class ImportBindList : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer.writeArray(members);
}
}
//ImportBind:
// Identifier
// Identifier = Identifier
class ImportBind : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer(getMember(0));
if(members.length > 1)
writer(" = ", getMember(1));
}
}
//MixinDeclaration:
// mixin ( AssignExpression ) ;
class MixinDeclaration : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer("mixin(", getMember(0), ");");
writer.nl;
}
override Node[] expandNonScopeInterpret(Scope sc, Node[] athis)
{
Context ctx = new Context(nullContext);
ctx.scop = sc;
Value v = getMember(0).interpret(ctx);
string s = v.toMixin();
Parser parser = new Parser;
if(auto prj = sc.getProject())
parser.saveErrors = prj.saveErrors;
return parser.parseDeclarations(s, span);
}
}
//Unittest:
// unittest BlockStatement
class Unittest : Node
{
mixin ForwardCtor!();
override void toD(CodeWriter writer)
{
writer("unittest");
writer.nl;
writer(getMember(0));
}
override void toC(CodeWriter writer)
{
}
}
| D |
INSTANCE Mod_7647_OUT_Strewak_EIS (Npc_Default)
{
// ------ NSC ------
name = "gefrorener Leichnam";
guild = GIL_NONE;
id = 7647;
voice = 0;
flags = 2;
npctype = NPCTYPE_FRIEND; //plündert nicht!!! (und ein Freischlag)
nofocus = 1;
// ------ AIVARs ------
aivar[AIV_ToughGuy] = TRUE;
aivar[AIV_ToughGuyNewsOverride] = TRUE;
aivar[AIV_MM_FollowTime] = 1000;
aivar[AIV_FightDistCancel] = 600;
aivar[AIV_MaxDistToWp] = 300;
aivar[AIV_OriginalFightTactic] = FAI_HUMAN_NORMAL;
// ------ Attribute ------
B_SetAttributesToChapter (self, 1);
level = 20;
// ------ Kampf-Taktik ------
fight_tactic = FAI_HUMAN_NORMAL;
// ------ Equippte Waffen ------
CreateInvItems (self, ItWr_Strewak_01, 1);
CreateInvItems (self, ItWr_Strewak_02, 1);
CreateInvItems (self, ItWr_Strewak_03, 1);
CreateInvItems (self, ItWr_ManaStonePlate2_Addon, 1);
// ------ Inventory ------
B_CreateAmbientInv (self);
// ------ visuals ------
B_SetNpcVisual (self, MALE, "Hum_Head_Fighter", Face_N_Bloodwyn, BodyTex_N, ITAR_Eisgebiet_01);
Mdl_SetModelFatness (self,0);
Mdl_ApplyOverlayMds (self, "Humans_Relaxed.mds");
// ------ NSC-relevante Talente vergeben ------
B_GiveNpcTalents (self);
// ------ Kampf-Talente ------
B_SetFightSkills (self,10);
// ------ TA anmelden ------
daily_routine = Rtn_Start_7647;
};
FUNC VOID Rtn_Start_7647() //NICHT ÄNDERN --> DIALOG!
{
TA_Eingefroren (10,55,19,15,"EISRIESE_02");
TA_Eingefroren (03,30,10,55,"EISRIESE_02");
};
FUNC VOID Rtn_Tot_7647()
{
TA_Stand_WP (08,00,22,00,"EISRIESE_02");
TA_Stand_WP (22,00,08,00,"EISRIESE_02");
}; | D |
#!/usr/bin/env rdmd
/**
* D testing tool.
*
* This module implements the test runner for all tests except `unit`.
*
* The general procedure is:
*
* 1. Parse the environment variables (`processEnvironment`)
* 2. Extract test parameters from the source file (`gatherTestParameters`)
* [3. Compile non-D sources (` collectExtraSources`)]
* 4. Compile the test file (`tryMain`)
* 5. Verify the compiler output (`compareOutput`)
* [6. Run the generated executable (`tryMain`) ]
* [5. Verify the executable's output (`compareOutput`) ]
* [7. Run post-test steps (`tryMain`) ]
* 8. Remove intermediate files (`tryMain`)
*
* Optional steps are marked with [...]
*/
module d_do_test;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime.stopwatch;
import std.datetime.systime;
import std.exception;
import std.file;
import std.format;
import std.meta : AliasSeq;
import std.process;
import std.random;
import std.range : chain;
import std.regex;
import std.path;
import std.stdio;
import std.string;
import core.sys.posix.sys.wait;
/// Absolute path to the test directory
const dmdTestDir = __FILE_FULL_PATH__.dirName.dirName;
version(Win32)
{
extern(C) int putenv(const char*);
}
/// Prints the `--help` information
void usage()
{
write("d_do_test <test_file>\n"
~ "\n"
~ " Note: this program is normally called through the Makefile, it"
~ " is not meant to be called directly by the user.\n"
~ "\n"
~ " example: d_do_test runnable/pi.d\n"
~ "\n"
~ " relevant environment variables:\n"
~ " ARGS: set to execute all combinations of\n"
~ " REQUIRED_ARGS: arguments always passed to the compiler\n"
~ " DMD: compiler to use, ex: ../src/dmd (required)\n"
~ " CC: C++ compiler to use, ex: dmc, g++\n"
~ " OS: windows, linux, freebsd, osx, netbsd, dragonflybsd\n"
~ " RESULTS_DIR: base directory for test results\n"
~ " MODEL: 32 or 64 (required)\n"
~ " AUTO_UPDATE: set to 1 to auto-update mismatching test output\n"
~ " PRINT_RUNTIME: set to 1 to print test runtime\n"
~ "\n"
~ " windows vs non-windows portability env vars:\n"
~ " DSEP: \\\\ or /\n"
~ " SEP: \\ or / (required)\n"
~ " OBJ: .obj or .o (required)\n"
~ " EXE: .exe or <null> (required)\n");
}
/// Type of test to execute (mapped to the subdirectories)
enum TestMode
{
COMPILE, /// compilable
FAIL_COMPILE, /// fail_compilation
RUN, /// runnable, runnable_cxx
DSHELL, /// dshell
}
/// Test parameters specified in the source file
/// (conditionally expanded depending on the environment)
struct TestArgs
{
TestMode mode; /// Test type based on the directory
bool compileSeparately; /// `COMPILE_SEPARATELY`: compile each source file separately
bool link; /// `LINK`: force linking for `fail_compilation` & `compilable` tests
bool clearDflags; /// `DFLAGS`: whether DFLAGS should be cleared before invoking dmd
string executeArgs; /// `EXECUTE_ARGS`: arguments passed to the compiled executable (for `runnable[_cxx]`)
string cxxflags; /// `CXXFLAGS`: arguments passed to $CC when compiling `EXTRA_CPP_SOURCES`
string[] sources; /// `EXTRA_SOURCES`: additional D sources (+ main source file)
string[] compiledImports; /// `COMPILED_IMPORTS`: files compiled alongside the main source
string[] cppSources; /// `EXTRA_CPP_SOURCES`: additional C++ sources
string[] objcSources; /// `EXTRA_OBJC_SOURCES`: additional Objective-C sources
string permuteArgs; /// `PERMUTE_ARGS`: set of dmd arguments to permute for multiple test runs
string[] argSets; /// `ARG_SETS`: selection of dmd arguments to use in different test runs
string compileOutput; /// `TEST_OUTPUT`: expected output of dmd
string compileOutputFile; /// `TEST_OUTPUT_FILE`: file containing the expected `TEST_OUTPUT`
string runOutput; /// `RUN_OUTPUT`: expected output of the compiled executable
string gdbScript; /// `GDB_SCRIPT`: script executed when running the compiled executable in GDB
string gdbMatch; /// `GDB_MATCH`: regex describing the expected output from executing `GDB_SSCRIPT`
string postScript; /// `POSTSCRIPT`: bash script executed after a successful test
string[] outputFiles; /// generated files appended to the compilation output
string transformOutput; /// Transformations for the compiler output
string requiredArgs; /// `REQUIRED_ARGS`: dmd arguments passed when compiling D sources
string requiredArgsForLink; /// `COMPILE_SEPARATELY`: dmd arguments passed when linking separately compiled objects
string disabledReason; /// `DISABLED`: reason to skip this test or empty, if the test is not disabled
/// Returns: whether this disabled due to some reason
bool isDisabled() const { return disabledReason.length != 0; }
}
/// Test parameters specified in the environment (e.g. target model)
/// which are shared between all tests
struct EnvData
{
string all_args; /// `ARGS`: arguments to test in permutations
string dmd; /// `DMD`: compiler under test
string results_dir; /// `RESULTS_DIR`: directory for temporary files
string sep; /// `SEP`: directory separator (`/` or `\`)
string dsep; /// `DSEP`: double directory separator ( `/` or `\\`)
string obj; /// `OBJ`: object file extension (`.o` or `.obj`)
string exe; /// `EXE`: executable file extension (none or `.exe`)
string os; /// `OS`: host operating system (`linux`, `windows`, ...)
string compiler; /// `HOST_DMD`: host D compiler
string ccompiler; /// `CC`: host C++ compiler
string model; /// `MODEL`: target model (`32` or `64`)
string required_args; /// `REQUIRED_ARGS`: flags added to the tests `REQUIRED_ARGS` parameter
string cxxCompatFlags; /// Additional flags passed to $(compiler) when `EXTRA_CPP_SOURCES` is present
string[] picFlag; /// Compiler flag for PIC (if requested from environment)
bool dobjc; /// `D_OBJC`: run Objective-C tests
bool coverage_build; /// `COVERAGE`: coverage build, skip linking & executing to save time
bool autoUpdate; /// `AUTO_UPDATE`: update `(TEST|RUN)_OUTPUT` on missmatch
bool printRuntime; /// `PRINT_RUNTIME`: Print time spent on a single test
bool usingMicrosoftCompiler; /// Using Visual Studio toolchain
bool tryDisabled; /// `TRY_DISABLED`:Silently try disabled tests (ignore failure and report success)
}
/++
Creates a new EnvData instance based on the current environment.
Other code should not read from the environment.
Returns: an initialized EnvData instance
++/
immutable(EnvData) processEnvironment()
{
static string envGetRequired(in char[] name)
{
if (auto value = environment.get(name))
return value;
writefln("Error: Missing environment variable '%s', was this called through the Makefile?",
name);
throw new SilentQuit();
}
EnvData envData;
envData.all_args = environment.get("ARGS");
envData.results_dir = envGetRequired("RESULTS_DIR");
envData.sep = envGetRequired ("SEP");
envData.dsep = environment.get("DSEP");
envData.obj = envGetRequired ("OBJ");
envData.exe = envGetRequired ("EXE");
envData.os = environment.get("OS");
envData.dmd = replace(envGetRequired("DMD"), "/", envData.sep);
envData.compiler = "dmd"; //should be replaced for other compilers
envData.ccompiler = environment.get("CC");
envData.model = envGetRequired("MODEL");
envData.required_args = environment.get("REQUIRED_ARGS");
envData.dobjc = environment.get("D_OBJC") == "1";
envData.coverage_build = environment.get("DMD_TEST_COVERAGE") == "1";
envData.autoUpdate = environment.get("AUTO_UPDATE", "") == "1";
envData.printRuntime = environment.get("PRINT_RUNTIME", "") == "1";
envData.tryDisabled = environment.get("TRY_DISABLED") == "1";
enforce(envData.sep.length == 1,
"Path separator must be a single character, not: `"~envData.sep~"`");
if (envData.ccompiler.empty)
{
if (envData.os != "windows")
envData.ccompiler = "c++";
else if (envData.model == "32")
envData.ccompiler = "dmc";
else if (envData.model == "64")
envData.ccompiler = `C:\"Program Files (x86)"\"Microsoft Visual Studio 10.0"\VC\bin\amd64\cl.exe`;
else
{
writeln("Unknown $OS$MODEL combination: ", envData.os, envData.model);
throw new SilentQuit();
}
}
envData.usingMicrosoftCompiler = envData.ccompiler.toLower.endsWith("cl.exe");
version (Windows) {} else
{
version(X86_64)
envData.picFlag = ["-fPIC"];
if (environment.get("PIC", null) == "1")
envData.picFlag = ["-fPIC"];
}
switch (envData.compiler)
{
case "dmd":
case "ldc":
if(envData.os != "windows")
envData.cxxCompatFlags = " -L-lstdc++ -L--no-demangle";
break;
case "gdc":
envData.cxxCompatFlags = "-Xlinker -lstdc++ -Xlinker --no-demangle";
break;
default:
writeln("Unknown compiler: ", envData.compiler);
throw new SilentQuit();
}
return cast(immutable) envData;
}
/**
* Read the single-line test parameter `token` from the source code which
* might be defined multiple times. All definitions found will be joined
* into a single string using `multilineDelimiter` as a separator.
*
* This will skip conditional parameters declared as `<token>(<environment>)`
* if the specified environment doesn't match the passed `envData`, e.g.
*
* ---
* REQURIRED_ARGS(linux): -ignore
* PERMUTE_ARGS(windows64): -ignore
* ---
*
* Params:
* envData = environment data
* file = source code
* token = test parameter
* result = variable to store the parameter
* multilineDelimiter = separator for multiple declarations
*
* Returns: whether the parameter was found in the source code
*/
bool findTestParameter(const ref EnvData envData, string file, string token, ref string result, string multiLineDelimiter = " ")
{
auto tokenStart = std.string.indexOf(file, token);
if (tokenStart == -1) return false;
file = file[tokenStart + token.length .. $];
auto lineEndR = std.string.indexOf(file, "\r");
auto lineEndN = std.string.indexOf(file, "\n");
auto lineEnd = lineEndR == -1 ?
(lineEndN == -1 ? file.length : lineEndN) :
(lineEndN == -1 ? lineEndR : min(lineEndR, lineEndN));
//writeln("found ", token, " in line: ", file.length, ", ", tokenStart, ", ", tokenStart+lineEnd);
//writeln("found ", token, " in line: '", file[tokenStart .. tokenStart+lineEnd], "'");
result = file[0 .. lineEnd];
const commentStart = std.string.indexOf(result, "//");
if (commentStart != -1)
result = result[0 .. commentStart];
result = strip(result);
// filter by OS specific setting (os1 os2 ...)
if (result.startsWith("("))
{
auto close = std.string.indexOf(result, ")");
if (close >= 0)
{
string[] oss = split(result[1 .. close], " ");
// Check if the current environment matches an entry in oss, which can either
// be an OS (e.g. "linux") or a combination of OS + MODEL (e.g. "windows32").
// The latter is important on windows because m32 might require other
// parameters than m32mscoff/m64.
if (oss.canFind!(o => o.skipOver(envData.os) && (o.empty || o == envData.model)))
result = result[close + 1 .. $];
else
result = null;
}
}
// skips the :, if present
if (result.startsWith(":"))
result = strip(result[1 .. $]);
//writeln("arg: '", result, "'");
string result2;
if (findTestParameter(envData, file[lineEnd .. $], token, result2, multiLineDelimiter))
{
if (result2.length > 0)
{
if (result.length == 0)
result = result2;
else
result ~= multiLineDelimiter ~ result2;
}
}
// fix-up separators
result = result.unifyDirSep(envData.sep);
return true;
}
/**
* Read the multi-line test parameter `token` from the source code and joins
* multiple definitions into a single string.
*
* ```
* TEST_OUTPUT:
* ---
* Hello, World!
* ---
* ```
*
* Params:
* file = source code
* token = test parameter
* result = variable to store the parameter
* sep = platform-dependent directory separator
*
* Returns: whether the parameter was found in the source code
*/
bool findOutputParameter(string file, string token, out string result, string sep)
{
bool found = false;
while (true)
{
const istart = std.string.indexOf(file, token);
if (istart == -1)
break;
found = true;
file = file[istart + token.length .. $];
enum embed_sep = "---";
auto n = std.string.indexOf(file, embed_sep);
enforce(n != -1, "invalid "~token~" format");
n += embed_sep.length;
while (file[n] == '-') ++n;
if (file[n] == '\r') ++n;
if (file[n] == '\n') ++n;
file = file[n .. $];
auto iend = std.string.indexOf(file, embed_sep);
enforce(iend != -1, "invalid TEST_OUTPUT format");
result ~= file[0 .. iend];
while (file[iend] == '-') ++iend;
file = file[iend .. $];
}
if (found)
{
result = std.string.strip(result);
result = result.unifyNewLine().unifyDirSep(sep);
result = result ? result : ""; // keep non-null
}
return found;
}
/// Replaces the placeholer `${RESULTS_DIR}` with the actual path
/// to `test_results` stored in `envData`.
void replaceResultsDir(ref string arguments, const ref EnvData envData)
{
// Bash would expand this automatically on Posix, but we need to manually
// perform the replacement for Windows compatibility.
arguments = replace(arguments, "${RESULTS_DIR}", envData.results_dir);
}
/// Returns: the reason why this test is disabled or null if it isn't skipped.
string getDisabledReason(string[] disabledPlatforms, const ref EnvData envData)
{
if (disabledPlatforms.length == 0)
return null;
const target = ((envData.os == "windows") ? "win" : envData.os) ~ envData.model;
// allow partial matching, e.g. `win` to disable both win32 and win64
const i = disabledPlatforms.countUntil!(p => target.canFind(p));
if (i != -1)
return "on " ~ disabledPlatforms[i];
return null;
}
/**
* Reads the test configuration from the source code (using `findTestParameter` and
* `findOutputParameter`) and initializes `testArgs` accordingly. Also merges
* configurations/additional parameters specified in the environment, e.g.
* `REQUIRED_ARGS`.
*
* Params:
* testArgs = test configuration object
* input_dir = test directory (e.g. `runnable`)
* input_file = path to the source file
* envData = environment configurations
*
* Returns: whether this test should be executed (true) or skipped (false)
* Throws: Exception if the test configuration is invalid
*/
bool gatherTestParameters(ref TestArgs testArgs, string input_dir, string input_file, const ref EnvData envData)
{
string file = cast(string)std.file.read(input_file);
string dflagsStr;
testArgs.clearDflags = findTestParameter(envData, file, "DFLAGS", dflagsStr);
enforce(dflagsStr.empty, "The DFLAGS test argument must be empty: It is '" ~ dflagsStr ~ "'");
findTestParameter(envData, file, "REQUIRED_ARGS", testArgs.requiredArgs);
if (envData.required_args.length)
{
if (testArgs.requiredArgs.length)
testArgs.requiredArgs ~= " " ~ envData.required_args;
else
testArgs.requiredArgs = envData.required_args;
}
replaceResultsDir(testArgs.requiredArgs, envData);
if (! findTestParameter(envData, file, "PERMUTE_ARGS", testArgs.permuteArgs))
{
if (testArgs.mode == TestMode.RUN)
testArgs.permuteArgs = envData.all_args;
}
replaceResultsDir(testArgs.permuteArgs, envData);
// remove permute args enforced as required anyway
if (testArgs.requiredArgs.length && testArgs.permuteArgs.length)
{
const required = split(testArgs.requiredArgs);
const newPermuteArgs = split(testArgs.permuteArgs)
.filter!(a => !required.canFind(a))
.join(" ");
testArgs.permuteArgs = newPermuteArgs;
}
// tests can override -verrors by using REQUIRED_ARGS
if (testArgs.mode == TestMode.FAIL_COMPILE)
testArgs.requiredArgs = "-verrors=0 " ~ testArgs.requiredArgs;
{
string argSetsStr;
findTestParameter(envData, file, "ARG_SETS", argSetsStr, ";");
foreach(s; split(argSetsStr, ";"))
{
replaceResultsDir(s, envData);
testArgs.argSets ~= s;
}
}
// win(32|64) doesn't support pic
if (envData.os == "windows")
{
auto index = std.string.indexOf(testArgs.permuteArgs, "-fPIC");
if (index != -1)
testArgs.permuteArgs = testArgs.permuteArgs[0 .. index] ~ testArgs.permuteArgs[index+5 .. $];
}
// clean up extra spaces
testArgs.permuteArgs = strip(replace(testArgs.permuteArgs, " ", " "));
if (findTestParameter(envData, file, "EXECUTE_ARGS", testArgs.executeArgs))
{
replaceResultsDir(testArgs.executeArgs, envData);
// Always run main even if compiled with '-unittest' but let
// tests switch to another behaviour if necessary
if (!testArgs.executeArgs.canFind("--DRT-testmode"))
testArgs.executeArgs ~= " --DRT-testmode=run-main";
}
string extraSourcesStr;
findTestParameter(envData, file, "EXTRA_SOURCES", extraSourcesStr);
testArgs.sources = [input_file];
// prepend input_dir to each extra source file
foreach(s; split(extraSourcesStr))
testArgs.sources ~= input_dir ~ "/" ~ s;
{
string compiledImports;
findTestParameter(envData, file, "COMPILED_IMPORTS", compiledImports);
foreach(s; split(compiledImports))
testArgs.compiledImports ~= input_dir ~ "/" ~ s;
}
findTestParameter(envData, file, "CXXFLAGS", testArgs.cxxflags);
string extraCppSourcesStr;
findTestParameter(envData, file, "EXTRA_CPP_SOURCES", extraCppSourcesStr);
testArgs.cppSources = split(extraCppSourcesStr);
if (testArgs.cppSources.length)
testArgs.requiredArgs ~= envData.cxxCompatFlags;
string extraObjcSourcesStr;
auto objc = findTestParameter(envData, file, "EXTRA_OBJC_SOURCES", extraObjcSourcesStr);
if (objc && !envData.dobjc)
return false;
testArgs.objcSources = split(extraObjcSourcesStr);
// swap / with $SEP
if (envData.sep && envData.sep != "/")
foreach (ref s; testArgs.sources)
s = replace(s, "/", to!string(envData.sep));
//writeln ("sources: ", testArgs.sources);
{
string throwAway;
testArgs.link = findTestParameter(envData, file, "LINK", throwAway);
}
// COMPILE_SEPARATELY can take optional compiler switches when link .o files
testArgs.compileSeparately = findTestParameter(envData, file, "COMPILE_SEPARATELY", testArgs.requiredArgsForLink);
string disabledPlatformsStr;
findTestParameter(envData, file, "DISABLED", disabledPlatformsStr);
version (DragonFlyBSD)
{
// DragonFlyBSD is x86_64 only, instead of adding DISABLED to a lot of tests, just exclude them from running
if (testArgs.requiredArgs.canFind("-m32"))
testArgs.disabledReason = "on DragonFlyBSD (no -m32)";
}
version (ARM) enum supportsM64 = false;
else version (MIPS32) enum supportsM64 = false;
else version (PPC) enum supportsM64 = false;
else enum supportsM64 = true;
static if (!supportsM64)
{
if (testArgs.requiredArgs.canFind("-m64"))
testArgs.disabledReason = "because target doesn't support -m64";
}
if (!testArgs.isDisabled)
testArgs.disabledReason = getDisabledReason(split(disabledPlatformsStr), envData);
findTestParameter(envData, file, "TEST_OUTPUT_FILE", testArgs.compileOutputFile);
// Only check for TEST_OUTPUT is no file was given because it would
// partially match TEST_OUTPUT_FILE
if (testArgs.compileOutputFile)
{
// Don't require tests to specify the test directory
testArgs.compileOutputFile = input_dir.buildPath(testArgs.compileOutputFile);
testArgs.compileOutput = readText(testArgs.compileOutputFile)
.unifyNewLine() // Avoid CRLF issues
.strip();
// Only sanitize directory separators from file types that support standalone \
if (!testArgs.compileOutputFile.endsWith(".json"))
testArgs.compileOutput = testArgs.compileOutput.unifyDirSep(envData.sep);
}
else
findOutputParameter(file, "TEST_OUTPUT", testArgs.compileOutput, envData.sep);
string outFilesStr;
findTestParameter(envData, file, "OUTPUT_FILES", outFilesStr);
testArgs.outputFiles = outFilesStr.split(';');
findTestParameter(envData, file, "TRANSFORM_OUTPUT", testArgs.transformOutput);
findOutputParameter(file, "RUN_OUTPUT", testArgs.runOutput, envData.sep);
findOutputParameter(file, "GDB_SCRIPT", testArgs.gdbScript, envData.sep);
findTestParameter(envData, file, "GDB_MATCH", testArgs.gdbMatch);
if (findTestParameter(envData, file, "POST_SCRIPT", testArgs.postScript))
testArgs.postScript = replace(testArgs.postScript, "/", to!string(envData.sep));
return true;
}
/// Generates all permutations of the space-separated word contained in `argstr`
string[] combinations(string argstr)
{
string[] results;
string[] args = split(argstr);
long combinations = 1 << args.length;
for (size_t i = 0; i < combinations; i++)
{
string r;
bool printed = false;
for (size_t j = 0; j < args.length; j++)
{
if (i & 1 << j)
{
if (printed)
r ~= " ";
r ~= args[j];
printed = true;
}
}
results ~= r;
}
return results;
}
/// Tries to remove the file identified by `filename` and prints warning on failure
void tryRemove(in char[] filename)
{
if (auto ex = std.file.remove(filename).collectException())
debug writeln("WARNING: Failed to remove ", filename);
}
/**
* Executes `command` while logging the invocation and any output produced into f.
*
* Params:
* f = the logfile
* command = the command to execute
* expectPass = whether the command should succeed
*
* Returns: the output produced by `command`
* Throws:
* Exception if `command` returns another exit code than 0/1 (depending on expectPass)
*/
string execute(ref File f, string command, bool expectpass)
{
f.writeln(command);
const result = std.process.executeShell(command);
f.write(result.output);
if (result.status < 0)
{
enforce(false, "caught signal: " ~ to!string(result.status));
}
else
{
const exp = expectpass ? 0 : 1;
enforce(result.status == exp, format("Expected rc == %d, but exited with rc == %d", exp, result.status));
}
return result.output;
}
/// add quotes around the whole string if it contains spaces that are not in quotes
string quoteSpaces(string str)
{
if (str.indexOf(' ') < 0)
return str;
bool inquote = false;
foreach(dchar c; str)
if (c == '"')
inquote = !inquote;
else if (c == ' ' && !inquote)
return "\"" ~ str ~ "\"";
return str;
}
/// Replaces non-Unix line endings in `str` with `\n`
string unifyNewLine(string str)
{
// On Windows, Outbuffer.writenl() puts `\r\n` into the buffer,
// then fprintf() adds another `\r` when formatting the message.
// This is why there's a match for `\r\r\n` in this regex.
static re = regex(`\r\r\n|\r\n|\r|\n`, "g");
return std.regex.replace(str, re, "\n");
}
/**
Unifies a text `str` with words that could be DMD path references to a common
separator `sep`. This normalizes the text and allows comparing path output
results between different operating systems.
Params:
str = text to be unified
sep = unification separator to use
Returns: Text with path separator standardized to `sep`.
*/
string unifyDirSep(string str, string sep)
{
static void unifyWordFromBack(char[] r, char sep)
{
foreach_reverse(ref ch; r)
{
// stop at common word boundaries
if (ch == '\n' || ch == '\r' || ch == ' ')
break;
// normalize path characters
if (ch == '\\' || ch == '/')
ch = sep;
}
}
auto mStr = str.dup;
auto remaining = mStr;
alias needles = AliasSeq!(".d", ".di", ".mixin", ".c");
enum needlesArray = [needles];
// simple multi-delimiter word identification
while (!remaining.empty)
{
auto res = remaining.find(needles);
if (res[0].empty) break;
auto currentWord = remaining[0 .. res[0].ptr-remaining.ptr];
// skip over current word and matched delimiter
const needleLength = res[1] > 0 ? needlesArray[res[1] - 1].length : 0;
remaining = remaining[currentWord.length + needleLength .. $];
if (remaining.empty ||
remaining.startsWith(" ", "\n", "\r", "-mixin",
"(", ":", "'", "`", "\"", ".", ","))
unifyWordFromBack(currentWord, sep[0]);
}
return mStr.assumeUnique;
}
unittest
{
assert(`fail_compilation/test.d(1) Error: dummy error message for 'test'`.unifyDirSep(`\`)
== `fail_compilation\test.d(1) Error: dummy error message for 'test'`);
assert(`fail_compilation/test.d(1) Error: at fail_compilation/test.d(2)`.unifyDirSep(`\`)
== `fail_compilation\test.d(1) Error: at fail_compilation\test.d(2)`);
assert(`fail_compilation/test.d(1) Error: at fail_compilation/imports/test.d(2)`.unifyDirSep(`\`)
== `fail_compilation\test.d(1) Error: at fail_compilation\imports\test.d(2)`);
assert(`fail_compilation/diag.d(2): Error: fail_compilation/imports/fail.d must be imported`.unifyDirSep(`\`)
== `fail_compilation\diag.d(2): Error: fail_compilation\imports\fail.d must be imported`);
assert(`{{RESULTS_DIR}}/fail_compilation/mixin_test.mixin(7): Error:`.unifyDirSep(`\`)
== `{{RESULTS_DIR}}\fail_compilation\mixin_test.mixin(7): Error:`);
assert(`{{RESULTS_DIR}}/fail_compilation/mixin_test.d-mixin-50(7): Error:`.unifyDirSep(`\`)
== `{{RESULTS_DIR}}\fail_compilation\mixin_test.d-mixin-50(7): Error:`);
assert("runnable\\xtest46_gc.d-mixin-37(187): Error".unifyDirSep("/") == "runnable/xtest46_gc.d-mixin-37(187): Error");
// optional columns
assert(`{{RESULTS_DIR}}/fail_compilation/cols.d(12,7): Error:`.unifyDirSep(`\`)
== `{{RESULTS_DIR}}\fail_compilation\cols.d(12,7): Error:`);
// gnu style
assert(`fail_compilation/test.d:1: Error: dummy error message for 'test'`.unifyDirSep(`\`)
== `fail_compilation\test.d:1: Error: dummy error message for 'test'`);
// in quotes as well
assert("'imports\\foo.d'".unifyDirSep("/") == "'imports/foo.d'");
assert("`imports\\foo.d`".unifyDirSep("/") == "`imports/foo.d`");
assert("\"imports\\foo.d\"".unifyDirSep("/") == "\"imports/foo.d\"");
assert("fail_compilation\\foo.d: Error:".unifyDirSep("/") == "fail_compilation/foo.d: Error:");
// at the end of a sentence
assert("fail_compilation\\foo.d. A".unifyDirSep("/") == "fail_compilation/foo.d. A");
assert("fail_compilation\\foo.d(2). A".unifyDirSep("/") == "fail_compilation/foo.d(2). A");
assert("fail_compilation\\foo.d, A".unifyDirSep("/") == "fail_compilation/foo.d, A");
assert("fail_compilation\\foo.d(2), A".unifyDirSep("/") == "fail_compilation/foo.d(2), A");
assert("fail_compilation\\foo.d".unifyDirSep("/") == "fail_compilation/foo.d");
assert("fail_compilation\\foo.d\n".unifyDirSep("/") == "fail_compilation/foo.d\n");
assert("fail_compilation\\foo.d\r\n".unifyDirSep("/") == "fail_compilation/foo.d\r\n");
assert("\nfail_compilation\\foo.d".unifyDirSep("/") == "\nfail_compilation/foo.d");
assert("\r\nfail_compilation\\foo.d".unifyDirSep("/") == "\r\nfail_compilation/foo.d");
assert("fail_compilation\\imports\\cfoo.c. A".unifyDirSep("/") == "fail_compilation/imports/cfoo.c. A");
assert(("runnable\\xtest46_gc.d-mixin-37(220): Deprecation: `opDot` is deprecated. Use `alias this`\n"~
"runnable\\xtest46_gc.d-mixin-37(222): Deprecation: `opDot` is deprecated. Use `alias this`").unifyDirSep("/") ==
"runnable/xtest46_gc.d-mixin-37(220): Deprecation: `opDot` is deprecated. Use `alias this`\n"~
"runnable/xtest46_gc.d-mixin-37(222): Deprecation: `opDot` is deprecated. Use `alias this`");
assert("".unifyDirSep("/") == "");
assert(" \n ".unifyDirSep("/") == " \n ");
assert("runnable/xtest46_gc.d-mixin-$n$(222): ".unifyDirSep("\\") ==
"runnable\\xtest46_gc.d-mixin-$n$(222): ");
assert(`S('\xff').this(1)`.unifyDirSep("/") == `S('\xff').this(1)`);
assert(`invalid UTF character \U80000000`.unifyDirSep("/") == `invalid UTF character \U80000000`);
assert("https://code.dlang.org".unifyDirSep("\\") == "https://code.dlang.org");
}
/**
* Compiles all non-D sources using their respective compiler and flags
* and appends the generated objects to `sources`.
*
* Params:
* input_dir = test directory (e.g. `runnable`)
* output_dir = directory for intermediate files
* extraSources = sources to compile
* sources = list of D sources to extend with object files
* envData = environment configuration
* compiler = external compiler (E.g. clang)
* cxxflags = external compiler flags
* logfile = the logfile
*
* Returns: false if a compilation error occurred
*/
bool collectExtraSources (in string input_dir, in string output_dir, in string[] extraSources,
ref string[] sources, in EnvData envData, in string compiler,
const(char)[] cxxflags, ref File logfile)
{
foreach (cur; extraSources)
{
auto curSrc = input_dir ~ envData.sep ~"extra-files" ~ envData.sep ~ cur;
auto curObj = output_dir ~ envData.sep ~ cur ~ envData.obj;
string command = quoteSpaces(compiler);
if (envData.usingMicrosoftCompiler)
{
command ~= ` /c /nologo `~curSrc~` /Fo`~curObj;
}
else if (envData.compiler == "dmd" && envData.os == "windows" && envData.model == "32")
{
command ~= " -c "~curSrc~" -o"~curObj;
}
else
{
command ~= " -m"~envData.model~" -c "~curSrc~" -o "~curObj;
}
if (cxxflags)
command ~= " " ~ cxxflags;
logfile.writeln(command);
logfile.flush(); // Avoid reordering due to buffering
auto pid = spawnShell(command, stdin, logfile, logfile, null, Config.retainStdout | Config.retainStderr);
if(wait(pid))
{
return false;
}
sources ~= curObj;
}
return true;
}
/++
Applies custom transformations defined in transformOutput to testOutput.
Currently the following actions are supported:
* "sanitize_json" = replace compiler/plattform specific data from generated JSON
* "remove_lines(<re>)" = remove all lines matching a regex <re>
Params:
testOutput = the existing output to be modified
transformOutput = list of transformation identifiers
++/
void applyOutputTransformations(ref string testOutput, string transformOutput)
{
while (transformOutput.length)
{
string step, arg;
const idx = transformOutput.countUntil(' ', '(');
if (idx == -1)
{
step = transformOutput;
transformOutput = null;
}
else
{
step = transformOutput[0 .. idx];
const hasArgs = transformOutput[idx] == '(';
transformOutput = transformOutput[idx + 1 .. $];
if (hasArgs)
{
// "..." quotes are optional but necessary if the arg contains ')'
const isQuoted = transformOutput[0] == '"';
const end = isQuoted ? `"` : `)`;
auto parts = transformOutput[isQuoted .. $].findSplit(end);
enforce(parts, "Missing closing `" ~ end ~ "`!");
arg = parts[0];
transformOutput = parts[2][isQuoted .. $];
}
// Skip space between steps
import std.ascii : isWhite;
transformOutput.skipOver!isWhite();
}
switch (step)
{
case "sanitize_json":
{
import sanitize_json : sanitize;
sanitize(testOutput);
break;
}
case "remove_lines":
{
auto re = regex(arg);
testOutput = testOutput
.splitter('\n')
.filter!(line => !line.matchFirst(re))
.join('\n');
break;
}
default:
throw new Exception(format(`Unknown transformation: "%s"!`, step));
}
}
}
unittest
{
static void test(string input, const string transformations, const string expected)
{
applyOutputTransformations(input, transformations);
assert(input == expected);
}
static void testJson(const string transformations, const string expectedJson)
{
test(`{
"modules": [
{
"file": "/path/to/the/file",
"kind": "module",
"members": []
}
]
}`, transformations, expectedJson);
}
testJson("sanitize_json", `{
"modules": [
{
"file": "VALUE_REMOVED_FOR_TEST",
"kind": "module",
"members": []
}
]
}`);
testJson(`sanitize_json remove_lines("kind")`, `{
"modules": [
{
"file": "VALUE_REMOVED_FOR_TEST",
"members": []
}
]
}`);
testJson(`sanitize_json remove_lines("kind") remove_lines("file")`, `{
"modules": [
{
"members": []
}
]
}`);
test(`This is a text containing
some words which is a text sample
nevertheless`,
`remove_lines(text sample)`,
`This is a text containing
nevertheless`);
test(`This is a text with
a random ) which should
still work`,
`remove_lines("random \)")`,
`This is a text with
still work`);
test(`Tom bought
12 apples
and 6 berries
from the store`,
`remove_lines("(\d+)")`,
`Tom bought
from the store`);
assertThrown(test("", "unknown", ""));
}
/// List of supported special sequences used in compareOutput
alias specialSequences = AliasSeq!("$n$", "$p:", "$r:", "$?:");
/++
Compares the output string to the reference string by character
except parts marked with one of the following special sequences:
$n$ = numbers (e.g. compiler generated unique identifiers)
$p:<path>$ = real paths ending with <path>
$?:<choices>$ = environment dependent content supplied as a list
choices (either <condition>=<content> or <default>),
separated by a '|'. Currently supported conditions are
OS and model as supplied from the environment
$r:<regex>$ = text matching <regex> (using $ inside of regex is not
supported, use multiple regexes instead)
Params:
output = the real output
refoutput = the expected output
envData = test environment
Returns: whether output matches the expected refoutput
++/
bool compareOutput(string output, string refoutput, const ref EnvData envData)
{
// If no output is expected, only check that nothing was captured.
if (refoutput.length == 0)
return (output.length == 0) ? true : false;
for ( ; ; )
{
auto special = refoutput.find(specialSequences).rename!("remainder", "id");
// Simple equality check if no special tokens remain
if (special.id == 0)
return refoutput == output;
const expected = refoutput[0 .. $ - special.remainder.length];
// Check until the special token
if (!output.skipOver(expected))
return false;
// Discard the special token and progress output appropriately
refoutput = special.remainder[3 .. $];
if (special.id == 1) // $n$
{
import std.ascii : isDigit;
output.skipOver!isDigit();
continue;
}
// $<identifier>:<special content>$
/// ( special content, "$", remaining expected output )
auto refparts = refoutput.findSplit("$");
enforce(refparts, "Malformed special sequence!");
refoutput = refparts[2];
if (special.id == 2) // $p:<some path>$
{
// special content is the expected path tail
// Substitute / with the appropriate directory separator
auto pathEnd = refparts[0].replace("/", envData.sep);
/// ( whole path, remaining output )
auto parts = output.findSplitAfter(pathEnd);
if (parts[0].empty || !exists(parts[0])) {
return false;
}
output = parts[1];
continue;
}
else if (special.id == 3) // $r:<regex>$
{
// need some context behind this expression to stop the regex match
// e.g. "$r:.*$ failed with..." uses " failed"
auto context = refoutput[0 .. min(7, $)];
const parts = context.findSplitBefore("$");
// Avoid collisions with other special sequences
if (!parts[1].empty)
{
context = parts[0];
enforce(context.length, "Another sequence following $r:...$ is not supported!");
}
// Remove the context from the remaining expected output
refoutput = refoutput[context.length .. $];
// Use '^' to match <regex><context> at the beginning of output
auto re = regex('^' ~ refparts[0] ~ context, "s");
auto match = output.matchFirst(re);
if (!match)
return false;
output = output[match.front.length .. $];
continue;
}
// $?:<predicate>=<content>(;<predicate>=<content>)*(;<default>)?$
string toSkip = null;
foreach (const chunk; refparts[0].splitter('|'))
{
// ( <predicate> , "=", <content> )
const searchResult = chunk.findSplit("=");
if (searchResult[1].empty) // <default>
{
toSkip = chunk;
break;
}
// Match against OS or model (accepts "32mscoff" as "32")
else if (searchResult[0].splitter('+').all!(c => c.among(envData.os, envData.model, envData.model[0 .. min(2, $)])))
{
toSkip = searchResult[2];
break;
}
}
if (toSkip !is null && !output.skipOver(toSkip))
return false;
}
}
unittest
{
EnvData ed;
version (Windows)
ed.sep = `\`;
else
ed.sep = `/`;
assert( compareOutput(`Grass is green`, `Grass is green`, ed));
assert(!compareOutput(`Grass is green`, `Grass was green`, ed));
assert( compareOutput(`Bob took 12 apples`, `Bob took $n$ apples`, ed));
assert(!compareOutput(`Bob took abc apples`, `Bob took $n$ apples`, ed));
assert(!compareOutput(`Bob took 12 berries`, `Bob took $n$ apples`, ed));
assert( compareOutput(`HINT: ` ~ __FILE_FULL_PATH__ ~ ` is important`, `HINT: $p:d_do_test.d$ is important`, ed));
assert( compareOutput(`HINT: ` ~ __FILE_FULL_PATH__ ~ ` is important`, `HINT: $p:test/tools/d_do_test.d$ is important`, ed));
ed.sep = "/";
assert(!compareOutput(`See /path/to/druntime/import/object.d`, `See $p:druntime/import/object.d$`, ed));
assertThrown(compareOutput(`Path /a/b/c.d!`, `Path $p:c.d!`, ed)); // Missing closing $
const fmt = "This $?:windows=A|posix=B|C$ uses $?:64=1|32=2|3$ bytes";
assert( compareOutput("This C uses 3 bytes", fmt, ed));
ed.os = "posix";
ed.model = "64";
assert( compareOutput("This B uses 1 bytes", fmt, ed));
assert(!compareOutput("This C uses 3 bytes", fmt, ed));
const emptyFmt = "On <$?:windows=abc|$> use <$?:posix=$>!";
assert(compareOutput("On <> use <>!", emptyFmt, ed));
ed.model = "32mscoff";
assert(compareOutput("size_t is uint!", "size_t is $?:32=uint|64=ulong$!", ed));
assert(compareOutput("no", "$?:posix+64=yes|no$", ed));
ed.model = "64";
assert(compareOutput("yes", "$?:posix+64=yes|no$", ed));
assert(compareOutput("This number 12", `This $r:\w+ \d+$`, ed));
assert(compareOutput("This number 12", `This $r:\w+ (\d)+$`, ed));
assert(compareOutput("This number 12 is nice", `This $r:.*$ 12 is nice`, ed));
assert(compareOutput("This number 12", `This $r:.*$ 12`, ed));
assert(!compareOutput("This number 12 is 24", `This $r:\d*$ 12`, ed));
assert(compareOutput("This number 12 is 24", `This $r:.*$ 12 is $n$`, ed));
string msg = collectExceptionMsg(compareOutput("12345", `$r:\d*$$n$`, ed));
assert(msg == "Another sequence following $r:...$ is not supported!");
}
/++
Creates a diff of the expected and actual test output.
Params:
expected = the expected output
expectedFile = file containing expected (if present, null otherwise)
actual = the actual output
name = the test files name
Returns: the comparison created by the `diff` utility
++/
string generateDiff(const string expected, string expectedFile,
const string actual, const string name)
{
string actualFile = tempDir.buildPath("actual_" ~ name);
File(actualFile, "w").writeln(actual); // Append \n
scope (exit) tryRemove(actualFile);
const needTmp = !expectedFile;
if (needTmp) // Create a temporary file
{
expectedFile = tempDir.buildPath("expected_" ~ name);
File(expectedFile, "w").writeln(expected); // Append \n
}
// Remove temporary file
scope (exit) if (needTmp)
tryRemove(expectedFile);
const cmd = ["diff", "-pu", "--strip-trailing-cr", expectedFile, actualFile];
try
{
string diff = std.process.execute(cmd).output;
// Skip diff's status lines listing the diffed files and line count
foreach (_; 0..3)
diff = diff.findSplitAfter("\n")[1];
return diff;
}
catch (Exception e)
return format(`%-(%s, %) failed: %s`, cmd, e.msg);
}
/**
* Exception thrown to abort the test without further error messages
* (they were either already printed or suppressed due to the environment)
*/
class SilentQuit : Exception { this() { super(null); } }
/**
* Exception thrown when the actual output doesn't match the expected
* `TEST_OUTPUT`/`RUN_OUTPUT.`
*/
class CompareException : Exception
{
string expected; /// expected output
string actual; /// actual output
bool fromRun; /// Compared execution instead of compilation output
this(string expected, string actual, string diff, bool fromRun = false) {
string msg = "\nexpected:\n----\n" ~ expected ~
"\n----\nactual:\n----\n" ~ actual ~
"\n----\ndiff:\n----\n" ~ diff ~ "----\n";
super(msg);
this.expected = expected;
this.actual = actual;
this.fromRun = fromRun;
}
}
/// Return code indicating that the test should be restarted.
/// Issued when an OUTPUT section was changed due to AUTO_UPDATE=1.
enum RERUN_TEST = 2;
version(unittest) void main(){} else
int main(string[] args)
{
try
{
// Test may be run multiple times with AUTO_UPDATE=1 because updates
// to output sections may change line numbers.
// Set a hard limit to avoid infinite loops in fringe cases
foreach (_; 0 .. 10)
{
const res = tryMain(args);
if (res == RERUN_TEST)
writeln("==> Restarting test to verify new output section(s)...\n");
else
return res;
}
// Should never happen, but just to be sure
writeln("Output sections changed too many times, please update manually.");
return RERUN_TEST;
}
catch(SilentQuit) { return 1; }
}
int tryMain(string[] args)
{
if (args.length != 2)
{
usage();
return 1;
}
immutable envData = processEnvironment();
const input_file = args[1];
const input_dir = input_file.dirName();
const test_base_name = input_file.baseName();
const test_name = test_base_name.stripExtension();
const result_path = envData.results_dir ~ envData.sep;
const output_dir = result_path ~ input_dir;
const output_file = result_path ~ input_file ~ ".out";
TestArgs testArgs;
switch (input_dir)
{
case "compilable": testArgs.mode = TestMode.COMPILE; break;
case "fail_compilation": testArgs.mode = TestMode.FAIL_COMPILE; break;
case "runnable", "runnable_cxx":
// running & linking costs time - for coverage builds we can save this
testArgs.mode = envData.coverage_build ? TestMode.COMPILE : TestMode.RUN;
break;
case "dshell":
testArgs.mode = TestMode.DSHELL;
return runDShellTest(input_dir, test_name, envData, output_dir, output_file);
default:
writefln("Error: invalid test directory '%s', expected 'compilable', 'fail_compilation', 'runnable', 'runnable_cxx' or 'dshell'", input_dir);
return 1;
}
if (test_base_name.extension() == ".sh")
{
string file = cast(string) std.file.read(input_file);
string disabledPlatforms;
if (findTestParameter(envData, file, "DISABLED", disabledPlatforms))
{
const reason = getDisabledReason(split(disabledPlatforms), envData);
if (reason.length != 0)
{
writefln(" ... %-30s [DISABLED %s]", input_file, reason);
return 0;
}
}
version (linux)
{
string gdbScript;
findTestParameter(envData, file, "GDB_SCRIPT", gdbScript);
if (gdbScript !is null)
{
return runGDBTestWithLock(envData, () {
return runBashTest(input_dir, test_name, envData);
});
}
}
return runBashTest(input_dir, test_name, envData);
}
// envData.sep is required as the results_dir path can be `generated`
const absoluteResultDirPath = envData.results_dir.absolutePath ~ envData.sep;
const resultsDirReplacement = "{{RESULTS_DIR}}" ~ envData.sep;
const test_app_dmd_base = output_dir ~ envData.sep ~ test_name ~ "_";
auto stopWatch = StopWatch(AutoStart.no);
if (envData.printRuntime)
stopWatch.start();
if (!gatherTestParameters(testArgs, input_dir, input_file, envData))
return 0;
// Clear the DFLAGS environment variable if it was specified in the test file
if (testArgs.clearDflags)
{
// `environment["DFLAGS"] = "";` doesn't seem to work on Win32 (might be a bug
// in std.process). So, resorting to `putenv` in snn.lib
version(Win32)
{
putenv("DFLAGS=");
}
else
{
environment["DFLAGS"] = "";
}
}
writef(" ... %-30s %s%s(%s)",
input_file,
testArgs.requiredArgs,
(!testArgs.requiredArgs.empty ? " " : ""),
testArgs.permuteArgs);
if (testArgs.isDisabled)
{
writef("!!! [DISABLED %s]", testArgs.disabledReason);
if (!envData.tryDisabled)
{
writeln();
return 0;
}
}
auto f = File(output_file, "w");
if (
//prepare cpp extra sources
!collectExtraSources(input_dir, output_dir, testArgs.cppSources, testArgs.sources, envData, envData.ccompiler, testArgs.cxxflags, f) ||
//prepare objc extra sources
!collectExtraSources(input_dir, output_dir, testArgs.objcSources, testArgs.sources, envData, "clang", null, f)
)
{
writeln();
// Ignore failed test
if (testArgs.isDisabled)
return 0;
printTestFailure(input_file, f);
return 1;
}
enum Result { continue_, return0, return1, returnRerun }
// Runs the test with a specific combination of arguments
Result testCombination(bool autoCompileImports, string argSet, size_t permuteIndex, string permutedArgs)
{
string test_app_dmd = test_app_dmd_base ~ to!string(permuteIndex) ~ envData.exe;
string command; // copy of the last executed command so that it can be re-invoked on failures
try
{
string[] toCleanup;
auto thisRunName = output_file ~ to!string(permuteIndex);
auto fThisRun = File(thisRunName, "w");
scope(exit)
{
fThisRun.close();
f.write(readText(thisRunName));
f.writeln();
tryRemove(thisRunName); // Never reached unless file is present
}
string compile_output;
if (!testArgs.compileSeparately)
{
string objfile = output_dir ~ envData.sep ~ test_name ~ "_" ~ to!string(permuteIndex) ~ envData.obj;
toCleanup ~= objfile;
command = format("%s -conf= -m%s -I%s %s %s -od%s -of%s %s %s%s %s", envData.dmd, envData.model, input_dir,
testArgs.requiredArgs, permutedArgs, output_dir,
(testArgs.mode == TestMode.RUN || testArgs.link ? test_app_dmd : objfile),
argSet,
(testArgs.mode == TestMode.RUN || testArgs.link ? "" : "-c "),
join(testArgs.sources, " "),
(autoCompileImports ? "-i" : join(testArgs.compiledImports, " ")));
try
compile_output = execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
catch (Exception e)
{
writeln(""); // We're at "... runnable/xxxx.d (args)"
printCppSources(testArgs.sources);
throw e;
}
}
else
{
foreach (filename; testArgs.sources ~ (autoCompileImports ? null : testArgs.compiledImports))
{
string newo = output_dir ~ envData.sep ~ replace(filename.baseName(), ".d", envData.obj);
toCleanup ~= newo;
command = format("%s -conf= -m%s -I%s %s %s -od%s -c %s %s", envData.dmd, envData.model, input_dir,
testArgs.requiredArgs, permutedArgs, output_dir, argSet, filename);
compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
}
if (testArgs.mode == TestMode.RUN || testArgs.link)
{
// link .o's into an executable
command = format("%s -conf= -m%s%s%s %s %s -od%s -of%s %s", envData.dmd, envData.model,
autoCompileImports ? " -i" : "",
autoCompileImports ? "extraSourceIncludePaths" : "",
envData.required_args, testArgs.requiredArgsForLink, output_dir, test_app_dmd, join(toCleanup, " "));
execute(fThisRun, command, true);
}
}
void prepare(ref string compile_output)
{
if (compile_output.empty)
return;
compile_output = compile_output.unifyNewLine();
compile_output = std.regex.replaceAll(compile_output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), "");
compile_output = std.string.strip(compile_output);
// replace test_result path with fixed ones
compile_output = compile_output.replace(result_path, resultsDirReplacement);
compile_output = compile_output.replace(absoluteResultDirPath, resultsDirReplacement);
compile_output.applyOutputTransformations(testArgs.transformOutput);
}
prepare(compile_output);
auto m = std.regex.match(compile_output, `Internal error: .*$`);
enforce(!m, m.hit);
m = std.regex.match(compile_output, `core.exception.AssertError@dmd.*`);
enforce(!m, m.hit);
// Prepare and append the content of each OUTPUT_FILE conforming to
// the HAR (https://code.dlang.org/packages/har) format, e.g.
// === <FILENAME_1>
// <CONTENT_1>
// === <FILENAME_2>
// <CONTENT_2>
// ...
foreach (const outfile; testArgs.outputFiles)
{
string path = outfile;
replaceResultsDir(path, envData);
// Don't abort if a file is missing, at least verify the remaining output.
string content = readText(path).ifThrown("<< File missing >>");
prepare(content);
// Make sure file starts on a new line
if (!compile_output.empty && !compile_output.endsWith("\n"))
compile_output ~= '\n';
// Prepend a header listing the explicit file
compile_output.reserve(outfile.length + content.length + 5);
compile_output ~= "=== ";
compile_output ~= outfile;
compile_output ~= '\n';
compile_output ~= content;
}
if (!compareOutput(compile_output, testArgs.compileOutput, envData))
{
const diff = generateDiff(testArgs.compileOutput, testArgs.compileOutputFile,
compile_output, test_base_name);
throw new CompareException(testArgs.compileOutput, compile_output, diff);
}
if (testArgs.mode == TestMode.RUN)
{
toCleanup ~= test_app_dmd;
version(Windows)
if (envData.usingMicrosoftCompiler)
{
toCleanup ~= test_app_dmd_base ~ to!string(permuteIndex) ~ ".ilk";
toCleanup ~= test_app_dmd_base ~ to!string(permuteIndex) ~ ".pdb";
}
if (testArgs.gdbScript is null)
{
command = test_app_dmd;
if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs;
const output = execute(fThisRun, command, true)
.strip()
.unifyNewLine();
if (testArgs.runOutput && !compareOutput(output, testArgs.runOutput, envData))
{
const diff = generateDiff(testArgs.runOutput, null, output, test_base_name);
throw new CompareException(testArgs.runOutput, output, diff, true);
}
}
else version (linux)
{
runGDBTestWithLock(envData, () {
auto script = test_app_dmd_base ~ to!string(permuteIndex) ~ ".gdb";
toCleanup ~= script;
with (File(script, "w"))
{
writeln("set disable-randomization off");
write(testArgs.gdbScript);
}
string gdbCommand = "gdb "~test_app_dmd~" --batch -x "~script;
auto gdb_output = execute(fThisRun, gdbCommand, true);
if (testArgs.gdbMatch !is null)
{
enforce(match(gdb_output, regex(testArgs.gdbMatch)),
"\nGDB regex: '"~testArgs.gdbMatch~"' didn't match output:\n----\n"~gdb_output~"\n----\n");
}
return 0;
});
}
}
fThisRun.close();
if (testArgs.postScript && !envData.coverage_build)
{
f.write("Executing post-test script: ");
string prefix = "";
version (Windows) prefix = "bash ";
execute(f, prefix ~ "tools/postscript.sh " ~ testArgs.postScript ~ " " ~ input_dir ~ " " ~ test_name ~ " " ~ thisRunName, true);
}
foreach (file; chain(toCleanup, testArgs.outputFiles))
tryRemove(file);
return Result.continue_;
}
catch(Exception e)
{
// it failed but it was disabled, exit as if it was successful
if (testArgs.isDisabled)
{
writeln();
return Result.return0;
}
if (envData.autoUpdate)
if (auto ce = cast(CompareException) e)
{
// remove the output file in test_results as its outdated
// (might fail for runnable tests on Windows)
if (output_file.remove().collectException())
writef("\nWARNING: Failed to remove `%s`!", output_file);
// Don't overwrite TEST_OUTPUT sections which contain special
// sequences because they must be manually adapted
if (testArgs.compileOutput.canFind(specialSequences))
{
writefln("\nWARNING: %s uses special sequences in `TEST_OUTPUT` blocks and can't be auto-updated", input_file);
return Result.return0;
}
if (testArgs.compileOutputFile && !ce.fromRun)
{
std.file.write(testArgs.compileOutputFile, ce.actual);
writefln("\n==> `TEST_OUTPUT_FILE` `%s` has been updated", testArgs.compileOutputFile);
return Result.returnRerun;
}
auto existingText = input_file.readText;
auto updatedText = existingText.replace(ce.expected, ce.actual);
const type = ce.fromRun ? `RUN`: `TEST`;
if (existingText != updatedText)
{
std.file.write(input_file, updatedText);
writefln("\n==> `%s_OUTPUT` of %s has been updated", type, input_file);
return Result.returnRerun;
}
else
{
writefln("\nWARNING: %s has multiple `%s_OUTPUT` blocks and can't be auto-updated", input_file, type);
return Result.return0;
}
}
const outputText = printTestFailure(input_file, f, e.msg);
// auto-update if a diff is found and can be updated
if (envData.autoUpdate &&
outputText.canFind("diff ") && outputText.canFind("--- ") && outputText.canFind("+++ "))
{
import std.range : dropOne;
auto newFile = outputText.findSplitAfter("+++ ")[1].until("\t");
auto baseFile = outputText.findSplitAfter("--- ")[1].until("\t");
writefln("===> Updating %s with %s", baseFile, newFile);
newFile.copy(baseFile);
return Result.return0;
}
// automatically rerun a segfaulting test and print its stack trace
version(linux)
if (e.msg.canFind("exited with rc == 139"))
{
auto gdbCommand = "gdb -q -n -ex 'set backtrace limit 100' -ex run -ex bt -batch -args " ~ command;
runGDBTestWithLock(envData, () => spawnShell(gdbCommand).wait);
}
return Result.return1;
}
}
size_t index = 0; // index over all tests to avoid identical output names in consecutive tests
auto argSets = (testArgs.argSets.length == 0) ? [""] : testArgs.argSets;
for(auto autoCompileImports = false;; autoCompileImports = true)
{
foreach(argSet; argSets)
{
foreach (c; combinations(testArgs.permuteArgs))
{
final switch(testCombination(autoCompileImports, argSet, index, c))
{
case Result.continue_: break;
case Result.return0: return 0;
case Result.return1: return 1;
case Result.returnRerun: return RERUN_TEST;
}
index++;
}
}
if(autoCompileImports || testArgs.compiledImports.length == 0)
break;
}
if (envData.printRuntime)
{
const long ms = stopWatch.peek.total!"msecs";
writefln(" [%.3f secs]", ms / 1000.0);
}
else
writeln();
// it was disabled but it passed! print an informational message
if (testArgs.isDisabled)
writefln(" !!! %-30s DISABLED but PASSES!", input_file);
return 0;
}
/**
* Executes a bash script (deprecated in favour of `dshell` tests).
*
* Params:
* input_dir = test directory (e.g. `runnable`)
* test_name = script filename
* envData = environment configuration
*
* Returns: the script's exit code
*/
int runBashTest(string input_dir, string test_name, const ref EnvData envData)
{
enum script = "tools/sh_do_test.sh";
version(Windows)
{
const cmd = "bash " ~ script ~ ' ' ~ input_dir ~ ' ' ~ test_name;
const env = [
// Make sure the path is bash-friendly
"DMD": envData.dmd.relativePath(dmdTestDir).replace("\\", "/")
];
auto process = spawnShell(cmd, env, Config.none, dmdTestDir);
}
else
{
const scriptPath = dmdTestDir.buildPath(script);
auto process = spawnProcess([scriptPath, input_dir, test_name]);
}
return process.wait();
}
/**
* Executes `fun` mutually exclusive to other instances of `d_do_test`
* using the lockfile `$RESULTS_DIR/gdb.lock`.
*
* Params:
* envData = environment configuration
* fun = task to execute
*
* Returns: the return value of `fun`
*/
int runGDBTestWithLock(const ref EnvData envData, int delegate() fun)
{
// Tests failed on SemaphoreCI when multiple GDB tests were run at once
scope lockfile = File(envData.results_dir.buildPath("gdb.lock"), "w");
lockfile.lock();
scope (exit) lockfile.unlock();
return fun();
}
/**
* Executes a `dshell` test.
*
* Params:
* input_dir = test directory (e.g. `runnable`)
* test_name = script filename
* envData = environment configuration
* output_dir = directory for intermediate files (usually `${RESULTS_DIR}/dshell`)
* output_file = logfile path
*
* Returns: the script's exit code (or dmd's exit code upon compilation failure)
*/
int runDShellTest(string input_dir, string test_name, const ref EnvData envData,
string output_dir, string output_file)
{
const testScriptDir = buildPath(dmdTestDir, input_dir);
const testScriptPath = buildPath(testScriptDir, test_name ~ ".d");
const testOutDir = buildPath(output_dir, test_name);
const testLogName = format("%s/%s.d", input_dir, test_name);
writefln(" ... %s", testLogName);
if (exists(testOutDir))
rmdirRecurse(testOutDir);
mkdirRecurse(testOutDir);
// create the "dshell" module for the tests
{
auto dshellFile = File(buildPath(testOutDir, "dshell.d"), "w");
dshellFile.writeln(`module dshell;
public import dshell_prebuilt;
static this()
{
dshellPrebuiltInit("` ~ input_dir ~ `", "`, test_name , `");
}
`);
}
const testScriptExe = buildPath(testOutDir, "run" ~ envData.exe);
auto outfile = File(output_file, "w");
enum keepFilesOpen = Config.retainStdout | Config.retainStderr;
//
// compile the test
//
{
const compile = [envData.dmd, "-conf=", "-m"~envData.model] ~
envData.picFlag ~ [
"-od" ~ testOutDir,
"-of" ~ testScriptExe,
"-I=" ~ testScriptDir,
"-I=" ~ testOutDir,
"-I=" ~ buildPath(dmdTestDir, "tools", "dshell_prebuilt"),
"-i",
// Causing linker errors for some reason?
"-i=-dshell_prebuilt", buildPath(envData.results_dir, "dshell_prebuilt" ~ envData.obj),
testScriptPath,
];
outfile.writeln("[COMPILE_TEST] ", escapeShellCommand(compile));
// Note that spawnprocess closes the file, so it will need to be re-opened
// below when we run the test
auto compileProc = std.process.spawnProcess(compile, stdin, outfile, outfile, null, keepFilesOpen);
const exitCode = wait(compileProc);
if (exitCode != 0)
{
printTestFailure(testLogName, outfile);
return exitCode;
}
}
//
// run the test
//
{
const runTest = [testScriptExe];
outfile.writeln("[RUN_TEST] ", escapeShellCommand(runTest));
auto runTestProc = std.process.spawnProcess(runTest, stdin, outfile, outfile, null, keepFilesOpen);
const exitCode = wait(runTestProc);
if (exitCode == 125) // = DISABLED from tools/dshell_prebuilt.d
{
writefln(" !!! %s is disabled!", testLogName);
return 0;
}
else if (exitCode != 0)
{
printTestFailure(testLogName, outfile);
return exitCode;
}
}
return 0;
}
/**
* Prints the summary of a test failure to stdout and removes the logfile.
*
* Params:
* testLogName = name of the test
* outfile = the logfile
* extra = supplemental error message
* Returns: the content of outfile
**/
string printTestFailure(string testLogName, scope ref File outfile, string extra = null)
{
const output_file_temp = outfile.name;
outfile.close();
writeln("==============================");
writefln("Test '%s' failed. The logged output:", testLogName);
const output = readText(output_file_temp);
write(output);
if (!output.endsWith("\n"))
writeln();
writeln("==============================");
if (extra)
writefln("Test '%s' failed: %s\n", testLogName, extra);
tryRemove(output_file_temp);
return output;
}
/**
* Print symbols in C++ objects
*
* If linking failed, we print the symbols present in the C++ object file being
* linked it. This is so that C++ `runnable` tests are easier to debug,
* as the CI machines can have different environment than the users,
* and it is generally painful to work with them when trying to support
* newer (C++11, C++14, C++17, etc...) features.
*/
void printCppSources (in const(char)[][] compiled)
{
version (Posix)
{
foreach (file; compiled)
{
if (!file.endsWith(".cpp.o"))
continue;
writeln("========== Symbols for C++ object file: ", file, " ==========");
std.process.spawnProcess(["nm", file]).wait();
}
}
}
| D |
/**
* D header file for GNU/Linux
*
* Authors: Martin Nowak
*/
module core.sys.linux.config;
version (linux):
public import core.sys.posix.config;
// man 7 feature_test_macros
// http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
enum _GNU_SOURCE = true;
// deduced <features.h>
// http://sourceware.org/git/?p=glibc.git;a=blob;f=include/features.h
enum _DEFAULT_SOURCE = true;
enum _ATFILE_SOURCE = true;
// _BSD_SOURCE and _SVID_SOURCE are deprecated aliases for _DEFAULT_SOURCE.
deprecated("use _DEFAULT_SOURCE")
{
enum _BSD_SOURCE = true;
enum _SVID_SOURCE = true;
}
enum __USE_MISC = _DEFAULT_SOURCE;
enum __USE_ATFILE = _ATFILE_SOURCE;
enum __USE_GNU = _GNU_SOURCE;
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto B = new char[][N];
foreach (i; 0..N) B[i] = readln.chomp.to!(char[]);
int x, y;
foreach (i; 0..N) {
foreach (j; 0..N) {
if (B[j][i] == 'X') {
x += j;
}
if (B[j][i] == 'Y') {
y += N-j-1;
}
}
}
writeln(x > y ? "X" : x < y ? "Y" : "Impossible");
} | D |
/run/media/sacha/stocky/isousb/isousb/target/debug/deps/byteorder-5b7a3e8dfe96d9b3.rmeta: /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/lib.rs /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/io.rs
/run/media/sacha/stocky/isousb/isousb/target/debug/deps/libbyteorder-5b7a3e8dfe96d9b3.rlib: /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/lib.rs /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/io.rs
/run/media/sacha/stocky/isousb/isousb/target/debug/deps/byteorder-5b7a3e8dfe96d9b3.d: /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/lib.rs /home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/io.rs
/home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/lib.rs:
/home/sacha/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.4/src/io.rs:
| D |
module ppl4.Operator;
import ppl4.all;
/**
* Operator precedence. Lower is higher.
*/
enum Operator {
NONE,
LITERAL,
DOT, // .
CALL, // call()
//INDEX, // get(), set() same as call()
CAST, // as Type
DIV, // /
MUL, // *
MOD, // %
ADD, // +
SUB, // -
SHL, // shl
SHR, // shr
USHR, // ushr
ROL, // rol
ROR, // ror
UGT, // ugt
UGTE, // ugte
ULT, // ult
ULTE, // ulte
BITAND, // &
BITOR, // |
BITXOR, // ^
ASSIGN, // = // do we need this here?
REASSIGN, // :=
DIV_ASSIGN, // /=
MUL_ASSIGN, // *=
MOD_ASSIGN, // %=
ADD_ASSIGN, // +=
SUB_ASSIGN, // -=
SHL_ASSIGN, // shl=
SHR_ASSIGN, // shr=
USHR_ASSIGN, // ushr=
BITAND_ASSIGN, // &=
BITOR_ASSIGN, // |=
BITXOR_ASSIGN, // ^=
EQ, // == // operator overloadable
NE, // != // operator overloadable
IS, // is
LT, // <
LTE, // <=
GT, // >
GTE, // >=
AND, // and
OR, // or
ASSERT, // assert
NUMBER, //
TYPE_EXPRESSION,//
IDENTIFIER, //
PARENS //
}
int precedenceOf(Operator o) {
final switch(o) with(Operator) {
case DOT: return 2;
case CALL: return 2;
case CAST: return 5;
case DIV: return 14;
case MUL: return 14;
case MOD: return 14;
case ADD: return 15;
case SUB: return 15;
case SHL: return 15;
case SHR: return 15;
case USHR: return 15;
case ROL: return 15;
case ROR: return 15;
case BITAND: return 15;
case BITOR: return 15;
case BITXOR: return 15;
case EQ: return 18;
case NE: return 18;
case IS: return 18;
case LT: return 18;
case LTE: return 18;
case GT: return 18;
case GTE: return 18;
case UGT: return 15;
case UGTE: return 15;
case ULT: return 15;
case ULTE: return 15;
case AND: return 21;
case OR: return 21;
case ASSIGN: return 40;
case REASSIGN: return 40;
case DIV_ASSIGN: return 40;
case MUL_ASSIGN: return 40;
case MOD_ASSIGN: return 40;
case ADD_ASSIGN: return 40;
case SUB_ASSIGN: return 40;
case SHL_ASSIGN: return 40;
case SHR_ASSIGN: return 40;
case USHR_ASSIGN: return 40;
case BITAND_ASSIGN: return 40;
case BITOR_ASSIGN: return 40;
case BITXOR_ASSIGN: return 40;
case ASSERT: return 50;
case NUMBER: return 50;
case TYPE_EXPRESSION: return 50;
case IDENTIFIER: return 50;
case PARENS: return 50;
case NONE: return 50;
case LITERAL: return 50;
}
}
Operator toOperator(ParseState state) {
auto k = state.kind();
switch(k) with(TokenKind) {
case FSLASH: return Operator.DIV;
case ASTERISK: return Operator.MUL;
case PERCENT: return Operator.MOD;
case PLUS: return Operator.ADD;
case MINUS: return Operator.SUB;
case PIPE: return Operator.BITOR;
case AMPERSAND: return Operator.BITAND;
case HAT: return Operator.BITXOR;
case COLON_EQUALS: return Operator.REASSIGN;
case LARROW: return Operator.LT;
case LARROW_EQ: return Operator.LTE;
case RARROW: return Operator.GT;
case RARROW_EQ: return Operator.GTE;
case DBL_EQUALS: return Operator.EQ;
case BANG_EQUALS: return Operator.NE;
default: break;
}
switch(state.text()) {
case "and": return Operator.AND;
case "or": return Operator.OR;
case "shl": return Operator.SHL;
case "shr": return Operator.SHR;
case "ushr": return Operator.USHR;
case "rol": return Operator.ROL;
case "ror": return Operator.ROR;
case "ugt": return Operator.UGT;
case "ugte": return Operator.UGTE;
case "ult": return Operator.ULT;
case "ulte": return Operator.ULTE;
default: break;
}
return Operator.NONE;
}
bool isBoolean(Operator o) {
switch(o) with(Operator) {
case OR:
case AND:
case EQ:
case NE:
case GT:
case GTE:
case LT:
case LTE:
case UGT:
case UGTE:
case ULT:
case ULTE:
return true;
default:
return false;
}
assert(false);
}
bool isAssign(Operator o) {
switch(o) with(Operator) {
case ASSIGN:
case REASSIGN:
case DIV_ASSIGN:
case MUL_ASSIGN:
case MOD_ASSIGN:
case ADD_ASSIGN:
case SUB_ASSIGN:
case SHL_ASSIGN:
case SHR_ASSIGN:
case USHR_ASSIGN:
case BITAND_ASSIGN:
case BITOR_ASSIGN:
case BITXOR_ASSIGN:
return true;
default:
return false;
}
assert(false);
}
bool isPtrArithmetic(Operator o) {
// todo
return false;
} | D |
/*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage
/*
* Conversion parameters:
* inFile =
* outPack = gio
* outFile = UnixMountMonitor
* strct = GUnixMountMonitor
* realStrct=
* ctorStrct=
* clss = UnixMountMonitor
* interf =
* class Code: No
* interface Code: No
* template for:
* extend =
* implements:
* prefixes:
* - g_unix_mount_monitor_
* omit structs:
* omit prefixes:
* omit code:
* omit signals:
* imports:
* structWrap:
* module aliases:
* local aliases:
* overrides:
*/
module gtkD.gio.UnixMountMonitor;
public import gtkD.gtkc.giotypes;
private import gtkD.gtkc.gio;
private import gtkD.glib.ConstructionException;
private import gtkD.gobject.Signals;
public import gtkD.gtkc.gdktypes;
private import gtkD.gobject.ObjectG;
/**
* Description
* Routines for managing mounted UNIX mount points and paths.
* Note that <gio/gunixmounts.h> belongs to the
* UNIX-specific GIO interfaces, thus you have to use the
* gio-unix-2.0.pc pkg-config file when using it.
*/
public class UnixMountMonitor : ObjectG
{
/** the main Gtk struct */
protected GUnixMountMonitor* gUnixMountMonitor;
public GUnixMountMonitor* getUnixMountMonitorStruct()
{
return gUnixMountMonitor;
}
/** the main Gtk struct as a void* */
protected override void* getStruct()
{
return cast(void*)gUnixMountMonitor;
}
/**
* Sets our main struct and passes it to the parent class
*/
public this (GUnixMountMonitor* gUnixMountMonitor)
{
if(gUnixMountMonitor is null)
{
this = null;
return;
}
//Check if there already is a D object for this gtk struct
void* ptr = getDObject(cast(GObject*)gUnixMountMonitor);
if( ptr !is null )
{
this = cast(UnixMountMonitor)ptr;
return;
}
super(cast(GObject*)gUnixMountMonitor);
this.gUnixMountMonitor = gUnixMountMonitor;
}
/**
*/
int[char[]] connectedSignals;
void delegate(UnixMountMonitor)[] onMountpointsChangedListeners;
/**
* Emitted when the unix mount points have changed.
*/
void addOnMountpointsChanged(void delegate(UnixMountMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
{
if ( !("mountpoints-changed" in connectedSignals) )
{
Signals.connectData(
getStruct(),
"mountpoints-changed",
cast(GCallback)&callBackMountpointsChanged,
cast(void*)this,
null,
connectFlags);
connectedSignals["mountpoints-changed"] = 1;
}
onMountpointsChangedListeners ~= dlg;
}
extern(C) static void callBackMountpointsChanged(GUnixMountMonitor* monitorStruct, UnixMountMonitor unixMountMonitor)
{
foreach ( void delegate(UnixMountMonitor) dlg ; unixMountMonitor.onMountpointsChangedListeners )
{
dlg(unixMountMonitor);
}
}
void delegate(UnixMountMonitor)[] onMountsChangedListeners;
/**
* Emitted when the unix mounts have changed.
*/
void addOnMountsChanged(void delegate(UnixMountMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
{
if ( !("mounts-changed" in connectedSignals) )
{
Signals.connectData(
getStruct(),
"mounts-changed",
cast(GCallback)&callBackMountsChanged,
cast(void*)this,
null,
connectFlags);
connectedSignals["mounts-changed"] = 1;
}
onMountsChangedListeners ~= dlg;
}
extern(C) static void callBackMountsChanged(GUnixMountMonitor* monitorStruct, UnixMountMonitor unixMountMonitor)
{
foreach ( void delegate(UnixMountMonitor) dlg ; unixMountMonitor.onMountsChangedListeners )
{
dlg(unixMountMonitor);
}
}
/**
* Gets a new GUnixMountMonitor. The default rate limit for which the
* monitor will report consecutive changes for the mount and mount
* point entry files is the default for a GFileMonitor. Use
* g_unix_mount_monitor_set_rate_limit() to change this.
* Throws: ConstructionException GTK+ fails to create the object.
*/
public this ()
{
// GUnixMountMonitor * g_unix_mount_monitor_new (void);
auto p = g_unix_mount_monitor_new();
if(p is null)
{
throw new ConstructionException("null returned by g_unix_mount_monitor_new()");
}
this(cast(GUnixMountMonitor*) p);
}
/**
* Sets the rate limit to which the mount_monitor will report
* consecutive change events to the mount and mount point entry files.
* Since 2.18
* Params:
* limitMsec = a integer with the limit in milliseconds to
* poll for changes.
*/
public void setRateLimit(int limitMsec)
{
// void g_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount_monitor, int limit_msec);
g_unix_mount_monitor_set_rate_limit(gUnixMountMonitor, limitMsec);
}
}
| D |
void main() {
auto N = ri;
int[] C, S, F;
foreach(i; 0..N-1) {
auto ip = readAs!(int[]), c = ip[0], s = ip[1], f = ip[2];
C ~= c; S ~= s; F ~= f;
}
foreach(i; 0..N-1) {
long tmp;
foreach(j; i..N-1) {
if(tmp < S[j]) tmp = S[j];
else if(tmp % F[j] != 0) tmp += F[j] - tmp % F[j];
tmp += C[j];
debug writefln("tmp: %d, i: %d, j: %d", tmp, i, j);
}
tmp.writeln;
}
0.writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
| D |
/**
A static HTTP file server.
Copyright: © 2012 RejectedSoftware e.K.
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Sönke Ludwig
*/
module vibe.http.fileserver;
import vibe.core.file;
import vibe.core.log;
import vibe.http.server;
import vibe.inet.message;
import vibe.inet.mimetypes;
import vibe.inet.url;
import std.conv;
import std.datetime;
import std.digest.md;
import std.string;
/**
Returns a request handler that serves files from the specified directory.
See_Also: serveStaticFile
*/
HTTPServerRequestDelegate serveStaticFiles(Path local_path, HTTPFileServerSettings settings = null)
{
if (!settings) settings = new HTTPFileServerSettings;
if (!settings.serverPathPrefix.endsWith("/")) settings.serverPathPrefix ~= "/";
void callback(HTTPServerRequest req, HTTPServerResponse res)
{
string srv_path;
if (auto pp = "pathMatch" in req.params) srv_path = *pp;
else if (req.path.length > 0) srv_path = req.path;
else srv_path = req.requestURL;
if (!srv_path.startsWith(settings.serverPathPrefix)) {
logDebug("path '%s' not starting with '%s'", srv_path, settings.serverPathPrefix);
return;
}
auto rel_path = srv_path[settings.serverPathPrefix.length .. $];
auto rpath = Path(rel_path);
logTrace("Processing '%s'", srv_path);
rpath.normalize();
logDebug("Path '%s' -> '%s'", rel_path, rpath.toNativeString());
if (rpath.empty) {
// TODO: support searching for an index file
return;
} else if (rpath.absolute) {
logDebug("Path is absolute, not responding");
return;
} else if (rpath[0] == "..") return; // don't respond to relative paths outside of the root path
sendFile(req, res, local_path ~ rpath, settings);
}
return &callback;
}
/// ditto
HTTPServerRequestDelegate serveStaticFiles(string local_path, HTTPFileServerSettings settings = null)
{
return serveStaticFiles(Path(local_path), settings);
}
///
unittest {
import vibe.http.fileserver;
import vibe.http.router;
import vibe.http.server;
void setupServer()
{
auto router = new URLRouter;
// add other routes here
router.get("*", serveStaticFiles("public/"));
auto settings = new HTTPServerSettings;
listenHTTP(settings, router);
}
}
/** This example serves all files in the "public" sub directory
with an added prefix "static/" so that they don't interfere
with other registered routes.
*/
unittest {
import vibe.http.fileserver;
import vibe.http.router;
import vibe.http.server;
void setupRoutes()
{
auto router = new URLRouter;
// add other routes here
auto fsettings = new HTTPFileServerSettings;
fsettings.serverPathPrefix = "/static";
router.get("static/*", serveStaticFiles("public/", fsettings));
auto settings = new HTTPServerSettings;
listenHTTP(settings, router);
}
}
/**
Returns a request handler that serves a specific file on disk.
See_Also: serveStaticFiles
*/
HTTPServerRequestDelegate serveStaticFile(Path local_path, HTTPFileServerSettings settings = null)
{
if (!settings) settings = new HTTPFileServerSettings;
assert(settings.serverPathPrefix == "/", "serverPathPrefix is not supported for single file serving.");
void callback(HTTPServerRequest req, HTTPServerResponse res)
{
sendFile(req, res, local_path, settings);
}
return &callback;
}
/// ditto
HTTPServerRequestDelegate serveStaticFile(string local_path, HTTPFileServerSettings settings = null)
{
return serveStaticFile(Path(local_path), settings);
}
/**
Configuration options for the static file server.
*/
class HTTPFileServerSettings {
string serverPathPrefix = "/";
Duration maxAge;// = hours(24);
bool failIfNotFound = false;
string[string] encodingFileExtension;
/**
Called just before headers and data are sent.
Allows headers to be customized, or other custom processing to be performed.
Note: Any changes you make to the response, physicalPath, or anything
else during this function will NOT be verified by Vibe.d for correctness.
Make sure any alterations you make are complete and correct according to HTTP spec.
*/
void delegate(HTTPServerRequest req, HTTPServerResponse res, ref string physicalPath) preWriteCallback = null;
this()
{
// need to use the contructor because the Ubuntu 13.10 GDC cannot CTFE dur()
maxAge = 24.hours;
}
this(string path_prefix)
{
this();
serverPathPrefix = path_prefix;
}
}
private void sendFile(HTTPServerRequest req, HTTPServerResponse res, Path path, HTTPFileServerSettings settings)
{
auto pathstr = path.toNativeString();
// return if the file does not exist
if( !existsFile(pathstr) ){
if( settings.failIfNotFound ) throw new HTTPStatusException(HTTPStatus.NotFound);
else return;
}
FileInfo dirent;
try dirent = getFileInfo(pathstr);
catch(Exception){
throw new HTTPStatusException(HTTPStatus.InternalServerError, "Failed to get information for the file due to a file system error.");
}
if (dirent.isDirectory) {
logDebugV("Hit directory when serving files, ignoring: %s", pathstr);
if( settings.failIfNotFound ) throw new HTTPStatusException(HTTPStatus.NotFound);
else return;
}
auto lastModified = toRFC822DateTimeString(dirent.timeModified.toUTC());
// simple etag generation
auto etag = "\"" ~ hexDigest!MD5(pathstr ~ ":" ~ lastModified ~ ":" ~ to!string(dirent.size)).idup ~ "\"";
res.headers["Last-Modified"] = lastModified;
res.headers["Etag"] = etag;
if (settings.maxAge > seconds(0)) {
auto expireTime = Clock.currTime(UTC()) + settings.maxAge;
res.headers["Expires"] = toRFC822DateTimeString(expireTime);
res.headers["Cache-Control"] = "max-age="~to!string(settings.maxAge.total!"seconds");
}
if( auto pv = "If-Modified-Since" in req.headers ) {
if( *pv == lastModified ) {
res.statusCode = HTTPStatus.NotModified;
res.writeVoidBody();
return;
}
}
if( auto pv = "If-None-Match" in req.headers ) {
if ( *pv == etag ) {
res.statusCode = HTTPStatus.NotModified;
res.writeVoidBody();
return;
}
}
auto mimetype = getMimeTypeForFile(pathstr);
// avoid double-compression
if ("Content-Encoding" in res.headers && isCompressedFormat(mimetype))
res.headers.remove("Content-Encoding");
res.headers["Content-Type"] = mimetype;
res.headers["Content-Length"] = to!string(dirent.size);
// check for already encoded file if configured
string encodedFilepath;
auto pce = "Content-Encoding" in res.headers;
if (pce) {
if (auto pfe = *pce in settings.encodingFileExtension) {
assert((*pfe).length > 0);
auto p = pathstr ~ *pfe;
if (existsFile(p))
encodedFilepath = p;
}
}
if (encodedFilepath.length) {
auto origLastModified = dirent.timeModified.toUTC();
try dirent = getFileInfo(encodedFilepath);
catch(Exception){
throw new HTTPStatusException(HTTPStatus.InternalServerError, "Failed to get information for the file due to a file system error.");
}
// encoded file must be younger than original else warn
if (dirent.timeModified.toUTC() >= origLastModified){
logTrace("Using already encoded file '%s' -> '%s'", path, encodedFilepath);
path = Path(encodedFilepath);
res.headers["Content-Length"] = to!string(dirent.size);
} else {
logWarn("Encoded file '%s' is older than the original '%s'. Ignoring it.", encodedFilepath, path);
encodedFilepath = null;
}
}
if(settings.preWriteCallback)
settings.preWriteCallback(req, res, pathstr);
// for HEAD responses, stop here
if( res.isHeadResponse() ){
res.writeVoidBody();
assert(res.headerWritten);
logDebug("sent file header %d, %s!", dirent.size, res.headers["Content-Type"]);
return;
}
// else write out the file contents
//logTrace("Open file '%s' -> '%s'", srv_path, pathstr);
FileStream fil;
try {
fil = openFile(path);
} catch( Exception e ){
// TODO: handle non-existant files differently than locked files?
logDebug("Failed to open file %s: %s", pathstr, e.toString());
return;
}
scope(exit) fil.close();
if (pce && !encodedFilepath.length)
res.bodyWriter.write(fil);
else res.writeRawBody(fil);
logTrace("sent file %d, %s!", fil.size, res.headers["Content-Type"]);
}
| D |
/*
EXTRA_SOURCES: imports/A16a.d
RUN_OUTPUT:
---
class AA16
class B16
---
*/
import std.stdio;
class AA16
{
protected:
this()
{
printf("class AA16\n");
}
}
| D |
module org.serviio.util.XmlUtils;
import java.lang.String;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class XmlUtils
{
private static Logger log;
static this()
{
log = LoggerFactory.getLogger!(XmlUtils);
}
public static String objectToXMLType(Object object)
{
if (object !is null)
{
if (( cast(String)object !is null )) {
return cast(String)object;
}
if (( cast(Integer)object !is null )) {
return (cast(Integer)object).toString();
}
return object.toString();
}
return null;
}
public static String getStringFromDocument(Document doc, bool omitXmlDeclaration)
{
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
try
{
Transformer transformer = tf.newTransformer();
if (omitXmlDeclaration) {
transformer.setOutputProperty("omit-xml-declaration", "yes");
}
transformer.transform(domSource, result);
}
catch (TransformerException e)
{
throw new RuntimeException(e);
}
return writer.toString();
}
public static bool validateXML(String xmlId, URL schemaURL, String xml)
{
Source xmlFile = new StreamSource(new StringReader(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
try
{
Schema schema = schemaFactory.newSchema(schemaURL);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
return true;
}
catch (SAXException e)
{
log.error(java.lang.String.format("XML %s didn't pass validation, reason: %s", cast(Object[])[ xmlId, e.getLocalizedMessage() ]));
return false;
}
catch (IOException e)
{
log.error(java.lang.String.format("Cannot validate XML %s, reason: %s", cast(Object[])[ xmlId, e.getMessage() ]));
}
return false;
}
public static String decodeXml(String decodedXml)
{
String result = decodedXml.replaceAll("<", "<");
result = result.replaceAll(">", ">");
return result;
}
}
/* Location: C:\Users\Main\Downloads\serviio.jar
* Qualified Name: org.serviio.util.XmlUtils
* JD-Core Version: 0.7.0.1
*/ | D |
/Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/Objects-normal/x86_64/GBHNotificationName.o : /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHAssetImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHNotificationName.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePickerDelegate.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerConfig.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHImageViewAsynchLoading.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHAlbumTableViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHPhotoCollectionViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookAlbum.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAppearanceManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHImageCacheManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHFacebookManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAssetManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookAlbumPicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookNavigationController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHPhotoPickerViewController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerCustomError.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHSelectedView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFURL.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/GBHFacebookImagePicker/GBHFacebookImagePicker-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/Bolts/Bolts-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKCoreKit/FBSDKCoreKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKLoginKit/FBSDKLoginKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTaskCompletionSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfile.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkResolving.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMutableCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLink.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAccessToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkNavigation.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestConnection.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKTestUsersManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFWebViewAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphErrorRecoveryProcessor.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFExecutor.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKSettings.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask+Exceptions.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMacros.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/Bolts.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkTarget.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManagerLoginResult.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestDataAttachment.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFMeasurementEvent.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequest.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfilePictureView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKUtility.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.h /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/unextended-module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/Bolts.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKCoreKit.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKLoginKit.build/module.modulemap
/Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/Objects-normal/x86_64/GBHNotificationName~partial.swiftmodule : /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHAssetImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHNotificationName.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePickerDelegate.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerConfig.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHImageViewAsynchLoading.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHAlbumTableViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHPhotoCollectionViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookAlbum.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAppearanceManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHImageCacheManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHFacebookManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAssetManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookAlbumPicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookNavigationController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHPhotoPickerViewController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerCustomError.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHSelectedView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFURL.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/GBHFacebookImagePicker/GBHFacebookImagePicker-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/Bolts/Bolts-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKCoreKit/FBSDKCoreKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKLoginKit/FBSDKLoginKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTaskCompletionSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfile.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkResolving.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMutableCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLink.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAccessToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkNavigation.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestConnection.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKTestUsersManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFWebViewAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphErrorRecoveryProcessor.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFExecutor.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKSettings.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask+Exceptions.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMacros.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/Bolts.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkTarget.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManagerLoginResult.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestDataAttachment.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFMeasurementEvent.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequest.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfilePictureView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKUtility.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.h /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/unextended-module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/Bolts.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKCoreKit.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKLoginKit.build/module.modulemap
/Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/Objects-normal/x86_64/GBHNotificationName~partial.swiftdoc : /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHAssetImage.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHNotificationName.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePickerDelegate.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerConfig.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHImageViewAsynchLoading.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHAlbumTableViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHPhotoCollectionViewCell.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookAlbum.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAppearanceManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHImageCacheManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHFacebookManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Manager/GBHAssetManager.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookImagePicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookAlbumPicker.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHFacebookNavigationController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Controller/GBHPhotoPickerViewController.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/Model/GBHFacebookPickerCustomError.swift /Users/nabil/Downloads/AlbumsMnager/Pods/GBHFacebookImagePicker/GBHFacebookImagePicker/Classes/View/GBHSelectedView.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFURL.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/GBHFacebookImagePicker/GBHFacebookImagePicker-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/Bolts/Bolts-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKCoreKit/FBSDKCoreKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Target\ Support\ Files/FBSDKLoginKit/FBSDKLoginKit-umbrella.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTaskCompletionSource.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfile.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkResolving.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMutableCopying.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLink.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAccessToken.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkNavigation.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestConnection.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginButton.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKTestUsersManager.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFWebViewAppLinkResolver.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphErrorRecoveryProcessor.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFExecutor.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKSettings.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/BFTask+Exceptions.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKMacros.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/Common/Bolts.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginConstants.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkTarget.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManagerLoginResult.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequestDataAttachment.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFMeasurementEvent.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphRequest.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKProfilePictureView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginTooltipView.h /Users/nabil/Downloads/AlbumsMnager/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererView.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKUtility.h /Users/nabil/Downloads/AlbumsMnager/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.h /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/GBHFacebookImagePicker.build/unextended-module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/Bolts.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKCoreKit.build/module.modulemap /Users/nabil/Downloads/AlbumsMnager/Build/Intermediates/Pods.build/Debug-iphonesimulator/FBSDKLoginKit.build/module.modulemap
| D |
the right to buy or sell property at an agreed price
one of a number of things from which only one can be chosen
the act of choosing or selecting
| D |
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96869
// { dg-do compile }
__vector(float[0]) var01;
// { dg-error "0 byte vector type '__vector\\\(float\\\[0\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float[3]) var02;
// { dg-error "12 byte vector type '__vector\\\(float\\\[3\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float[][4]) var03;
// { dg-error "vector type '__vector\\\(float\\\[\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float[4][4]) var04;
// { dg-error "vector type '__vector\\\(float\\\[4\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float[float][4]) var05;
// { dg-error "vector type '__vector\\\(float\\\[float\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float function()[4]) var06;
// { dg-error "vector type '__vector\\\(float function\\\(\\\)\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(float delegate()[4]) var07;
// { dg-error "vector type '__vector\\\(float delegate\\\(\\\)\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
enum E { a, b, c }
__vector(E[4]) var08;
// { dg-error "vector type '__vector\\\(E\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
struct S { float a; }
__vector(S[4]) var09;
// { dg-error "vector type '__vector\\\(S\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
class C { float a; }
__vector(C[4]) var10;
// { dg-error "vector type '__vector\\\(C\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(cfloat[4]) var11;
// { dg-error "vector type '__vector\\\(cfloat\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(bool[4]) var12;
// { dg-error "vector type '__vector\\\(bool\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
__vector(real[128]) var13;
// { dg-error "vector type '__vector\\\(real\\\[128\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 }
| D |
/*
Copyright (c) 2019-2022 Timur Gafarov
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
module dagon.postproc.shaders.present;
import std.stdio;
import dlib.core.memory;
import dlib.core.ownership;
import dlib.math.vector;
import dlib.math.matrix;
import dlib.math.transformation;
import dlib.math.interpolation;
import dlib.image.color;
import dlib.text.str;
import dagon.core.bindings;
import dagon.graphics.shader;
import dagon.graphics.state;
class PresentShader: Shader
{
String vs, fs;
this(Owner owner)
{
vs = Shader.load("data/__internal/shaders/Present/Present.vert.glsl");
fs = Shader.load("data/__internal/shaders/Present/Present.frag.glsl");
auto myProgram = New!ShaderProgram(vs, fs, this);
super(myProgram, owner);
}
~this()
{
vs.free();
fs.free();
}
override void bindParameters(GraphicsState* state)
{
// Texture 0 - color buffer
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, state.colorTexture);
setParameter("colorBuffer", 0);
// Texture 1 - depth buffer
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, state.depthTexture);
setParameter("depthBuffer", 1);
glActiveTexture(GL_TEXTURE0);
super.bindParameters(state);
}
override void unbindParameters(GraphicsState* state)
{
super.unbindParameters(state);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
}
}
| D |
/**
* Windows API header module
*
* Translated from MinGW Windows headers
*
* Authors: Stewart Gordon
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(DRUNTIMESRC core/sys/windows/_ole.d)
*/
module core.sys.windows.ole;
version (Windows):
pragma(lib, "ole32");
import core.sys.windows.windef, core.sys.windows.wingdi, core.sys.windows.uuid;
alias LPCSTR OLE_LPCSTR;
/+#define LRESULT LONG
#define HGLOBAL HANDLE+/
enum {
OT_LINK = 1,
OT_EMBEDDED,
OT_STATIC
}
enum OLEVERB_PRIMARY = 0;
enum OF_SET = 1;
enum OF_GET = 2;
enum OF_HANDLER = 4;
struct OLETARGETDEVICE {
USHORT otdDeviceNameOffset;
USHORT otdDriverNameOffset;
USHORT otdPortNameOffset;
USHORT otdExtDevmodeOffset;
USHORT otdExtDevmodeSize;
USHORT otdEnvironmentOffset;
USHORT otdEnvironmentSize;
BYTE _otdData;
BYTE* otdData() return { return &_otdData; }
}
alias OLETARGETDEVICE* LPOLETARGETDEVICE;
enum OLESTATUS {
OLE_OK,
OLE_WAIT_FOR_RELEASE,
OLE_BUSY,
OLE_ERROR_PROTECT_ONLY,
OLE_ERROR_MEMORY,
OLE_ERROR_STREAM,
OLE_ERROR_STATIC,
OLE_ERROR_BLANK,
OLE_ERROR_DRAW,
OLE_ERROR_METAFILE,
OLE_ERROR_ABORT,
OLE_ERROR_CLIPBOARD,
OLE_ERROR_FORMAT,
OLE_ERROR_OBJECT,
OLE_ERROR_OPTION,
OLE_ERROR_PROTOCOL,
OLE_ERROR_ADDRESS,
OLE_ERROR_NOT_EQUAL,
OLE_ERROR_HANDLE,
OLE_ERROR_GENERIC,
OLE_ERROR_CLASS,
OLE_ERROR_SYNTAX,
OLE_ERROR_DATATYPE,
OLE_ERROR_PALETTE,
OLE_ERROR_NOT_LINK,
OLE_ERROR_NOT_EMPTY,
OLE_ERROR_SIZE,
OLE_ERROR_DRIVE,
OLE_ERROR_NETWORK,
OLE_ERROR_NAME,
OLE_ERROR_TEMPLATE,
OLE_ERROR_NEW,
OLE_ERROR_EDIT,
OLE_ERROR_OPEN,
OLE_ERROR_NOT_OPEN,
OLE_ERROR_LAUNCH,
OLE_ERROR_COMM,
OLE_ERROR_TERMINATE,
OLE_ERROR_COMMAND,
OLE_ERROR_SHOW,
OLE_ERROR_DOVERB,
OLE_ERROR_ADVISE_NATIVE,
OLE_ERROR_ADVISE_PICT,
OLE_ERROR_ADVISE_RENAME,
OLE_ERROR_POKE_NATIVE,
OLE_ERROR_REQUEST_NATIVE,
OLE_ERROR_REQUEST_PICT,
OLE_ERROR_SERVER_BLOCKED,
OLE_ERROR_REGISTRATION,
OLE_ERROR_ALREADY_REGISTERED,
OLE_ERROR_TASK,
OLE_ERROR_OUTOFDATE,
OLE_ERROR_CANT_UPDATE_CLIENT,
OLE_ERROR_UPDATE,
OLE_ERROR_SETDATA_FORMAT,
OLE_ERROR_STATIC_FROM_OTHER_OS,
OLE_ERROR_FILE_VER,
OLE_WARN_DELETE_DATA = 1000
}
enum OLE_NOTIFICATION {
OLE_CHANGED,
OLE_SAVED,
OLE_CLOSED,
OLE_RENAMED,
OLE_QUERY_PAINT,
OLE_RELEASE,
OLE_QUERY_RETRY
}
enum OLE_RELEASE_METHOD {
OLE_NONE,
OLE_DELETE,
OLE_LNKPASTE,
OLE_EMBPASTE,
OLE_SHOW,
OLE_RUN,
OLE_ACTIVATE,
OLE_UPDATE,
OLE_CLOSE,
OLE_RECONNECT,
OLE_SETUPDATEOPTIONS,
OLE_SERVERUNLAUNCH,
OLE_LOADFROMSTREAM,
OLE_SETDATA,
OLE_REQUESTDATA,
OLE_OTHER,
OLE_CREATE,
OLE_CREATEFROMTEMPLATE,
OLE_CREATELINKFROMFILE,
OLE_COPYFROMLNK,
OLE_CREATEFROMFILE,
OLE_CREATEINVISIBLE
}
enum OLEOPT_RENDER {
olerender_none,
olerender_draw,
olerender_format
}
alias WORD OLECLIPFORMAT;
enum OLEOPT_UPDATE {
oleupdate_always,
oleupdate_onsave,
oleupdate_oncall,
// #ifdef OLE_INTERNAL
oleupdate_onclose
// #endif
}
mixin DECLARE_HANDLE!("HOBJECT");
alias LONG_PTR LHSERVER, LHCLIENTDOC, LHSERVERDOC;
struct OLEOBJECTVTBL {
extern (Windows) {
void* function(LPOLEOBJECT, OLE_LPCSTR) QueryProtocol;
OLESTATUS function(LPOLEOBJECT) Release;
OLESTATUS function(LPOLEOBJECT, BOOL) Show;
OLESTATUS function(LPOLEOBJECT, UINT, BOOL, BOOL) DoVerb;
OLESTATUS function(LPOLEOBJECT, OLECLIPFORMAT, HANDLE*) GetData;
OLESTATUS function(LPOLEOBJECT, OLECLIPFORMAT, HANDLE) SetData;
OLESTATUS function(LPOLEOBJECT, HGLOBAL) SetTargetDevice;
OLESTATUS function(LPOLEOBJECT, RECT*) SetBounds;
OLECLIPFORMAT function(LPOLEOBJECT, OLECLIPFORMAT) EnumFormats;
OLESTATUS function(LPOLEOBJECT, LOGPALETTE*) SetColorScheme;
//#ifndef SERVERONLY
OLESTATUS function(LPOLEOBJECT) Delete;
OLESTATUS function(LPOLEOBJECT, OLE_LPCSTR, OLE_LPCSTR) SetHostNames;
OLESTATUS function(LPOLEOBJECT, LPOLESTREAM) SaveToStream;
OLESTATUS function(LPOLEOBJECT, LPOLECLIENT, LHCLIENTDOC, OLE_LPCSTR,
LPOLEOBJECT*) Clone;
OLESTATUS function(LPOLEOBJECT, LPOLECLIENT, LHCLIENTDOC, OLE_LPCSTR,
LPOLEOBJECT*) CopyFromLink;
OLESTATUS function(LPOLEOBJECT, LPOLEOBJECT) Equal;
OLESTATUS function(LPOLEOBJECT) CopyToClipboard;
OLESTATUS function(LPOLEOBJECT, HDC, RECT*, RECT*, HDC) Draw;
OLESTATUS function(LPOLEOBJECT, UINT, BOOL, BOOL, HWND, RECT*)
Activate;
OLESTATUS function(LPOLEOBJECT, HGLOBAL, UINT) Execute;
OLESTATUS function(LPOLEOBJECT) Close;
OLESTATUS function(LPOLEOBJECT) Update;
OLESTATUS function(LPOLEOBJECT) Reconnect;
OLESTATUS function(LPOLEOBJECT, OLE_LPCSTR, LPOLECLIENT, LHCLIENTDOC,
OLE_LPCSTR, LPOLEOBJECT*) ObjectConvert;
OLESTATUS function(LPOLEOBJECT, OLEOPT_UPDATE*) GetLinkUpdateOptions;
OLESTATUS function(LPOLEOBJECT, OLEOPT_UPDATE) SetLinkUpdateOptions;
OLESTATUS function(LPOLEOBJECT, OLE_LPCSTR) Rename;
OLESTATUS function(LPOLEOBJECT, LPSTR, UINT*) QueryName;
OLESTATUS function(LPOLEOBJECT, LONG*) QueryType;
OLESTATUS function(LPOLEOBJECT, RECT*) QueryBounds;
OLESTATUS function(LPOLEOBJECT, DWORD*) QuerySize;
OLESTATUS function(LPOLEOBJECT) QueryOpen;
OLESTATUS function(LPOLEOBJECT) QueryOutOfDate;
OLESTATUS function(LPOLEOBJECT) QueryReleaseStatus;
OLESTATUS function(LPOLEOBJECT) QueryReleaseError;
OLE_RELEASE_METHOD function(LPOLEOBJECT) QueryReleaseMethod;
OLESTATUS function(LPOLEOBJECT, OLECLIPFORMAT) RequestData;
OLESTATUS function(LPOLEOBJECT, UINT, LONG*) ObjectLong;
OLESTATUS function(LPOLEOBJECT, HANDLE, LPOLECLIENT, BOOL) ChangeData;
//#endif
}
}
alias OLEOBJECTVTBL* LPOLEOBJECTVTBL;
//#ifndef OLE_INTERNAL
struct OLEOBJECT {
LPOLEOBJECTVTBL lpvtbl;
}
alias OLEOBJECT* LPOLEOBJECT;
//#endif
struct OLECLIENTVTBL {
extern (Windows) int function(LPOLECLIENT, OLE_NOTIFICATION, LPOLEOBJECT) CallBack;
}
alias OLECLIENTVTBL* LPOLECLIENTVTBL;
struct OLECLIENT {
LPOLECLIENTVTBL lpvtbl;
}
alias OLECLIENT* LPOLECLIENT;
struct OLESTREAMVTBL {
extern (Windows):
DWORD function(LPOLESTREAM, void*, DWORD) Get;
DWORD function(LPOLESTREAM, void*, DWORD) Put;
}
alias OLESTREAMVTBL* LPOLESTREAMVTBL;
struct OLESTREAM {
LPOLESTREAMVTBL lpstbl;
}
alias OLESTREAM* LPOLESTREAM;
enum OLE_SERVER_USE {
OLE_SERVER_MULTI,
OLE_SERVER_SINGLE
}
struct OLESERVERVTBL {
extern (Windows):
OLESTATUS function(LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, LPOLESERVERDOC*)
Open;
OLESTATUS function(LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR,
LPOLESERVERDOC*) Create;
OLESTATUS function(LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR,
OLE_LPCSTR, LPOLESERVERDOC*) CreateFromTemplate;
OLESTATUS function(LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR,
LPOLESERVERDOC*) Edit;
OLESTATUS function(LPOLESERVER) Exit;
OLESTATUS function(LPOLESERVER) Release;
OLESTATUS function(LPOLESERVER, HGLOBAL) Execute;
}
alias TypeDef!(OLESERVERVTBL*) LPOLESERVERVTBL;
struct OLESERVER {
LPOLESERVERVTBL lpvtbl;
}
alias OLESERVER* LPOLESERVER;
struct OLESERVERDOCVTBL {
extern (Windows):
OLESTATUS function(LPOLESERVERDOC) Save;
OLESTATUS function(LPOLESERVERDOC) Close;
OLESTATUS function(LPOLESERVERDOC, OLE_LPCSTR, OLE_LPCSTR) SetHostNames;
OLESTATUS function(LPOLESERVERDOC, RECT*) SetDocDimensions;
OLESTATUS function(LPOLESERVERDOC, OLE_LPCSTR, LPOLEOBJECT*, LPOLECLIENT)
GetObject;
OLESTATUS function(LPOLESERVERDOC) Release;
OLESTATUS function(LPOLESERVERDOC, LOGPALETTE*) SetColorScheme;
OLESTATUS function(LPOLESERVERDOC, HGLOBAL) Execute;
}
alias OLESERVERDOCVTBL* LPOLESERVERDOCVTBL;
struct OLESERVERDOC {
LPOLESERVERDOCVTBL lpvtbl;
}
alias OLESERVERDOC* LPOLESERVERDOC;
extern (Windows) {
OLESTATUS OleDelete(LPOLEOBJECT);
OLESTATUS OleRelease(LPOLEOBJECT);
OLESTATUS OleSaveToStream(LPOLEOBJECT, LPOLESTREAM);
OLESTATUS OleEqual(LPOLEOBJECT, LPOLEOBJECT);
OLESTATUS OleCopyToClipboard(LPOLEOBJECT);
OLESTATUS OleSetHostNames(LPOLEOBJECT, LPCSTR, LPCSTR);
OLESTATUS OleSetTargetDevice(LPOLEOBJECT, HGLOBAL);
OLESTATUS OleSetBounds(LPOLEOBJECT, LPCRECT);
OLESTATUS OleSetColorScheme(LPOLEOBJECT, const(LOGPALETTE)*);
OLESTATUS OleQueryBounds(LPOLEOBJECT, RECT*);
OLESTATUS OleQuerySize(LPOLEOBJECT, DWORD*);
OLESTATUS OleDraw(LPOLEOBJECT, HDC, LPCRECT, LPCRECT, HDC);
OLESTATUS OleQueryOpen(LPOLEOBJECT);
OLESTATUS OleActivate(LPOLEOBJECT, UINT, BOOL, BOOL, HWND, LPCRECT);
OLESTATUS OleExecute(LPOLEOBJECT, HGLOBAL, UINT);
OLESTATUS OleClose(LPOLEOBJECT);
OLESTATUS OleUpdate(LPOLEOBJECT);
OLESTATUS OleReconnect(LPOLEOBJECT);
OLESTATUS OleGetLinkUpdateOptions(LPOLEOBJECT, OLEOPT_UPDATE*);
OLESTATUS OleSetLinkUpdateOptions(LPOLEOBJECT, OLEOPT_UPDATE);
void* OleQueryProtocol(LPOLEOBJECT, LPCSTR);
OLESTATUS OleQueryReleaseStatus(LPOLEOBJECT);
OLESTATUS OleQueryReleaseError(LPOLEOBJECT);
OLE_RELEASE_METHOD OleQueryReleaseMethod(LPOLEOBJECT);
OLESTATUS OleQueryType(LPOLEOBJECT, LONG*);
DWORD OleQueryClientVersion();
DWORD OleQueryServerVersion();
OLECLIPFORMAT OleEnumFormats(LPOLEOBJECT, OLECLIPFORMAT);
OLESTATUS OleGetData(LPOLEOBJECT, OLECLIPFORMAT, HANDLE*);
OLESTATUS OleSetData(LPOLEOBJECT, OLECLIPFORMAT, HANDLE);
OLESTATUS OleQueryOutOfDate(LPOLEOBJECT);
OLESTATUS OleRequestData(LPOLEOBJECT, OLECLIPFORMAT);
OLESTATUS OleQueryLinkFromClip(LPCSTR, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleQueryCreateFromClip(LPCSTR, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleCreateFromClip(LPCSTR, LPOLECLIENT, LHCLIENTDOC, LPCSTR,
LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleCreateLinkFromClip(LPCSTR, LPOLECLIENT, LHCLIENTDOC, LPCSTR,
LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleCreateFromFile(LPCSTR, LPOLECLIENT, LPCSTR, LPCSTR,
LHCLIENTDOC, LPCSTR, LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleCreateLinkFromFile(LPCSTR, LPOLECLIENT, LPCSTR, LPCSTR,
LPCSTR, LHCLIENTDOC, LPCSTR, LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleLoadFromStream(LPOLESTREAM, LPCSTR, LPOLECLIENT, LHCLIENTDOC,
LPCSTR, LPOLEOBJECT*);
OLESTATUS OleCreate(LPCSTR, LPOLECLIENT, LPCSTR, LHCLIENTDOC, LPCSTR,
LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleCreateInvisible(LPCSTR, LPOLECLIENT, LPCSTR, LHCLIENTDOC,
LPCSTR, LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT, BOOL);
OLESTATUS OleCreateFromTemplate(LPCSTR, LPOLECLIENT, LPCSTR, LHCLIENTDOC,
LPCSTR, LPOLEOBJECT*, OLEOPT_RENDER, OLECLIPFORMAT);
OLESTATUS OleClone(LPOLEOBJECT, LPOLECLIENT, LHCLIENTDOC, LPCSTR,
LPOLEOBJECT*);
OLESTATUS OleCopyFromLink(LPOLEOBJECT, LPCSTR, LPOLECLIENT, LHCLIENTDOC,
LPCSTR, LPOLEOBJECT*);
OLESTATUS OleObjectConvert(LPOLEOBJECT, LPCSTR, LPOLECLIENT, LHCLIENTDOC,
LPCSTR, LPOLEOBJECT*);
OLESTATUS OleRename(LPOLEOBJECT, LPCSTR);
OLESTATUS OleQueryName(LPOLEOBJECT, LPSTR, UINT*);
OLESTATUS OleRevokeObject(LPOLECLIENT);
BOOL OleIsDcMeta(HDC);
OLESTATUS OleRegisterClientDoc(LPCSTR, LPCSTR, LONG, LHCLIENTDOC*);
OLESTATUS OleRevokeClientDoc(LHCLIENTDOC);
OLESTATUS OleRenameClientDoc(LHCLIENTDOC, LPCSTR);
OLESTATUS OleRevertClientDoc(LHCLIENTDOC);
OLESTATUS OleSavedClientDoc(LHCLIENTDOC);
OLESTATUS OleEnumObjects(LHCLIENTDOC, LPOLEOBJECT*);
OLESTATUS OleRegisterServer(LPCSTR, LPOLESERVER, LHSERVER*, HINSTANCE,
OLE_SERVER_USE);
OLESTATUS OleRevokeServer(LHSERVER);
OLESTATUS OleBlockServer(LHSERVER);
OLESTATUS OleUnblockServer(LHSERVER, BOOL*);
OLESTATUS OleLockServer(LPOLEOBJECT, LHSERVER*);
OLESTATUS OleUnlockServer(LHSERVER);
OLESTATUS OleRegisterServerDoc(LHSERVER, LPCSTR, LPOLESERVERDOC,
LHSERVERDOC*);
OLESTATUS OleRevokeServerDoc(LHSERVERDOC);
OLESTATUS OleRenameServerDoc(LHSERVERDOC, LPCSTR);
OLESTATUS OleRevertServerDoc(LHSERVERDOC);
OLESTATUS OleSavedServerDoc(LHSERVERDOC);
}
| D |
/*
TEST_OUTPUT:
---
fail_compilation/diag10169.d(11): Error: no property `x` for type `imports.a10169.B`
---
*/
import imports.a10169;
void main()
{
auto a = B.init.x;
}
| D |
import std.range, std.algorithm;
struct Permutations(bool doCopy=true, T) {
T[] items;
int r;
bool stopped;
int[] indices, cycles;
static if (!doCopy)
T[] result;
this(T)(T[] items, int r=-1) /*pure nothrow*/ {
this.items = items;
immutable int n = items.length;
if (r < 0)
r = n;
this.r = r;
immutable n_minus_r = n - r;
if (n_minus_r < 0) {
this.stopped = true;
} else {
this.stopped = false;
this.indices = n.iota.array; // Not pure nothrow.
this.cycles = iota(n, n_minus_r, -1).array;
}
static if (!doCopy)
result = new T[r];
}
@property bool empty() const pure nothrow {
return this.stopped;
}
static if (doCopy) {
@property T[] front() const pure nothrow {
assert(!this.stopped);
auto result = new T[r];
foreach (immutable i, ref re; result)
re = items[indices[i]];
return result;
}
} else {
@property T[] front() pure nothrow {
assert(!this.stopped);
foreach (immutable i, ref re; this.result)
re = items[indices[i]];
return this.result;
}
}
void popFront() pure /*nothrow*/ {
assert(!this.stopped);
int i = r - 1;
while (i >= 0) {
immutable int j = cycles[i] - 1;
if (j > 0) {
cycles[i] = j;
swap(indices[i], indices[$ - j]);
return;
}
cycles[i] = indices.length - i;
immutable int n1 = indices.length - 1;
assert(n1 >= 0);
immutable int num = indices[i];
// copy isn't nothrow.
indices[i + 1 .. n1 + 1].copy(indices[i .. n1]);
indices[n1] = num;
i--;
}
this.stopped = true;
}
}
Permutations!(doCopy, T) permutations(bool doCopy=true, T)
(T[] items, int r=-1)
/*pure nothrow*/ {
return Permutations!(doCopy, T)(items, r);
}
// ---------------------------------
import std.stdio, std.typecons, std.conv, std.algorithm, std.array,
std.exception, std.string;
enum maxIters = 1_000_000;
string A036058(in string ns) pure {
return ns.group.map!(t => t[1].text ~ cast(char)t[0]).join;
}
int A036058_length(bool doPrint=false)(string numberString="0") {
int iterations = 1;
int queueIndex;
string[3] lastThree;
while (true) {
static if (doPrint)
writefln(" %2d %s", iterations, numberString);
numberString = cast(string)(numberString
.dup
.representation
.sort()
.release
.assumeUnique);
if (lastThree[].canFind(numberString))
break;
assert(iterations < maxIters);
lastThree[queueIndex] = numberString;
numberString = numberString.A036058;
iterations++;
queueIndex++;
queueIndex %= 3;
}
return iterations;
}
Tuple!(int,int[]) max_A036058_length(R)(R startRange = 11.iota) {
bool[string] alreadyDone;
auto max_len = tuple(-1, (int[]).init);
foreach (n; startRange) {
immutable string sns = cast(string)(n
.to!(char[])
.representation
.sort()
.release
.assumeUnique);
if (sns !in alreadyDone) {
alreadyDone[sns] = true;
const size = sns.A036058_length;
if (size > max_len[0])
max_len = tuple(size, [n]);
else if (size == max_len[0])
max_len[1] ~= n;
}
}
return max_len;
}
void main() {
//const (lenMax, starts) = maxIters.iota.max_A036058_length;
const lenMax_starts = maxIters.iota.max_A036058_length;
immutable lenMax = lenMax_starts[0];
const starts = lenMax_starts[1];
// Expand:
int[] allStarts;
foreach (immutable n; starts) {
bool[string] set;
foreach (const k; permutations!false(n.to!(char[]), 4))
if (k[0] != '0')
set[k.idup] = true;
//allStarts ~= set.byKey.to!(int[]);
allStarts ~= set.byKey.map!(to!int).array;
}
allStarts = allStarts.sort().filter!(x => x < maxIters).array;
writefln("The longest length, followed by the number(s) with the
longest sequence length for starting sequence numbers below maxIters
are:
Iterations = %d and sequence-starts = %s.", lenMax, allStarts);
writeln("Note that only the first of any sequences with the same
digits is printed below. (The others will differ only in their first
term).");
foreach (immutable n; starts) {
writeln;
A036058_length!true(n.text);
}
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto as = readln.split.to!(int[]);
auto a1 = as[0];
auto a2 = as[1];
auto a3 = as[2];
auto DP = new int[][][][](3,3,3,3);
auto memo = new bool[][][][](3,3,3,3);
int run(int i, int j, int k, int l) {
if (i == 2 && j == a1-1 && k == a2-1 && l == a3-1) return 1;
if (memo[i][j][k][l]) return DP[i][j][k][l];
memo[i][j][k][l] = true;
int r;
if (i < 2) r += run(i+1, j, k, l);
if (j < a1-1) r += run(i, j+1, k, l);
if (i >= 1 && j >= k+1 && k < a2-1) r += run(i, j, k+1, l);
if (i >= 2 && k >= l+1 && l < a3-1) r += run(i, k, k, l+1);
return DP[i][j][k][l] = r;
}
writeln(run(0, 0, 0, 0));
} | D |
import std.stdio, std.string;
T[] _insertAt(T)(T val, T[] a, int idx, int pos)
{
if (a.length == 0) return [];
if (idx == pos) return [val] ~ _insertAt(val, a, idx + 1, pos);
return [a[0]] ~ _insertAt(val, a[1 .. $], idx + 1, pos);
}
T[] insertAt(T)(T val, T[] a, int pos)
{
if (pos < 0) pos = 0;
if (pos > a.length) pos = cast(int)a.length;
return _insertAt(val, a, 1, pos);
}
int main(string[] args)
{
auto a = [1, 2, 3, 4, 5, 6];
assert(insertAt!int(0, a, 3) == [1, 2, 0, 3, 4, 5, 6]);
return 0;
}
| D |
module drats;
public {
import drats.kbd;
import drats.term;
import drats.drats;
import drats.color;
//
import std.conv : to;
}
| D |
module a;
final class Foo
{
import b;
}
| D |
/Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/StORM.build/StORMDataSourceCredentials.swift.o : /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORM.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMConnect.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMCursor.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSource.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceCredentials.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceOptions.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMError.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMJoins.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMProtocol.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMRow.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMtResultSet.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/PerfectLib.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc
/Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/StORM.build/StORMDataSourceCredentials~partial.swiftmodule : /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORM.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMConnect.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMCursor.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSource.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceCredentials.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceOptions.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMError.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMJoins.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMProtocol.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMRow.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMtResultSet.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/PerfectLib.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc
/Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/StORM.build/StORMDataSourceCredentials~partial.swiftdoc : /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORM.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMConnect.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMCursor.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSource.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceCredentials.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMDataSourceOptions.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMError.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMJoins.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMProtocol.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMRow.swift /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/checkouts/StORM.git-6077292811663054913/Sources/StORM/StORMtResultSet.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/SwiftOnoneSupport.swiftmodule /Users/Dai/Desktop/Studing/swift服务端/PerfectDemo4/.build/debug/PerfectLib.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreGraphics.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/IOKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/CoreText.apinotesc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/x86_64/Foundation.apinotesc
| D |
/**
* Contains TelegramPassportElementErrorTranslationFile
*/
module tg.passport.types.telegram_passport_element_error_translation_file;
import tg.core.type, tg.core.exception;
import std.json, tg.type;
/**
* Represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes.
*/
class TelegramPassportElementErrorTranslationFile : TelegramType {
/**
* Creates new type object
*/
nothrow pure public this () @safe {
_source = "";
_type = "";
_file_hash = "";
_message = "";
}
/** Add constructor with data init from response */
mixin(TelegramTypeConstructor);
override public void setFromJson (JSONValue data) {
if ( "source" !in data ) throw new TelegramException("Could not find reqired entry : source");
_source = data["source"].str();
if ( "type" !in data ) throw new TelegramException("Could not find reqired entry : type");
_type = data["type"].str();
if ( "file_hash" !in data ) throw new TelegramException("Could not find reqired entry : file_hash");
_file_hash = data["file_hash"].str();
if ( "message" !in data ) throw new TelegramException("Could not find reqired entry : message");
_message = data["message"].str();
}
override public JSONValue getAsJson () {
JSONValue data = parseJSON("");
data["source"] = _source;
data["type"] = _type;
data["file_hash"] = _file_hash;
data["message"] = _message;
return data;
}
/** Error source, must be <em>translation_file</em> */
private string _source;
/**
* Getter for '_source'
* Returns: Current value of '_source'
*/
@property string source () { return _source; }
/**
* Setter for '_source'
* Params: sourceNew = New value of '_source'
* Returns: New value of '_source'
*/
@property string source ( string sourceNew ) { return _source = sourceNew; }
/** Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” */
private string _type;
/**
* Getter for '_type'
* Returns: Current value of '_type'
*/
@property string type () { return _type; }
/**
* Setter for '_type'
* Params: typeNew = New value of '_type'
* Returns: New value of '_type'
*/
@property string type ( string typeNew ) { return _type = typeNew; }
/** Base64-encoded file hash */
private string _file_hash;
/**
* Getter for '_file_hash'
* Returns: Current value of '_file_hash'
*/
@property string fileHash () { return _file_hash; }
/**
* Setter for '_file_hash'
* Params: fileHashNew = New value of '_file_hash'
* Returns: New value of '_file_hash'
*/
@property string fileHash ( string fileHashNew ) { return _file_hash = fileHashNew; }
/** Error message */
private string _message;
/**
* Getter for '_message'
* Returns: Current value of '_message'
*/
@property string message () { return _message; }
/**
* Setter for '_message'
* Params: messageNew = New value of '_message'
* Returns: New value of '_message'
*/
@property string message ( string messageNew ) { return _message = messageNew; }
}
| D |
module soup.PasswordManagerIF;
private import gio.Cancellable;
private import glib.MainContext;
private import soup.Auth;
private import soup.Message;
private import soup.c.functions;
public import soup.c.types;
/** */
public interface PasswordManagerIF{
/** Get the main Gtk struct */
public SoupPasswordManager* getPasswordManagerStruct(bool transferOwnership = false);
/** the main Gtk struct as a void* */
protected void* getStruct();
/** */
public static GType getType()
{
return soup_password_manager_get_type();
}
/** */
public void getPasswordsAsync(Message msg, Auth auth, bool retrying, MainContext asyncContext, Cancellable cancellable, SoupPasswordManagerCallback callback, void* userData);
/** */
public void getPasswordsSync(Message msg, Auth auth, Cancellable cancellable);
}
| D |
/Users/admin/Desktop/PlsHireMe/build/PlsHireMe.build/Debug-iphonesimulator/PlsHireMe.build/Objects-normal/x86_64/WordsearchFooter.o : /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Page.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Response.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/AppDelegate.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Song.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Wordsearch.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/PageCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingConfigCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/ProjectCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/SongLibraryCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/CircularTransition.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridHeader.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingGridViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PageViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingConfigViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/WordsearchViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PlayerViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/ProjectsViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/SongLibraryViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchFooter.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Project.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreMedia.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/simd.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/AVFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreAudio.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/MediaToolbox.framework/Headers/MediaToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/admin/Desktop/PlsHireMe/build/PlsHireMe.build/Debug-iphonesimulator/PlsHireMe.build/Objects-normal/x86_64/WordsearchFooter~partial.swiftmodule : /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Page.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Response.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/AppDelegate.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Song.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Wordsearch.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/PageCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingConfigCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/ProjectCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/SongLibraryCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/CircularTransition.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridHeader.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingGridViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PageViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingConfigViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/WordsearchViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PlayerViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/ProjectsViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/SongLibraryViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchFooter.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Project.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreMedia.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/simd.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/AVFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreAudio.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/MediaToolbox.framework/Headers/MediaToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
/Users/admin/Desktop/PlsHireMe/build/PlsHireMe.build/Debug-iphonesimulator/PlsHireMe.build/Objects-normal/x86_64/WordsearchFooter~partial.swiftdoc : /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Page.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Response.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/AppDelegate.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Song.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Wordsearch.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/PageCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingConfigCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/ProjectCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/SongLibraryCell.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/CircularTransition.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/MatchingGridHeader.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingGridViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PageViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/MatchingConfigViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/WordsearchViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/PlayerViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/ProjectsViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Controller/SongLibraryViewController.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/View/WordsearchFooter.swift /Users/admin/Desktop/PlsHireMe/PlsHireMe/Model/Project.swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/ObjectiveC.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreMedia.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/simd.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreImage.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/QuartzCore.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Metal.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Darwin.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Foundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/AVFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreFoundation.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreAudio.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/CoreGraphics.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Swift.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/UIKit.swiftmodule /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/SwiftOnoneSupport.swiftmodule /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/objc/ObjectiveC.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/OpenGLES.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.apinotes /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/x86_64/Dispatch.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Metal.framework/Headers/Metal.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/Darwin.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/MediaToolbox.framework/Headers/MediaToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioToolbox.apinotes /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/System/Library/Frameworks/Security.framework/Headers/Security.apinotes
| D |
/home/mahc/sistemasoperativos/C-stems-Programming/Rust/string_witchery/target/rls/debug/deps/string_witchery-2b7897963a2bf5fa.rmeta: src/main.rs
/home/mahc/sistemasoperativos/C-stems-Programming/Rust/string_witchery/target/rls/debug/deps/string_witchery-2b7897963a2bf5fa.d: src/main.rs
src/main.rs:
| D |
a salt deposit that animals regularly lick
touching with the tongue
(boxing) a blow with the fist
beat thoroughly and conclusively in a competition or fight
pass the tongue over
find the solution to (a problem or question) or understand the meaning of
take up with the tongue
| D |
/*
TEST_OUTPUT:
---
fail_compilation/diag16977.d(25): Error: undefined identifier `undefined`, did you mean function `undefinedId`?
fail_compilation/diag16977.d(26): Error: cannot implicitly convert expression `"\x01string"` of type `string` to `int`
fail_compilation/diag16977.d(27): Error: template `diag16977.templ` cannot deduce function from argument types `!()(int)`
fail_compilation/diag16977.d(20): Candidate is: `templ(S)(S s)`
with `S = int`
must satisfy the following constraint:
` false`
fail_compilation/diag16977.d(28): Error: cannot implicitly convert expression `5` of type `int` to `string`
fail_compilation/diag16977.d(30): Error: template instance `diag16977.test.funcTemplate!string` error instantiating
---
*/
// when copying the expression of a default argument, location information is
// replaced by the location of the caller to improve debug information
// verify error messages are displayed for the original location only
string templ(S)(S s) if(false) { return null; }
void test()
{
// local functions to defer evaluation into semantic3 pass
void undefinedId(int x, int y = undefined) {}
void badOp(int x, int y = 1 ~ "string") {}
void lazyTemplate(int x, lazy int y = 4.templ) {}
void funcTemplate(T)(T y = 5) {}
funcTemplate!string();
undefinedId(1);
badOp(2);
lazyTemplate(3);
}
| D |
/**
* Twofish
*
* Copyright:
* (C) 1999-2007 Jack Lloyd
* (C) 2014-2015 Etienne Cimon
*
* License:
* Botan is released under the Simplified BSD License (see LICENSE.md)
*/
module botan.block.twofish;
import botan.constants;
static if (BOTAN_HAS_TWOFISH):
import std.range : iota;
import botan.utils.loadstor;
import botan.utils.get_byte;
import botan.utils.rotate;
import botan.block.block_cipher;
import botan.utils.mem_ops;
/**
* Twofish, an AES finalist
*/
final class Twofish : BlockCipherFixedParams!(16, 16, 32, 8), BlockCipher, SymmetricAlgorithm
{
public:
/*
* Twofish Encryption
*/
override void encryptN(const(ubyte)* input, ubyte* output, size_t blocks)
{
foreach (size_t i; 0 .. blocks)
{
uint A = loadLittleEndian!uint(input, 0) ^ m_RK[0];
uint B = loadLittleEndian!uint(input, 1) ^ m_RK[1];
uint C = loadLittleEndian!uint(input, 2) ^ m_RK[2];
uint D = loadLittleEndian!uint(input, 3) ^ m_RK[3];
for (size_t j = 0; j != 16; j += 2)
{
uint X, Y;
X = m_SB[ get_byte(3, A)] ^ m_SB[256+get_byte(2, A)] ^
m_SB[512+ get_byte(1, A)] ^ m_SB[768+get_byte(0, A)];
Y = m_SB[ get_byte(0, B)] ^ m_SB[256+get_byte(3, B)] ^
m_SB[512+ get_byte(2, B)] ^ m_SB[768+get_byte(1, B)];
X += Y;
Y += X + m_RK[2*j + 9];
X += m_RK[2*j + 8];
C = rotateRight(C ^ X, 1);
D = rotateLeft(D, 1) ^ Y;
X = m_SB[ get_byte(3, C)] ^ m_SB[256+get_byte(2, C)] ^
m_SB[512+ get_byte(1, C)] ^ m_SB[768+get_byte(0, C)];
Y = m_SB[ get_byte(0, D)] ^ m_SB[256+get_byte(3, D)] ^
m_SB[512+ get_byte(2, D)] ^ m_SB[768+get_byte(1, D)];
X += Y;
Y += X + m_RK[2*j + 11];
X += m_RK[2*j + 10];
A = rotateRight(A ^ X, 1);
B = rotateLeft(B, 1) ^ Y;
}
C ^= m_RK[4];
D ^= m_RK[5];
A ^= m_RK[6];
B ^= m_RK[7];
storeLittleEndian(output, C, D, A, B);
input += BLOCK_SIZE;
output += BLOCK_SIZE;
}
}
/*
* Twofish Decryption
*/
override void decryptN(const(ubyte)* input, ubyte* output, size_t blocks)
{
foreach (size_t i; 0 .. blocks)
{
uint A = loadLittleEndian!uint(input, 0) ^ m_RK[4];
uint B = loadLittleEndian!uint(input, 1) ^ m_RK[5];
uint C = loadLittleEndian!uint(input, 2) ^ m_RK[6];
uint D = loadLittleEndian!uint(input, 3) ^ m_RK[7];
for (size_t j = 0; j != 16; j += 2)
{
uint X, Y;
X = m_SB[ get_byte(3, A)] ^ m_SB[256+get_byte(2, A)] ^
m_SB[512+ get_byte(1, A)] ^ m_SB[768+get_byte(0, A)];
Y = m_SB[ get_byte(0, B)] ^ m_SB[256+get_byte(3, B)] ^
m_SB[512+ get_byte(2, B)] ^ m_SB[768+get_byte(1, B)];
X += Y;
Y += X + m_RK[39 - 2*j];
X += m_RK[38 - 2*j];
C = rotateLeft(C, 1) ^ X;
D = rotateRight(D ^ Y, 1);
X = m_SB[ get_byte(3, C)] ^ m_SB[256+get_byte(2, C)] ^
m_SB[512+ get_byte(1, C)] ^ m_SB[768+get_byte(0, C)];
Y = m_SB[ get_byte(0, D)] ^ m_SB[256+get_byte(3, D)] ^
m_SB[512+ get_byte(2, D)] ^ m_SB[768+get_byte(1, D)];
X += Y;
Y += X + m_RK[37 - 2*j];
X += m_RK[36 - 2*j];
A = rotateLeft(A, 1) ^ X;
B = rotateRight(B ^ Y, 1);
}
C ^= m_RK[0];
D ^= m_RK[1];
A ^= m_RK[2];
B ^= m_RK[3];
storeLittleEndian(output, C, D, A, B);
input += BLOCK_SIZE;
output += BLOCK_SIZE;
}
}
/*
* Clear memory of sensitive data
*/
override void clear()
{
zap(m_SB);
zap(m_RK);
}
override @property string name() const { return "Twofish"; }
override @property size_t parallelism() const { return 1; }
override BlockCipher clone() const { return new Twofish; }
override size_t blockSize() const { return super.blockSize(); }
override KeyLengthSpecification keySpec() const { return super.keySpec(); }
protected:
/*
* Twofish Key Schedule
*/
override void keySchedule(const(ubyte)* key, size_t length)
{
m_SB.resize(1024);
m_RK.resize(40);
SecureVector!ubyte S = SecureVector!ubyte(16);
foreach (size_t i; 0 .. length)
rs_mul(*cast(ubyte[4]*) &S[4*(i/8)], key[i], i);
if (length == 16)
{
foreach (size_t i; 0 .. 256)
{
m_SB[ i] = MDS0[Q0[Q0[i]^S[ 0]]^S[ 4]];
m_SB[256+i] = MDS1[Q0[Q1[i]^S[ 1]]^S[ 5]];
m_SB[512+i] = MDS2[Q1[Q0[i]^S[ 2]]^S[ 6]];
m_SB[768+i] = MDS3[Q1[Q1[i]^S[ 3]]^S[ 7]];
}
foreach (size_t i; iota(0, 40, 2))
{
uint X = MDS0[Q0[Q0[i ]^key[ 8]]^key[ 0]] ^
MDS1[Q0[Q1[i ]^key[ 9]]^key[ 1]] ^
MDS2[Q1[Q0[i ]^key[10]]^key[ 2]] ^
MDS3[Q1[Q1[i ]^key[11]]^key[ 3]];
uint Y = MDS0[Q0[Q0[i+1]^key[12]]^key[ 4]] ^
MDS1[Q0[Q1[i+1]^key[13]]^key[ 5]] ^
MDS2[Q1[Q0[i+1]^key[14]]^key[ 6]] ^
MDS3[Q1[Q1[i+1]^key[15]]^key[ 7]];
Y = rotateLeft(Y, 8);
X += Y; Y += X;
m_RK[i] = X;
m_RK[i+1] = rotateLeft(Y, 9);
}
}
else if (length == 24)
{
foreach (size_t i; 0 .. 256)
{
m_SB[ i] = MDS0[Q0[Q0[Q1[i]^S[ 0]]^S[ 4]]^S[ 8]];
m_SB[256+i] = MDS1[Q0[Q1[Q1[i]^S[ 1]]^S[ 5]]^S[ 9]];
m_SB[512+i] = MDS2[Q1[Q0[Q0[i]^S[ 2]]^S[ 6]]^S[10]];
m_SB[768+i] = MDS3[Q1[Q1[Q0[i]^S[ 3]]^S[ 7]]^S[11]];
}
foreach (size_t i; iota(0, 40, 2))
{
uint X = MDS0[Q0[Q0[Q1[i ]^key[16]]^key[ 8]]^key[ 0]] ^
MDS1[Q0[Q1[Q1[i ]^key[17]]^key[ 9]]^key[ 1]] ^
MDS2[Q1[Q0[Q0[i ]^key[18]]^key[10]]^key[ 2]] ^
MDS3[Q1[Q1[Q0[i ]^key[19]]^key[11]]^key[ 3]];
uint Y = MDS0[Q0[Q0[Q1[i+1]^key[20]]^key[12]]^key[ 4]] ^
MDS1[Q0[Q1[Q1[i+1]^key[21]]^key[13]]^key[ 5]] ^
MDS2[Q1[Q0[Q0[i+1]^key[22]]^key[14]]^key[ 6]] ^
MDS3[Q1[Q1[Q0[i+1]^key[23]]^key[15]]^key[ 7]];
Y = rotateLeft(Y, 8);
X += Y; Y += X;
m_RK[i] = X;
m_RK[i+1] = rotateLeft(Y, 9);
}
}
else if (length == 32)
{
foreach (size_t i; 0 .. 256)
{
m_SB[ i] = MDS0[Q0[Q0[Q1[Q1[i]^S[ 0]]^S[ 4]]^S[ 8]]^S[12]];
m_SB[256+i] = MDS1[Q0[Q1[Q1[Q0[i]^S[ 1]]^S[ 5]]^S[ 9]]^S[13]];
m_SB[512+i] = MDS2[Q1[Q0[Q0[Q0[i]^S[ 2]]^S[ 6]]^S[10]]^S[14]];
m_SB[768+i] = MDS3[Q1[Q1[Q0[Q1[i]^S[ 3]]^S[ 7]]^S[11]]^S[15]];
}
foreach (size_t i; iota(0, 40, 2))
{
uint X = MDS0[Q0[Q0[Q1[Q1[i ]^key[24]]^key[16]]^key[ 8]]^key[ 0]] ^
MDS1[Q0[Q1[Q1[Q0[i ]^key[25]]^key[17]]^key[ 9]]^key[ 1]] ^
MDS2[Q1[Q0[Q0[Q0[i ]^key[26]]^key[18]]^key[10]]^key[ 2]] ^
MDS3[Q1[Q1[Q0[Q1[i ]^key[27]]^key[19]]^key[11]]^key[ 3]];
uint Y = MDS0[Q0[Q0[Q1[Q1[i+1]^key[28]]^key[20]]^key[12]]^key[ 4]] ^
MDS1[Q0[Q1[Q1[Q0[i+1]^key[29]]^key[21]]^key[13]]^key[ 5]] ^
MDS2[Q1[Q0[Q0[Q0[i+1]^key[30]]^key[22]]^key[14]]^key[ 6]] ^
MDS3[Q1[Q1[Q0[Q1[i+1]^key[31]]^key[23]]^key[15]]^key[ 7]];
Y = rotateLeft(Y, 8);
X += Y; Y += X;
m_RK[i] = X;
m_RK[i+1] = rotateLeft(Y, 9);
}
}
}
SecureVector!uint m_SB, m_RK;
}
private:
/*
* Do one column of the rs matrix multiplcation
*/
void rs_mul(ref ubyte[4] S, ubyte key, size_t offset) pure
{
if (key)
{
ubyte X = POLY_TO_EXP[key - 1];
ubyte rs1 = RS[(4*offset ) % 32];
ubyte rs2 = RS[(4*offset+1) % 32];
ubyte rs3 = RS[(4*offset+2) % 32];
ubyte rs4 = RS[(4*offset+3) % 32];
S[0] ^= EXP_TO_POLY[(X + POLY_TO_EXP[rs1 - 1]) % 255];
S[1] ^= EXP_TO_POLY[(X + POLY_TO_EXP[rs2 - 1]) % 255];
S[2] ^= EXP_TO_POLY[(X + POLY_TO_EXP[rs3 - 1]) % 255];
S[3] ^= EXP_TO_POLY[(X + POLY_TO_EXP[rs4 - 1]) % 255];
}
}
__gshared immutable ubyte[256] Q0 = [
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78,
0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30,
0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE,
0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45,
0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF,
0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED,
0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B,
0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F,
0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17,
0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68,
0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42,
0x4A, 0x5E, 0xC1, 0xE0 ];
__gshared immutable ubyte[256] Q1 = [
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B,
0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B,
0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54,
0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7,
0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF,
0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D,
0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21,
0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E,
0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44,
0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B,
0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56,
0x55, 0x09, 0xBE, 0x91 ];
__gshared immutable ubyte[32] RS = [
0x01, 0xA4, 0x02, 0xA4, 0xA4, 0x56, 0xA1, 0x55, 0x55, 0x82, 0xFC, 0x87,
0x87, 0xF3, 0xC1, 0x5A, 0x5A, 0x1E, 0x47, 0x58, 0x58, 0xC6, 0xAE, 0xDB,
0xDB, 0x68, 0x3D, 0x9E, 0x9E, 0xE5, 0x19, 0x03 ];
__gshared immutable ubyte[255] EXP_TO_POLY = [
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x4D, 0x9A, 0x79, 0xF2,
0xA9, 0x1F, 0x3E, 0x7C, 0xF8, 0xBD, 0x37, 0x6E, 0xDC, 0xF5, 0xA7, 0x03,
0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xCD, 0xD7, 0xE3, 0x8B, 0x5B, 0xB6,
0x21, 0x42, 0x84, 0x45, 0x8A, 0x59, 0xB2, 0x29, 0x52, 0xA4, 0x05, 0x0A,
0x14, 0x28, 0x50, 0xA0, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xED, 0x97, 0x63,
0xC6, 0xC1, 0xCF, 0xD3, 0xEB, 0x9B, 0x7B, 0xF6, 0xA1, 0x0F, 0x1E, 0x3C,
0x78, 0xF0, 0xAD, 0x17, 0x2E, 0x5C, 0xB8, 0x3D, 0x7A, 0xF4, 0xA5, 0x07,
0x0E, 0x1C, 0x38, 0x70, 0xE0, 0x8D, 0x57, 0xAE, 0x11, 0x22, 0x44, 0x88,
0x5D, 0xBA, 0x39, 0x72, 0xE4, 0x85, 0x47, 0x8E, 0x51, 0xA2, 0x09, 0x12,
0x24, 0x48, 0x90, 0x6D, 0xDA, 0xF9, 0xBF, 0x33, 0x66, 0xCC, 0xD5, 0xE7,
0x83, 0x4B, 0x96, 0x61, 0xC2, 0xC9, 0xDF, 0xF3, 0xAB, 0x1B, 0x36, 0x6C,
0xD8, 0xFD, 0xB7, 0x23, 0x46, 0x8C, 0x55, 0xAA, 0x19, 0x32, 0x64, 0xC8,
0xDD, 0xF7, 0xA3, 0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x2D, 0x5A, 0xB4, 0x25,
0x4A, 0x94, 0x65, 0xCA, 0xD9, 0xFF, 0xB3, 0x2B, 0x56, 0xAC, 0x15, 0x2A,
0x54, 0xA8, 0x1D, 0x3A, 0x74, 0xE8, 0x9D, 0x77, 0xEE, 0x91, 0x6F, 0xDE,
0xF1, 0xAF, 0x13, 0x26, 0x4C, 0x98, 0x7D, 0xFA, 0xB9, 0x3F, 0x7E, 0xFC,
0xB5, 0x27, 0x4E, 0x9C, 0x75, 0xEA, 0x99, 0x7F, 0xFE, 0xB1, 0x2F, 0x5E,
0xBC, 0x35, 0x6A, 0xD4, 0xE5, 0x87, 0x43, 0x86, 0x41, 0x82, 0x49, 0x92,
0x69, 0xD2, 0xE9, 0x9F, 0x73, 0xE6, 0x81, 0x4F, 0x9E, 0x71, 0xE2, 0x89,
0x5F, 0xBE, 0x31, 0x62, 0xC4, 0xC5, 0xC7, 0xC3, 0xCB, 0xDB, 0xFB, 0xBB,
0x3B, 0x76, 0xEC, 0x95, 0x67, 0xCE, 0xD1, 0xEF, 0x93, 0x6B, 0xD6, 0xE1,
0x8F, 0x53, 0xA6 ];
__gshared immutable ubyte[255] POLY_TO_EXP = [
0x00, 0x01, 0x17, 0x02, 0x2E, 0x18, 0x53, 0x03, 0x6A, 0x2F, 0x93, 0x19,
0x34, 0x54, 0x45, 0x04, 0x5C, 0x6B, 0xB6, 0x30, 0xA6, 0x94, 0x4B, 0x1A,
0x8C, 0x35, 0x81, 0x55, 0xAA, 0x46, 0x0D, 0x05, 0x24, 0x5D, 0x87, 0x6C,
0x9B, 0xB7, 0xC1, 0x31, 0x2B, 0xA7, 0xA3, 0x95, 0x98, 0x4C, 0xCA, 0x1B,
0xE6, 0x8D, 0x73, 0x36, 0xCD, 0x82, 0x12, 0x56, 0x62, 0xAB, 0xF0, 0x47,
0x4F, 0x0E, 0xBD, 0x06, 0xD4, 0x25, 0xD2, 0x5E, 0x27, 0x88, 0x66, 0x6D,
0xD6, 0x9C, 0x79, 0xB8, 0x08, 0xC2, 0xDF, 0x32, 0x68, 0x2C, 0xFD, 0xA8,
0x8A, 0xA4, 0x5A, 0x96, 0x29, 0x99, 0x22, 0x4D, 0x60, 0xCB, 0xE4, 0x1C,
0x7B, 0xE7, 0x3B, 0x8E, 0x9E, 0x74, 0xF4, 0x37, 0xD8, 0xCE, 0xF9, 0x83,
0x6F, 0x13, 0xB2, 0x57, 0xE1, 0x63, 0xDC, 0xAC, 0xC4, 0xF1, 0xAF, 0x48,
0x0A, 0x50, 0x42, 0x0F, 0xBA, 0xBE, 0xC7, 0x07, 0xDE, 0xD5, 0x78, 0x26,
0x65, 0xD3, 0xD1, 0x5F, 0xE3, 0x28, 0x21, 0x89, 0x59, 0x67, 0xFC, 0x6E,
0xB1, 0xD7, 0xF8, 0x9D, 0xF3, 0x7A, 0x3A, 0xB9, 0xC6, 0x09, 0x41, 0xC3,
0xAE, 0xE0, 0xDB, 0x33, 0x44, 0x69, 0x92, 0x2D, 0x52, 0xFE, 0x16, 0xA9,
0x0C, 0x8B, 0x80, 0xA5, 0x4A, 0x5B, 0xB5, 0x97, 0xC9, 0x2A, 0xA2, 0x9A,
0xC0, 0x23, 0x86, 0x4E, 0xBC, 0x61, 0xEF, 0xCC, 0x11, 0xE5, 0x72, 0x1D,
0x3D, 0x7C, 0xEB, 0xE8, 0xE9, 0x3C, 0xEA, 0x8F, 0x7D, 0x9F, 0xEC, 0x75,
0x1E, 0xF5, 0x3E, 0x38, 0xF6, 0xD9, 0x3F, 0xCF, 0x76, 0xFA, 0x1F, 0x84,
0xA0, 0x70, 0xED, 0x14, 0x90, 0xB3, 0x7E, 0x58, 0xFB, 0xE2, 0x20, 0x64,
0xD0, 0xDD, 0x77, 0xAD, 0xDA, 0xC5, 0x40, 0xF2, 0x39, 0xB0, 0xF7, 0x49,
0xB4, 0x0B, 0x7F, 0x51, 0x15, 0x43, 0x91, 0x10, 0x71, 0xBB, 0xEE, 0xBF,
0x85, 0xC8, 0xA1 ];
__gshared immutable uint[256] MDS0 = [
0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B,
0xE2E22BFB, 0x9E9EFAC8, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B,
0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0x3C3C57D6, 0x93938A32,
0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
0x24243C30, 0x5151E20F, 0xBABAC6F8, 0x4A4AF31B, 0xBFBF4887, 0x0D0D70FA,
0xB0B0B306, 0x7575DE3F, 0xD2D2FD5E, 0x7D7D20BA, 0x666631AE, 0x3A3AA35B,
0x59591C8A, 0x00000000, 0xCDCD93BC, 0x1A1AE09D, 0xAEAE2C6D, 0x7F7FABC1,
0x2B2BC7B1, 0xBEBEB90E, 0xE0E0A080, 0x8A8A105D, 0x3B3B52D2, 0x6464BAD5,
0xD8D888A0, 0xE7E7A584, 0x5F5FE807, 0x1B1B1114, 0x2C2CC2B5, 0xFCFCB490,
0x3131272C, 0x808065A3, 0x73732AB2, 0x0C0C8173, 0x79795F4C, 0x6B6B4154,
0x4B4B0292, 0x53536974, 0x94948F36, 0x83831F51, 0x2A2A3638, 0xC4C49CB0,
0x2222C8BD, 0xD5D5F85A, 0xBDBDC3FC, 0x48487860, 0xFFFFCE62, 0x4C4C0796,
0x4141776C, 0xC7C7E642, 0xEBEB24F7, 0x1C1C1410, 0x5D5D637C, 0x36362228,
0x6767C027, 0xE9E9AF8C, 0x4444F913, 0x1414EA95, 0xF5F5BB9C, 0xCFCF18C7,
0x3F3F2D24, 0xC0C0E346, 0x7272DB3B, 0x54546C70, 0x29294CCA, 0xF0F035E3,
0x0808FE85, 0xC6C617CB, 0xF3F34F11, 0x8C8CE4D0, 0xA4A45993, 0xCACA96B8,
0x68683BA6, 0xB8B84D83, 0x38382820, 0xE5E52EFF, 0xADAD569F, 0x0B0B8477,
0xC8C81DC3, 0x9999FFCC, 0x5858ED03, 0x19199A6F, 0x0E0E0A08, 0x95957EBF,
0x70705040, 0xF7F730E7, 0x6E6ECF2B, 0x1F1F6EE2, 0xB5B53D79, 0x09090F0C,
0x616134AA, 0x57571682, 0x9F9F0B41, 0x9D9D803A, 0x111164EA, 0x2525CDB9,
0xAFAFDDE4, 0x4545089A, 0xDFDF8DA4, 0xA3A35C97, 0xEAEAD57E, 0x353558DA,
0xEDEDD07A, 0x4343FC17, 0xF8F8CB66, 0xFBFBB194, 0x3737D3A1, 0xFAFA401D,
0xC2C2683D, 0xB4B4CCF0, 0x32325DDE, 0x9C9C71B3, 0x5656E70B, 0xE3E3DA72,
0x878760A7, 0x15151B1C, 0xF9F93AEF, 0x6363BFD1, 0x3434A953, 0x9A9A853E,
0xB1B1428F, 0x7C7CD133, 0x88889B26, 0x3D3DA65F, 0xA1A1D7EC, 0xE4E4DF76,
0x8181942A, 0x91910149, 0x0F0FFB81, 0xEEEEAA88, 0x161661EE, 0xD7D77321,
0x9797F5C4, 0xA5A5A81A, 0xFEFE3FEB, 0x6D6DB5D9, 0x7878AEC5, 0xC5C56D39,
0x1D1DE599, 0x7676A4CD, 0x3E3EDCAD, 0xCBCB6731, 0xB6B6478B, 0xEFEF5B01,
0x12121E18, 0x6060C523, 0x6A6AB0DD, 0x4D4DF61F, 0xCECEE94E, 0xDEDE7C2D,
0x55559DF9, 0x7E7E5A48, 0x2121B24F, 0x03037AF2, 0xA0A02665, 0x5E5E198E,
0x5A5A6678, 0x65654B5C, 0x62624E58, 0xFDFD4519, 0x0606F48D, 0x404086E5,
0xF2F2BE98, 0x3333AC57, 0x17179067, 0x05058E7F, 0xE8E85E05, 0x4F4F7D64,
0x89896AAF, 0x10109563, 0x74742FB6, 0x0A0A75FE, 0x5C5C92F5, 0x9B9B74B7,
0x2D2D333C, 0x3030D6A5, 0x2E2E49CE, 0x494989E9, 0x46467268, 0x77775544,
0xA8A8D8E0, 0x9696044D, 0x2828BD43, 0xA9A92969, 0xD9D97929, 0x8686912E,
0xD1D187AC, 0xF4F44A15, 0x8D8D1559, 0xD6D682A8, 0xB9B9BC0A, 0x42420D9E,
0xF6F6C16E, 0x2F2FB847, 0xDDDD06DF, 0x23233934, 0xCCCC6235, 0xF1F1C46A,
0xC1C112CF, 0x8585EBDC, 0x8F8F9E22, 0x7171A1C9, 0x9090F0C0, 0xAAAA539B,
0x0101F189, 0x8B8BE1D4, 0x4E4E8CED, 0x8E8E6FAB, 0xABABA212, 0x6F6F3EA2,
0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9,
0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504,
0x04047FF6, 0x272746C2, 0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756,
0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91 ];
__gshared immutable uint[256] MDS1 = [
0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252,
0xA3658080, 0x76DFE4E4, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A,
0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x0D54E6E6, 0xC6432020,
0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
0x43BD2828, 0x7532BCBC, 0x37D47B7B, 0x269B8888, 0xFA700D0D, 0x13F94444,
0x94B1FBFB, 0x485A7E7E, 0xF27A0303, 0xD0E48C8C, 0x8B47B6B6, 0x303C2424,
0x84A5E7E7, 0x54416B6B, 0xDF06DDDD, 0x23C56060, 0x1945FDFD, 0x5BA33A3A,
0x3D68C2C2, 0x59158D8D, 0xF321ECEC, 0xAE316666, 0xA23E6F6F, 0x82165757,
0x63951010, 0x015BEFEF, 0x834DB8B8, 0x2E918686, 0xD9B56D6D, 0x511F8383,
0x9B53AAAA, 0x7C635D5D, 0xA63B6868, 0xEB3FFEFE, 0xA5D63030, 0xBE257A7A,
0x16A7ACAC, 0x0C0F0909, 0xE335F0F0, 0x6123A7A7, 0xC0F09090, 0x8CAFE9E9,
0x3A809D9D, 0xF5925C5C, 0x73810C0C, 0x2C273131, 0x2576D0D0, 0x0BE75656,
0xBB7B9292, 0x4EE9CECE, 0x89F10101, 0x6B9F1E1E, 0x53A93434, 0x6AC4F1F1,
0xB499C3C3, 0xF1975B5B, 0xE1834747, 0xE66B1818, 0xBDC82222, 0x450E9898,
0xE26E1F1F, 0xF4C9B3B3, 0xB62F7474, 0x66CBF8F8, 0xCCFF9999, 0x95EA1414,
0x03ED5858, 0x56F7DCDC, 0xD4E18B8B, 0x1C1B1515, 0x1EADA2A2, 0xD70CD3D3,
0xFB2BE2E2, 0xC31DC8C8, 0x8E195E5E, 0xB5C22C2C, 0xE9894949, 0xCF12C1C1,
0xBF7E9595, 0xBA207D7D, 0xEA641111, 0x77840B0B, 0x396DC5C5, 0xAF6A8989,
0x33D17C7C, 0xC9A17171, 0x62CEFFFF, 0x7137BBBB, 0x81FB0F0F, 0x793DB5B5,
0x0951E1E1, 0xADDC3E3E, 0x242D3F3F, 0xCDA47676, 0xF99D5555, 0xD8EE8282,
0xE5864040, 0xC5AE7878, 0xB9CD2525, 0x4D049696, 0x44557777, 0x080A0E0E,
0x86135050, 0xE730F7F7, 0xA1D33737, 0x1D40FAFA, 0xAA346161, 0xED8C4E4E,
0x06B3B0B0, 0x706C5454, 0xB22A7373, 0xD2523B3B, 0x410B9F9F, 0x7B8B0202,
0xA088D8D8, 0x114FF3F3, 0x3167CBCB, 0xC2462727, 0x27C06767, 0x90B4FCFC,
0x20283838, 0xF67F0404, 0x60784848, 0xFF2EE5E5, 0x96074C4C, 0x5C4B6565,
0xB1C72B2B, 0xAB6F8E8E, 0x9E0D4242, 0x9CBBF5F5, 0x52F2DBDB, 0x1BF34A4A,
0x5FA63D3D, 0x9359A4A4, 0x0ABCB9B9, 0xEF3AF9F9, 0x91EF1313, 0x85FE0808,
0x49019191, 0xEE611616, 0x2D7CDEDE, 0x4FB22121, 0x8F42B1B1, 0x3BDB7272,
0x47B82F2F, 0x8748BFBF, 0x6D2CAEAE, 0x46E3C0C0, 0xD6573C3C, 0x3E859A9A,
0x6929A9A9, 0x647D4F4F, 0x2A948181, 0xCE492E2E, 0xCB17C6C6, 0x2FCA6969,
0xFCC3BDBD, 0x975CA3A3, 0x055EE8E8, 0x7AD0EDED, 0xAC87D1D1, 0x7F8E0505,
0xD5BA6464, 0x1AA8A5A5, 0x4BB72626, 0x0EB9BEBE, 0xA7608787, 0x5AF8D5D5,
0x28223636, 0x14111B1B, 0x3FDE7575, 0x2979D9D9, 0x88AAEEEE, 0x3C332D2D,
0x4C5F7979, 0x02B6B7B7, 0xB896CACA, 0xDA583535, 0xB09CC4C4, 0x17FC4343,
0x551A8484, 0x1FF64D4D, 0x8A1C5959, 0x7D38B2B2, 0x57AC3333, 0xC718CFCF,
0x8DF40606, 0x74695353, 0xB7749B9B, 0xC4F59797, 0x9F56ADAD, 0x72DAE3E3,
0x7ED5EAEA, 0x154AF4F4, 0x229E8F8F, 0x12A2ABAB, 0x584E6262, 0x07E85F5F,
0x99E51D1D, 0x34392323, 0x6EC1F6F6, 0x50446C6C, 0xDE5D3232, 0x68724646,
0x6526A0A0, 0xBC93CDCD, 0xDB03DADA, 0xF8C6BABA, 0xC8FA9E9E, 0xA882D6D6,
0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF,
0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A,
0x0FE25151, 0x00000000, 0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7,
0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8 ];
__gshared immutable uint[256] MDS2 = [
0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B,
0xE2FBE22B, 0x9EC89EFA, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F,
0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0x3CD63C57, 0x9332938A,
0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
0x2430243C, 0x510F51E2, 0xBAF8BAC6, 0x4A1B4AF3, 0xBF87BF48, 0x0DFA0D70,
0xB006B0B3, 0x753F75DE, 0xD25ED2FD, 0x7DBA7D20, 0x66AE6631, 0x3A5B3AA3,
0x598A591C, 0x00000000, 0xCDBCCD93, 0x1A9D1AE0, 0xAE6DAE2C, 0x7FC17FAB,
0x2BB12BC7, 0xBE0EBEB9, 0xE080E0A0, 0x8A5D8A10, 0x3BD23B52, 0x64D564BA,
0xD8A0D888, 0xE784E7A5, 0x5F075FE8, 0x1B141B11, 0x2CB52CC2, 0xFC90FCB4,
0x312C3127, 0x80A38065, 0x73B2732A, 0x0C730C81, 0x794C795F, 0x6B546B41,
0x4B924B02, 0x53745369, 0x9436948F, 0x8351831F, 0x2A382A36, 0xC4B0C49C,
0x22BD22C8, 0xD55AD5F8, 0xBDFCBDC3, 0x48604878, 0xFF62FFCE, 0x4C964C07,
0x416C4177, 0xC742C7E6, 0xEBF7EB24, 0x1C101C14, 0x5D7C5D63, 0x36283622,
0x672767C0, 0xE98CE9AF, 0x441344F9, 0x149514EA, 0xF59CF5BB, 0xCFC7CF18,
0x3F243F2D, 0xC046C0E3, 0x723B72DB, 0x5470546C, 0x29CA294C, 0xF0E3F035,
0x088508FE, 0xC6CBC617, 0xF311F34F, 0x8CD08CE4, 0xA493A459, 0xCAB8CA96,
0x68A6683B, 0xB883B84D, 0x38203828, 0xE5FFE52E, 0xAD9FAD56, 0x0B770B84,
0xC8C3C81D, 0x99CC99FF, 0x580358ED, 0x196F199A, 0x0E080E0A, 0x95BF957E,
0x70407050, 0xF7E7F730, 0x6E2B6ECF, 0x1FE21F6E, 0xB579B53D, 0x090C090F,
0x61AA6134, 0x57825716, 0x9F419F0B, 0x9D3A9D80, 0x11EA1164, 0x25B925CD,
0xAFE4AFDD, 0x459A4508, 0xDFA4DF8D, 0xA397A35C, 0xEA7EEAD5, 0x35DA3558,
0xED7AEDD0, 0x431743FC, 0xF866F8CB, 0xFB94FBB1, 0x37A137D3, 0xFA1DFA40,
0xC23DC268, 0xB4F0B4CC, 0x32DE325D, 0x9CB39C71, 0x560B56E7, 0xE372E3DA,
0x87A78760, 0x151C151B, 0xF9EFF93A, 0x63D163BF, 0x345334A9, 0x9A3E9A85,
0xB18FB142, 0x7C337CD1, 0x8826889B, 0x3D5F3DA6, 0xA1ECA1D7, 0xE476E4DF,
0x812A8194, 0x91499101, 0x0F810FFB, 0xEE88EEAA, 0x16EE1661, 0xD721D773,
0x97C497F5, 0xA51AA5A8, 0xFEEBFE3F, 0x6DD96DB5, 0x78C578AE, 0xC539C56D,
0x1D991DE5, 0x76CD76A4, 0x3EAD3EDC, 0xCB31CB67, 0xB68BB647, 0xEF01EF5B,
0x1218121E, 0x602360C5, 0x6ADD6AB0, 0x4D1F4DF6, 0xCE4ECEE9, 0xDE2DDE7C,
0x55F9559D, 0x7E487E5A, 0x214F21B2, 0x03F2037A, 0xA065A026, 0x5E8E5E19,
0x5A785A66, 0x655C654B, 0x6258624E, 0xFD19FD45, 0x068D06F4, 0x40E54086,
0xF298F2BE, 0x335733AC, 0x17671790, 0x057F058E, 0xE805E85E, 0x4F644F7D,
0x89AF896A, 0x10631095, 0x74B6742F, 0x0AFE0A75, 0x5CF55C92, 0x9BB79B74,
0x2D3C2D33, 0x30A530D6, 0x2ECE2E49, 0x49E94989, 0x46684672, 0x77447755,
0xA8E0A8D8, 0x964D9604, 0x284328BD, 0xA969A929, 0xD929D979, 0x862E8691,
0xD1ACD187, 0xF415F44A, 0x8D598D15, 0xD6A8D682, 0xB90AB9BC, 0x429E420D,
0xF66EF6C1, 0x2F472FB8, 0xDDDFDD06, 0x23342339, 0xCC35CC62, 0xF16AF1C4,
0xC1CFC112, 0x85DC85EB, 0x8F228F9E, 0x71C971A1, 0x90C090F0, 0xAA9BAA53,
0x018901F1, 0x8BD48BE1, 0x4EED4E8C, 0x8EAB8E6F, 0xAB12ABA2, 0x6FA26F3E,
0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9,
0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705,
0x04F6047F, 0x27C22746, 0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7,
0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF ];
__gshared immutable uint[256] MDS3 = [
0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98,
0x6580A365, 0xDFE476DF, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866,
0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x54E60D54, 0x4320C643,
0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
0xBD2843BD, 0x32BC7532, 0xD47B37D4, 0x9B88269B, 0x700DFA70, 0xF94413F9,
0xB1FB94B1, 0x5A7E485A, 0x7A03F27A, 0xE48CD0E4, 0x47B68B47, 0x3C24303C,
0xA5E784A5, 0x416B5441, 0x06DDDF06, 0xC56023C5, 0x45FD1945, 0xA33A5BA3,
0x68C23D68, 0x158D5915, 0x21ECF321, 0x3166AE31, 0x3E6FA23E, 0x16578216,
0x95106395, 0x5BEF015B, 0x4DB8834D, 0x91862E91, 0xB56DD9B5, 0x1F83511F,
0x53AA9B53, 0x635D7C63, 0x3B68A63B, 0x3FFEEB3F, 0xD630A5D6, 0x257ABE25,
0xA7AC16A7, 0x0F090C0F, 0x35F0E335, 0x23A76123, 0xF090C0F0, 0xAFE98CAF,
0x809D3A80, 0x925CF592, 0x810C7381, 0x27312C27, 0x76D02576, 0xE7560BE7,
0x7B92BB7B, 0xE9CE4EE9, 0xF10189F1, 0x9F1E6B9F, 0xA93453A9, 0xC4F16AC4,
0x99C3B499, 0x975BF197, 0x8347E183, 0x6B18E66B, 0xC822BDC8, 0x0E98450E,
0x6E1FE26E, 0xC9B3F4C9, 0x2F74B62F, 0xCBF866CB, 0xFF99CCFF, 0xEA1495EA,
0xED5803ED, 0xF7DC56F7, 0xE18BD4E1, 0x1B151C1B, 0xADA21EAD, 0x0CD3D70C,
0x2BE2FB2B, 0x1DC8C31D, 0x195E8E19, 0xC22CB5C2, 0x8949E989, 0x12C1CF12,
0x7E95BF7E, 0x207DBA20, 0x6411EA64, 0x840B7784, 0x6DC5396D, 0x6A89AF6A,
0xD17C33D1, 0xA171C9A1, 0xCEFF62CE, 0x37BB7137, 0xFB0F81FB, 0x3DB5793D,
0x51E10951, 0xDC3EADDC, 0x2D3F242D, 0xA476CDA4, 0x9D55F99D, 0xEE82D8EE,
0x8640E586, 0xAE78C5AE, 0xCD25B9CD, 0x04964D04, 0x55774455, 0x0A0E080A,
0x13508613, 0x30F7E730, 0xD337A1D3, 0x40FA1D40, 0x3461AA34, 0x8C4EED8C,
0xB3B006B3, 0x6C54706C, 0x2A73B22A, 0x523BD252, 0x0B9F410B, 0x8B027B8B,
0x88D8A088, 0x4FF3114F, 0x67CB3167, 0x4627C246, 0xC06727C0, 0xB4FC90B4,
0x28382028, 0x7F04F67F, 0x78486078, 0x2EE5FF2E, 0x074C9607, 0x4B655C4B,
0xC72BB1C7, 0x6F8EAB6F, 0x0D429E0D, 0xBBF59CBB, 0xF2DB52F2, 0xF34A1BF3,
0xA63D5FA6, 0x59A49359, 0xBCB90ABC, 0x3AF9EF3A, 0xEF1391EF, 0xFE0885FE,
0x01914901, 0x6116EE61, 0x7CDE2D7C, 0xB2214FB2, 0x42B18F42, 0xDB723BDB,
0xB82F47B8, 0x48BF8748, 0x2CAE6D2C, 0xE3C046E3, 0x573CD657, 0x859A3E85,
0x29A96929, 0x7D4F647D, 0x94812A94, 0x492ECE49, 0x17C6CB17, 0xCA692FCA,
0xC3BDFCC3, 0x5CA3975C, 0x5EE8055E, 0xD0ED7AD0, 0x87D1AC87, 0x8E057F8E,
0xBA64D5BA, 0xA8A51AA8, 0xB7264BB7, 0xB9BE0EB9, 0x6087A760, 0xF8D55AF8,
0x22362822, 0x111B1411, 0xDE753FDE, 0x79D92979, 0xAAEE88AA, 0x332D3C33,
0x5F794C5F, 0xB6B702B6, 0x96CAB896, 0x5835DA58, 0x9CC4B09C, 0xFC4317FC,
0x1A84551A, 0xF64D1FF6, 0x1C598A1C, 0x38B27D38, 0xAC3357AC, 0x18CFC718,
0xF4068DF4, 0x69537469, 0x749BB774, 0xF597C4F5, 0x56AD9F56, 0xDAE372DA,
0xD5EA7ED5, 0x4AF4154A, 0x9E8F229E, 0xA2AB12A2, 0x4E62584E, 0xE85F07E8,
0xE51D99E5, 0x39233439, 0xC1F66EC1, 0x446C5044, 0x5D32DE5D, 0x72466872,
0x26A06526, 0x93CDBC93, 0x03DADB03, 0xC6BAF8C6, 0xFA9EC8FA, 0x82D6A882,
0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D,
0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10,
0xE2510FE2, 0x00000000, 0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6,
0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8 ];
| D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.