 func +(lhs: Nano, rhs: String) -> String { return lhs.s + rhs; }
 func +(lhs: String, rhs: Nano) -> String { return lhs + rhs.s; }
 func +(lhs: Nano, rhs: Nano) -> Nano { return Nano(lhs.value + rhs.value); }
+func -(lhs: Nano, rhs: Nano) -> Nano { return Nano(lhs.value - rhs.value); }
 
 extension Int {
 	var ns: Nano { return Nano(Int64(self)) }

	var y: Nano { return self * u_year }
}

func test_seconds() {
	print("Testing second operations:\n")
	print("\(Nano(500)) = \(500.ns)")

	}

	var description: String {
		assert(self.value >= 0)
		if (self.value < 1) {
			return "0s"
		}

		let nano = self.value % 1_000_000_000
		var seconds = (self.value / 1_000_000_000) % 60
		var minutes = self.value / 60_000_000_000

		var result = (0 == nano ? "" : "\(nano)ns")
		result = (0 == seconds ? result : "\(seconds)s\(result)")
		if (minutes < 1) {
			return result
		}

		var hours = minutes / 60
		minutes = minutes % 60

		result = (0 == minutes ? result : "\(minutes)m\(result)")
		if (hours < 1) {
			return result
		}

		var days = hours / 24
		hours = hours % 24

		result = (0 == hours ? result : "\(hours)h\(result)")
		if (days < 1) {
			return result
		}

		let years = days / 365
		days = days % 365

		result = (0 == days ? result : "\(days)d\(result)")
		if (years < 1) {
			return result
		}

		return "\(years)y\(result)"
	}

	var s: String { return description }

	func year() -> Int { return Int(self.value / u_year.value); }

	func month() -> Int {
		let result = Int(self.value / u_day.value) % 365
		return 1 + result % 12
	}

	func week() -> Int {
		let result = Int(self.value / u_day.value) % 365
		return 1 + result / 7
	}

	func day() -> Int {
		let result = Int(self.value / u_day.value) % 365
		return 1 + result % 30
	}

	func hour() -> Int {
		let result = Int(self.value / u_hour.value)
		return result % 24
	}

	func minute() -> Int {
		let result = Int(self.value / u_minute.value)
		return result % 60
	}

	func second() -> Int {
		let result = Int(self.value / u_second.value)
		return result % 60
	}

	func millisecond() -> Int {
		return Int(self.value % u_second.value) / 1_000_000
	}

	func microsecond() -> Int {
		return Int(self.value % u_second.value) / 1_000
	}

	func nanosecond() -> Int {
		return Int(self.value % u_second.value)
	}
}

func *(lhs: Nano, rhs: Int) -> Nano { return Nano(lhs.value * Int64(rhs)); }
