File tree Expand file tree Collapse file tree 10 files changed +29
-29
lines changed
android/library/src/main/java/io/appwrite
kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 10 files changed +29
-29
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import java.time.Instant
4
4
import kotlin.math.floor
5
5
import kotlin.random.Random
6
6
7
- // Generate a unique ID based on timestamp
7
+ // Generate an hex ID based on timestamp
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
- private fun uniqueId (): String {
9
+ private fun hexTimestamp (): String {
10
10
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
11
11
val secondsPart = floor(currentTimestamp).toLong()
12
12
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -24,7 +24,7 @@ class ID {
24
24
// Generate a unique ID with padding to have a longer ID
25
25
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
26
26
fun unique(padding: Int = 7): String {
27
- val baseId = uniqueId ()
27
+ val baseId = hexTimestamp ()
28
28
val randomPadding = (1..padding)
29
29
.map { Random.nextInt(0, 16).toString(16) }
30
30
.joinToString("")
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ part of {{ language.params.packageName }};
4
4
class ID {
5
5
ID._();
6
6
7
- // Generate a unique ID based on timestamp
7
+ // Generate an hex ID based on timestamp
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
- static String _uniqueId () {
9
+ static String _hexTimestamp () {
10
10
final now = DateTime.now();
11
11
final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
12
12
final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
@@ -17,7 +17,7 @@ class ID {
17
17
// Generate a unique ID with padding to have a longer ID
18
18
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19
19
static String unique({int padding = 7}) {
20
- String id = _uniqueId ();
20
+ String id = _hexTimestamp ();
21
21
22
22
if (padding > 0) {
23
23
StringBuffer sb = StringBuffer();
Original file line number Diff line number Diff line change 1
1
export class ID {
2
- // Generate a unique ID based on timestamp
2
+ // Generate an hex ID based on timestamp
3
3
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4
- static #uniqueId (): string {
4
+ static #hexTimestamp (): string {
5
5
const now = new Date();
6
6
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
7
7
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -19,7 +19,7 @@ export class ID {
19
19
// Generate a unique ID with padding to have a longer ID
20
20
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
21
21
public static unique(padding: number = 7): string {
22
- const baseId = ID.#uniqueId ();
22
+ const baseId = ID.#hexTimestamp ();
23
23
let randomPadding = '';
24
24
25
25
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ namespace {{ spec.title | caseUcfirst }}
4
4
{
5
5
public static class ID
6
6
{
7
- // Generate a unique ID based on timestamp
7
+ // Generate an hex ID based on timestamp
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
- private static string uniqueId ()
9
+ private static string hexTimestamp ()
10
10
{
11
11
var now = DateTime.UtcNow;
12
12
var secondsSinceEpoch = (long)(now - new DateTime(1970, 1, 1)).TotalSeconds;
@@ -23,7 +23,7 @@ namespace {{ spec.title | caseUcfirst }}
23
23
public static string Unique(int padding = 7)
24
24
{
25
25
var random = new Random();
26
- var baseId = uniqueId ();
26
+ var baseId = hexTimestamp ();
27
27
var randomPadding = "";
28
28
29
29
for (int i = 0; i < padding; i++)
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import java.time.Instant
4
4
import kotlin.math.floor
5
5
import kotlin.random.Random
6
6
7
- // Generate a unique ID based on timestamp
7
+ // Generate an hex ID based on timestamp
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
- private fun uniqueId (): String {
9
+ private fun hexTimestamp (): String {
10
10
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
11
11
val secondsPart = floor(currentTimestamp).toLong()
12
12
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -23,7 +23,7 @@ class ID {
23
23
// Generate a unique ID with padding to have a longer ID
24
24
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
25
25
fun unique(padding: Int = 7): String {
26
- val baseId = uniqueId ()
26
+ val baseId = hexTimestamp ()
27
27
val randomPadding = (1..padding)
28
28
.map { Random.nextInt(0, 16).toString(16) }
29
29
.joinToString("")
Original file line number Diff line number Diff line change 1
1
class ID {
2
- // Generate a unique ID based on timestamp
2
+ // Generate an hex ID based on timestamp
3
3
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4
4
static #uniqueId = () => {
5
5
const now = new Date();
@@ -15,7 +15,7 @@ class ID {
15
15
// Generate a unique ID with padding to have a longer ID
16
16
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
17
17
static unique = (padding = 7) => {
18
- const baseId = ID.#uniqueId ();
18
+ const baseId = ID.#hexTimestamp ();
19
19
let randomPadding = '';
20
20
21
21
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ from datetime import datetime
2
2
import random
3
3
4
4
class ID:
5
- # Generate a unique ID based on timestamp
5
+ # Generate an hex ID based on timestamp
6
6
# Recreated from https://www.php.net/manual/en/function.uniqid.php
7
7
@staticmethod
8
- def __uniqueId ():
8
+ def __hex_timestamp ():
9
9
now = datetime.now()
10
10
seconds_since_epoch = int(now.timestamp())
11
11
microseconds_part = now.microsecond
@@ -20,6 +20,6 @@ class ID:
20
20
# Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
21
21
@staticmethod
22
22
def unique(padding = 7):
23
- base_id = ID.__uniqueId ()
23
+ base_id = ID.__hex_timestamp ()
24
24
random_padding = ''.join(random.choice('0123456789abcdef') for _ in range(padding))
25
25
return base_id + random_padding
Original file line number Diff line number Diff line change 1
1
require 'securerandom'
2
2
3
- #Generate a unique ID based on timestamp
3
+ #Generate an hex ID based on timestamp
4
4
#Recreated from https://www.php.net/manual/en/function.uniqid.php
5
- def uniqueId
5
+ def hex_timestamp
6
6
now = Time.now
7
7
seconds_since_epoch = now.to_i
8
8
microseconds_part = now.usec
@@ -19,7 +19,7 @@ module {{spec.title | caseUcfirst}}
19
19
# Generate a unique ID with padding to have a longer ID
20
20
# Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
21
21
def self.unique(padding=7)
22
- base_id = uniqueId
22
+ base_id = hex_timestamp
23
23
random_padding = SecureRandom.hex(padding)
24
24
random_padding = random_padding[0...padding]
25
25
base_id + random_padding
Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
- // Generate a unique ID based on timestamp
3
+ // Generate an hex ID based on timestamp
4
4
// Recreated from https://www.php.net/manual/en/function.uniqid.php
5
- func uniqueId () -> String {
5
+ func hexTimestamp () -> String {
6
6
let now = Date()
7
7
let secondsSinceEpoch = Int(now.timeIntervalSince1970)
8
8
let microsecondsPart = Int((now.timeIntervalSince1970 - Double(secondsSinceEpoch)) * 1_000_000)
@@ -18,7 +18,7 @@ public class ID {
18
18
// Generate a unique ID with padding to have a longer ID
19
19
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
20
20
public static func unique(padding: Int = 7) -> String {
21
- let baseId = uniqueId ()
21
+ let baseId = hexTimestamp ()
22
22
let randomPadding = (1...padding).map {
23
23
_ in String(format: "%x", Int.random(in: 0..<16 ))
24
24
}.joined ()
Original file line number Diff line number Diff line change 1
- // Generate a unique ID based on timestamp
1
+ // Generate an hex ID based on timestamp
2
2
// Recreated from https://www.php.net/manual/en/function.uniqid.php
3
- function uniqueId (): string {
3
+ function hexTimestamp (): string {
4
4
const now = new Date();
5
5
const secondsSinceEpoch = Math.floor(now.getTime() / 1000); // Get Unix Timestamp
6
6
const microsecondsPart = now.getMilliseconds() * 1000; // Convert milliseconds to microseconds
@@ -16,7 +16,7 @@ export class ID {
16
16
public static unique(padding: number = 7): string {
17
17
// Generate a unique ID with padding to have a longer ID
18
18
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19
- const baseId = uniqueId ();
19
+ const baseId = hexTimestamp ();
20
20
let randomPadding = '';
21
21
for (let i = 0; i < padding; i++) {
22
22
const randomHexDigit = Math.floor(Math.random() * 16).toString(16);
You can’t perform that action at this time.
0 commit comments