File tree Expand file tree Collapse file tree 8 files changed +13
-13
lines changed
android/library/src/main/java/io/package
kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 8 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ 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 sec = floor( now).toLong()
14
- val usec = ((now - sec) * 1_000_000).toLong()
12
+ val now = Instant.now()
13
+ val sec = now.epochSecond
14
+ val usec = System.nanoTime() / 1000
15
15
16
16
// Convert both parts to hexadecimal format
17
17
val hexTimestamp = "%08x%05x".format(sec, usec)
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class ID {
9
9
static String _hexTimestamp() {
10
10
final now = DateTime.now();
11
11
final sec = (now.millisecondsSinceEpoch / 1000).floor();
12
- final usec = now.microsecondsSinceEpoch - sec * 1000000;
12
+ final usec = ( now.microsecondsSinceEpoch - sec) * 1000000;
13
13
return sec.toRadixString(16) +
14
14
usec.toRadixString(16).padLeft(5, '0');
15
15
}
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ export class ID {
4
4
static #hexTimestamp(): string {
5
5
const now = new Date();
6
6
const sec = Math.floor(now.getTime() / 1000);
7
- const usec = now.getMilliseconds() * 1000 ;
7
+ const msec = now.getMilliseconds();
8
8
9
9
// Convert to hexadecimal
10
- const hexTimestamp = sec.toString(16) + usec .toString(16).padStart(5, '0');
10
+ const hexTimestamp = sec.toString(16) + msec .toString(16).padStart(5, '0');
11
11
return hexTimestamp;
12
12
}
13
13
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ namespace {{ spec.title | caseUcfirst }}
11
11
var now = DateTime.UtcNow;
12
12
var epoch = (now - new DateTime(1970, 1, 1));
13
13
var sec = (long)epoch.TotalSeconds;
14
- var usec = (long)(epoch.TotalMilliseconds % 1000); // Corrected calculation for milliseconds
14
+ var usec = (long)(epoch.TotalMilliseconds * 1000);
15
15
16
16
// Convert to hexadecimal
17
17
var hexTimestamp = sec.ToString("x") + usec.ToString("x").PadLeft(5, '0');
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class ID {
11
11
private fun hexTimestamp(): String {
12
12
val now = Instant.now()
13
13
val sec = now.epochSecond
14
- val millis = now.toEpochMilli () % 1000
14
+ val usec = System.nanoTime () / 1000
15
15
16
16
val hexTimestamp = "%08x%05x".format(sec, millis)
17
17
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ class ID {
4
4
static #hexTimestamp = () => {
5
5
const now = new Date();
6
6
const sec = Math.floor(now.getTime() / 1000);
7
- const usec = now.getMilliseconds() * 1000 ;
7
+ const msec = now.getMilliseconds();
8
8
9
9
// Convert to hexadecimal
10
- const hexTimestamp = sec.toString(16) + usec .toString(16).padStart(5, '0');
10
+ const hexTimestamp = sec.toString(16) + msec .toString(16).padStart(5, '0');
11
11
return hexTimestamp;
12
12
}
13
13
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class ID:
9
9
def __hex_timestamp():
10
10
now = datetime.now()
11
11
sec = int(now.timestamp())
12
- usec = now.microsecond
12
+ usec = ( now.microsecond % 1000)
13
13
hex_timestamp = f'{sec:08x}{usec:05x}'
14
14
return hex_timestamp
15
15
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ export class ID {
4
4
static #hexTimestamp(): string {
5
5
const now = new Date();
6
6
const sec = Math.floor(now.getTime() / 1000);
7
- const usec = now.getMilliseconds() * 1000 ;
7
+ const msec = now.getMilliseconds();
8
8
9
9
// Convert to hexadecimal
10
- const hexTimestamp = sec.toString(16) + usec .toString(16).padStart(5, '0');
10
+ const hexTimestamp = sec.toString(16) + msec .toString(16).padStart(5, '0');
11
11
return hexTimestamp;
12
12
}
13
13
You can’t perform that action at this time.
0 commit comments