Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Support Time-range Search #5

Open
JacobLinCool opened this issue Oct 14, 2022 · 1 comment
Open

How to Support Time-range Search #5

JacobLinCool opened this issue Oct 14, 2022 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@JacobLinCool
Copy link
Member

Encode timestamp into a number?

@JacobLinCool JacobLinCool moved this to 🆕 New in UniCourse Roadmap Oct 14, 2022
@skyhong2002 skyhong2002 added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 14, 2022
@skyhong2002 skyhong2002 moved this from 🆕 New to 💬 Discussing in UniCourse Roadmap Oct 20, 2022
@JacobLinCool
Copy link
Member Author

My current algorithm:

export class TimeRange {
    public start: number;
    public end: number;

    constructor(start: number, end: number);
    constructor(start: [number, number], end: [number, number]);
    constructor(start: number | [number, number], end: number | [number, number]) {
        if (Array.isArray(start) && Array.isArray(end)) {
            this.start = start[0] * (60 * 24) + start[1];
            this.end = end[0] * (60 * 24) + end[1];
        } else if (typeof start === "number" && typeof end === "number") {
            this.start = start;
            this.end = end;
        } else {
            throw new TypeError("Invalid arguments");
        }
    }

    public get code(): number {
        return this.start * 100_000 + this.end;
    }

    public in(range: TimeRange): boolean {
        return this.start >= range.start && this.end <= range.end;
    }
}

@skyhong2002 skyhong2002 moved this from 💬 Discussing to 🏗 In progress in UniCourse Roadmap Nov 4, 2022
@skyhong2002 skyhong2002 moved this from 🏗 In progress to 🔖 Ready in UniCourse Roadmap Nov 4, 2022
@skyhong2002 skyhong2002 moved this from 🔖 Ready to 📋 Backlog in UniCourse Roadmap Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants