File tree Expand file tree Collapse file tree 10 files changed +37
-40
lines changed
android/library/src/main/java/io/appwrite
kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 10 files changed +37
-40
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ class ID {
10
10
// Recreated from https://www.php.net/manual/en/function.uniqid.php
11
11
private fun hexTimestamp(): String {
12
12
val now = Instant.now().toEpochMilli() / 1000.0
13
- val secondsSinceEpoch = floor(now).toLong()
14
- val msecs = ((now - secondsSinceEpoch ) * 1_000_000).toLong()
13
+ val sec = floor(now).toLong()
14
+ val usec = ((now - sec ) * 1_000_000).toLong()
15
15
16
16
// Convert both parts to hexadecimal format
17
- val hexTimestamp = "%08x%05x".format(secondsSinceEpoch, msecs )
17
+ val hexTimestamp = "%08x%05x".format(sec, usec )
18
18
return hexTimestamp
19
19
}
20
20
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ class ID {
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
9
static String _hexTimestamp() {
10
10
final now = DateTime.now();
11
- final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
12
- final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
13
- return secondsSinceEpoch .toRadixString(16) +
14
- msecs .toRadixString(16).padLeft(5, '0');
11
+ final sec = (now.millisecondsSinceEpoch / 1000).floor();
12
+ final usec = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
13
+ return sec .toRadixString(16) +
14
+ usec .toRadixString(16).padLeft(5, '0');
15
15
}
16
16
17
17
// Generate a unique ID with padding to have a longer ID
Original file line number Diff line number Diff line change @@ -3,12 +3,11 @@ export class ID {
3
3
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4
4
static #hexTimestamp(): string {
5
5
const now = new Date();
6
- const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
7
- const msecs = now.getTime() - secondsSinceEpoch * 1000;
8
- const microsecondsPart = msecs * 1000; // Convert milliseconds to microseconds
6
+ const sec = Math.floor(now.getTime() / 1000);
7
+ const usec = now.getMilliseconds() * 1000;
9
8
10
9
// Convert to hexadecimal
11
- const hexTimestamp = secondsSinceEpoch .toString(16) + microsecondsPart .toString(16).padStart(5, '0');
10
+ const hexTimestamp = sec .toString(16) + usec .toString(16).padStart(5, '0');
12
11
return hexTimestamp;
13
12
}
14
13
Original file line number Diff line number Diff line change @@ -10,13 +10,12 @@ namespace {{ spec.title | caseUcfirst }}
10
10
{
11
11
var now = DateTime.UtcNow;
12
12
var epoch = (now - new DateTime(1970, 1, 1));
13
- var secondsSinceEpoch = (long)epoch.TotalSeconds;
14
- var msecs = epoch.TotalMilliseconds - secondsSinceEpoch * 1000;
15
- var microsecondsPart = (long)(msecs * 1000); // Convert milliseconds to microseconds
16
-
13
+ var sec = (long)epoch.TotalSeconds;
14
+ var usec = epoch.TotalMilliseconds - secondsSinceEpoch * 1000000;
15
+
17
16
// Convert to hexadecimal
18
- var hexTimestamp = secondsSinceEpoch .ToString("x")
19
- + microsecondsPart .ToString("x").PadLeft(5, '0');
17
+ var hexTimestamp = sec .ToString("x")
18
+ + usec .ToString("x").PadLeft(5, '0');
20
19
return hexTimestamp;
21
20
}
22
21
Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ class ID {
9
9
// Generate an hex ID based on timestamp
10
10
// Recreated from https://www.php.net/manual/en/function.uniqid.php
11
11
private fun hexTimestamp(): String {
12
- val now = Instant.now().toEpochMilli() / 1000.0
13
- val secondsSinceEpoch = floor(now).toLong()
14
- val msecs = ((now - secondsSinceEpoch) * 1_000_000).toLong()
12
+ val now = Instant.now()
13
+ val sec = now.epochSecond
14
+ val millis = now.toEpochMilli() % 1000
15
+
16
+ val hexTimestamp = "%08x%03x".format(sec, millis)
15
17
16
- // Convert both parts to hexadecimal format
17
- val hexTimestamp = "%08x%05x".format(secondsSinceEpoch, msecs)
18
18
return hexTimestamp
19
19
}
20
20
Original file line number Diff line number Diff line change @@ -3,13 +3,11 @@ class ID {
3
3
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4
4
static #hexTimestamp = () => {
5
5
const now = new Date();
6
- const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
7
- const msecs = now.getTime() - secondsSinceEpoch * 1000;
8
- const microsecondsPart = msecs * 1000; // Convert milliseconds to microseconds
6
+ const sec = Math.floor(now.getTime() / 1000);
7
+ const usec = now.getMilliseconds() * 1000;
9
8
10
9
// Convert to hexadecimal
11
- const hexTimestamp = secondsSinceEpoch.toString(16)
12
- + microsecondsPart.toString(16).padStart(5, '0');
10
+ const hexTimestamp = sec.toString(16) + usec.toString(16).padStart(5, '0');
13
11
return hexTimestamp;
14
12
}
15
13
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ class ID:
8
8
@staticmethod
9
9
def __hex_timestamp():
10
10
now = datetime.now()
11
- seconds_since_epoch = int(now.timestamp())
12
- microseconds_part = now.microsecond
13
- hex_timestamp = f'{seconds_since_epoch :08x}{microseconds_part :05x}'
11
+ sec = int(now.timestamp())
12
+ usec = now.microsecond
13
+ hex_timestamp = f'{sec :08x}{usec :05x}'
14
14
return hex_timestamp
15
15
16
16
@staticmethod
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ module {{spec.title | caseUcfirst}}
20
20
#Recreated from https://www.php.net/manual/en/function.uniqid.php
21
21
def self.hex_timestamp
22
22
now = Time.now
23
- seconds_since_epoch = now.to_i
24
- microseconds_part = now.usec
25
- hex_timestamp = "%08x%05x" % [seconds_since_epoch, microseconds_part ]
23
+ sec = now.to_i
24
+ usec = now.usec
25
+ hex_timestamp = "%08x%05x" % [sec, usec ]
26
26
hex_timestamp
27
27
end
28
28
end
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ public class ID {
5
5
// Recreated from https://www.php.net/manual/en/function.uniqid.php
6
6
private static func hexTimestamp() -> String {
7
7
let now = Date()
8
- let secondsSinceEpoch = Int(now.timeIntervalSince1970)
9
- let microsecondsPart = Int((now.timeIntervalSince1970 - Double(secondsSinceEpoch )) * 1_000_000)
10
- let hexTimestamp = String(format: "%08x%05x", secondsSinceEpoch, microsecondsPart )
8
+ let secs = Int(now.timeIntervalSince1970)
9
+ let usec = Int((now.timeIntervalSince1970 - Double(secs )) * 1_000_000)
10
+ let hexTimestamp = String(format: "%08x%05x", secs, usec )
11
11
return hexTimestamp
12
12
}
13
13
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ export class ID {
3
3
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4
4
static #hexTimestamp(): string {
5
5
const now = new Date();
6
- const secondsSinceEpoch = Math.floor(now.getTime() / 1000); // Get Unix Timestamp
7
- const microsecondsPart = now.getMilliseconds() * 1000; // Convert milliseconds to microseconds
8
- const hexTimestamp = secondsSinceEpoch.toString(16)
9
- + microsecondsPart.toString(16).padStart(5, '0');
6
+ const sec = Math.floor(now.getTime() / 1000);
7
+ const usec = now.getMilliseconds() * 1000;
8
+
9
+ // Convert to hexadecimal
10
+ const hexTimestamp = sec.toString(16) + usec.toString(16).padStart(5, '0');
10
11
return hexTimestamp;
11
12
}
12
13
You can’t perform that action at this time.
0 commit comments