CROSS-PLATFORM ● ENGLISH ● 18+

SORRY, WE ARE CLOSED
WHAT'S NEW?
16/07: Stick to your guns ►►
16/06: The first steps ►►
01/06: We are officially open ►►

CC: PIE

User info

Welcome, Guest! Please login or register.


You are here » CC: PIE » living room » flood #4 midsummer night's dream


flood #4 midsummer night's dream

Posts 361 to 390 of 846

1

https://forumupload.ru/uploads/001c/2a/e6/22/137356.jpg

Previous pictures

Last edited by Coffee table knight (2024-07-20 10:00:40)

+3

361

В Питере теперь знаю больше исторических мест чем в родной Москве, а так всегда - где живешь, там все пофиг

+3

362

The Herald
I've been to Ermitage once. When my friend came to visit )

+2

363

I know a lot of places in Moscow (a native Muscovite). And I know several attractions in St. Petersburg

+2

364

Coffee table knight
soon you'll know all the places in Belgrad  :D

+1

365

#p14282,Lucifer wrote:

soon you'll know all the places in Belgrad

Dream of going to museums. While I visited the botanical garden and zoo. It was amazing!

+1

366

I always considered Moscow grey and dull, but, in the hindsight, it might be because I never went exploring further than the route from home to school/work. But now I know the waterfront of Toronto almost intimately :D

+1

367

we bought a comic in serbian)))
I like how they call wonder woman: чудесна жена

+2

368

Cheetah = Гепардица

+2

369

42
How are you doing today?)

0

370

#p14285,newest chronology wrote:

wonder woman: чудесна жена

if I ever have a wife that's how I'll call her

+2

371

Lucifer
I have an interesting brain-wrecking task, so I'm good)
And you?

+1

372

#p14291,42 wrote:

I have an interesting brain-wrecking task, so I'm good)

is it work related or one of your pet projects?

0

373

Lucifer
Work-related this time. In truth, it sounds rather simple, but when you start coding it, it gets quite complicated

+1

374

42
well, you like a challenge )

0

375

Lucifer
I do. And I've always solved it (at least in broad strokes), but I cannot pin down how to write the recursion nicely here...

+1

376

#p14292,Lucifer wrote:

And you?

My leave starts in 15 minutes. I'm counting  :D

+1

377

Lucifer
Lucky you!

I think I more or less did it!

Just look at this beauty!

const timeStart = '2023-05-12 00:00:00';
const timeEnd = '2024-07-15 23:59:59';

const timeStartDate = new Date(timeStart);
let timeEndDate = new Date(timeEnd);
timeEndDate = new Date(timeEndDate.valueOf() + 1000)

const periods = {
    "year": [],
    "month": [],
    "week": [],
    "day": [],
    "hour": []
}

function extractPeriods(timeStartDate, timeEndDate, period) {
    let lastPeriodStart = new Date(timeEndDate);
    lastPeriodStart = getFirstDayOfPeriod(lastPeriodStart, period)

    let prevPeriodStart = new Date(lastPeriodStart);
    prevPeriodStart = onePeriodBack(prevPeriodStart, period);
    let prev = new Date(prevPeriodStart);
    while (timeStartDate < prevPeriodStart) {
        periods[period].push(prevPeriodStart.toISOString())
        prev = new Date(prevPeriodStart);
        prevPeriodStart = onePeriodBack(prevPeriodStart, period);
    }
    if (timeStartDate < prev) {
        return [
            {
                timeStartDate: timeStartDate,
                timeEndDate: prev
            },
            {
                timeStartDate: lastPeriodStart,
                timeEndDate: timeEndDate
            }
        ]
    } else {
        return [
            {
                timeStartDate: timeStartDate,
                timeEndDate: timeEndDate
            }
        ]
    }
}

function getFirstDayOfPeriod(date, period) {
    switch (period) {
        case "year":
            date.setMonth(0, 1);
            return date;
        case "month":
            date.setDate(1);
            return date;
        case "week":
            const d = date.getDay()
            date.setDate(date.getDate() - d);
            return date;
        case "day":
            return date;
        case "hour":
            return date;
    }
}

function onePeriodBack(date, period) {
    switch(period) {
        case "year":
            date.setFullYear(date.getFullYear() - 1)
            return date;
        case "month":
            date.setMonth(date.getMonth() - 1);
            return date;
        case "week":
            date = new Date(date.valueOf() - 604800000);
            return date;
        case "day":
            date = new Date(date.valueOf() - 86400000);
            return date;
        case "hour":
            date = new Date(date.valueOf() - 36000000);
            return date;
    }
}

const timeIntervals = [ {
    timeStartDate: timeStartDate,
    timeEndDate: timeEndDate
}];
const periodNames = ['year', 'month', 'week', 'day', 'hour']

function extractPeriodsRecursive(timeIntervals, periodNameIndex) {
    timeIntervals.forEach((timeInterval) => {
        const newTimeIntervals = extractPeriods(timeInterval['timeStartDate'], timeInterval['timeEndDate'], periodNames[periodNameIndex])
        if (periodNameIndex < periodNames.length - 1) {
            extractPeriodsRecursive(newTimeIntervals, periodNameIndex + 1)
        }
    })
}

extractPeriodsRecursive(timeIntervals, 0);

Last edited by 42 (2024-07-22 22:00:31)

+2

378

https://forumupload.ru/uploads/000b/09/4f/30026/922607.png that's a lot of code

+1

379

Faded Star
It's not as big as it looks, there are a couple of switches inside.

Basically, what it is supposed to do, given an arbitrary time period, it will split it into some calendar periods trying to prioritize the largest. So, if it's, say, a period of three years and some days, it will extract the full calendar years first, than, from the remaining time, it will extract all the full calendar months, than weeks, days and finally hours (my time periods don't go more granular than hours).

+2

380

#p14500,42 wrote:

Faded Star
It's not as big as it looks, there are a couple of switches inside.

Basically, what it is supposed to do, given an arbitrary time period, it will split it into some calendar periods trying to prioritize the largest. So, if it's, say, a period of three years and some days, it will extract the full calendar years first, than, from the remaining time, it will extract all the full calendar months, than weeks, days and finally hours (my time periods don't go more granular than hours).

Sounds formidable even though hard for me to grasp as of now
Keep up the good work, it does not sound easy in the slightest

+1

381

Faded Star
This actually supposed to be the easiest part of the whole data processing module I've been developing :D But this time sorting algorithm is a little b*tch, it's true

+1

382

Why is the code similar to English? Is it a python that speaks Rudyard Kipling's language?

0

383

Coffee table knight
Why would not it be? The code consists of functions, memory blocks (variables) and operations. All these things need names, and ideally those names should be eloquent enough that, simply by looking at the name, you would guess what the function does. So yes, the names of the functions, variables and everything else always make perfect sense in English

+1

384

42
How do you know which words the progamming language recognizes in code and which ones it doesn’t? Who gives it a list of English words to recognize? And how to replenish a dictionary?

0

385

Coffee table knight
The compiler (the program) does not care about the words. All those words are names and needed only for humans' benefit. For the compiler they are simply names. Like "Jack" does not have any meaning on its own and simply points to a person, the same way calculateDates() does not mean anything for the compiler, it simply indicates which chunk of code to execute

+1

386

42
I mean, how do you know what to say in code, so the computer can do what you want?
For example, how do you know what to write exactly this?

const timeStart = '2023-05-12 00:00:00';
const timeEnd = '2024-07-15 23:59:59';

const timeStartDate = new Date(timeStart);
let timeEndDate = new Date(timeEnd);
timeEndDate = new Date(timeEndDate.valueOf() + 1000)

How do you know that the computer will understand you? Have you learned all these commands? Is there a dictionary of all the commands in the world? Who’s filling in the dictionary? The developers of the programming language?

+1

387

Coffee table knight
Yes. It's called "the programming language syntax". It is slightly different for every language although most of the languages are similar enough. Each language has specific rules for how you need to structure your commands and a set of predefined, the most commonly used functions (a very large set of thousands of functions usually). You do not have to know them all, of course, but the most common you memorize fast enough.
In a way, it is like learning another language

Last edited by 42 (2024-07-22 23:15:48)

+2

388

42
Wow, thank you, it's interesting!

0

389

Good morning  https://i.imgur.com/de3qc.gif

+2

390

Lucifer, hello! https://forumupload.ru/uploads/0019/a4/9b/6/20655.gif  New puzzles are waiting for you.

+1


You are here » CC: PIE » living room » flood #4 midsummer night's dream


Рейтинг форумов | Создать форум бесплатно