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

a way to synchronize the system to a timestamp #4

Open
ratacat opened this issue Oct 23, 2019 · 1 comment
Open

a way to synchronize the system to a timestamp #4

ratacat opened this issue Oct 23, 2019 · 1 comment
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed

Comments

@ratacat
Copy link

ratacat commented Oct 23, 2019

I am currently using something like this...which doesn't use any particular custom units, or their respective make functions. But it lets me synchronize the time to the real world, which I like. Also it prevents the game time from restarting every time the mud reboots (and I don't have to worry about saving it to disk or anything).

If this seems like a good feature to you, maybe I'll try to write it in a modular fashion to account for custom units and make functions.

here's my current manual way of doing it

function getSynchronize(datetime){
    let yfloat = (datetime * 48) / 31536000000;
    let ywhole = Math.floor(yfloat);
    let yremainder = yfloat - ywhole;

    let mfloat = yremainder * 12;
    let mwhole = Math.floor(mfloat);
    let mremainder = mfloat - mwhole;

    let dfloat = mremainder * 30;
    let dwhole = Math.floor(dfloat);
    let dremainder = dfloat - dwhole;

    let hfloat = dremainder * 24;
    let hwhole = Math.floor(hfloat);
    let hremainder = hfloat - hwhole;

    let ifloat = hremainder * 60;
    let iwhole = Math.floor(ifloat);
    let iremainder = ifloat - iwhole;

    return {minute: iwhole, hour: hwhole, day: dwhole, month: mwhole, year: ywhole - 2000};
}

An integrated function could be called with something like

let syncTo.timestamp = Date.now();
syncTo.offsets[customUnit] = -230
syncTo.offsets[otherCustomUnit] = +23
syncTo.conversionRatio = 48 // 1unit
syncTo.conversionUnit = 'minute'

or just add options in the config itself is probably a better idea...

state.TimeCrunch = new TimeCrunch(config,syncTo);

@seanohue
Copy link
Owner

Yes, it would be nice to be able to define a relation between the smallest defined unit of fantasy time and real-world milliseconds. I'd be open to that. Not sure about relying on the JavaScript Date object, though, but you're welcome to take a swing at a PR. Thanks for trying this out!

@seanohue seanohue added enhancement New feature or request help wanted Extra attention is needed hacktoberfest labels Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants