Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

C#: count DateTimeOffset.Now and UtcNow as reading the clock (#1270)

jakalijeyb5b46a80ecd6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eb40193e..c3044e71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- C#: `DateTimeOffset.Now` and `DateTimeOffset.UtcNow` count as reading the clock, as `DateTime.Now`
+ does. Before, a function that read the clock through `DateTimeOffset` was bridged as pure, and its
+ one recorded case was one moment that `diff` never matched again (#1256 by @jakalijey).
- `package` takes `-o` for `--out`, as `analyze` and `bridge` do. Before, `package -o dir` was
refused as an unknown argument (#1249 by @jakalijey).
- PHP, Swift and C: when a unit has functions that stay in the original language (a variadic one,
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index e3b2f6ee..d38b1b5e 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -240,6 +240,8 @@ fn clock_and_random(lang: Lang) -> &'static [&'static str] {
"DateTime.Now",
"DateTime.UtcNow",
"DateTime.Today",
+ "DateTimeOffset.Now",
+ "DateTimeOffset.UtcNow",
"Random",
"Guid.NewGuid",
],
@@ -1460,6 +1462,12 @@ mod tests {
"class X { static int F() { return DateTime.Now.Year; } }",
Risk::ClockAndRandom,
),
+ (
+ Lang::Csharp,
+ "X.cs",
+ "class X { static long F() { return DateTimeOffset.UtcNow.ToUnixTimeSeconds(); } }",
+ Risk::ClockAndRandom,
+ ),
(
Lang::Kotlin,
"X.kt",