StorytellerCZ / meteor-fictionaltime

Create your own fictional time!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MIT License Build Status Code Climate Test Coverage Issue Count

Under development, use with caution!

Fictional time

Fictional time allows you to create, display and convert units to and from your own (symetric) fictional time.

Installation

meteor add storyteller:fictionaltime

Now you can create your own fictional time anywhere in the code like this:

const myTime = new FictionalTime({connectedToET: false, beginning: false, units: [10, 100, 1000], separators: [":", ":"], declaration: "SUT", declarationLocation: "before"});

How to use

Creating time

In order to create a time you need the following values:

  • Array with the length of each unit in milliseconds
  • Begging date for your time in milliseconds (use new Date("your date").valueOf() or the same with Moment.js) if you choose to lock it with Earth Time.
  • Unit separators array with time declarator (this means that the first value in the array is for what will be display before the time itself and the same goes for the last value, so a GMT unit separators in American style would look like this: ["/", "/", " ", ":", ":"])
  • Declarator that will be placed "before" ('Earth Time '), "after" (' GMT') or at "both" ends (['Earth Time ', ' GMT']) - don't forget the spaces - or "none".
  • Where is the main unit declaration located at, options are: before, after, both, false

Get started - not yet working

First add the package to your project: meteor add storyteller:fictionaltime

Then you can initialize fictional time anywhere in your code.

const sut = {
  connectedToET: false,
  beginning: false,
  units: [500, 10, 100, 100, 1000],
  separators: [".", " ", ":", ":"],
  declaration: "SUT ",
  declarationLocation: "before"
};
const sutTime = new FictionalTime(sut);

Available functions

toTime

toTime(milliseconds)

milliseconds - the number of milliseconds you want to dispaly in the time

TODO: shorten the displayed time only to the relevant units

Example:

sut.toTime(100000)

Will return "0.000 0:01:00".

toDate

toDate(milliseconds)

milliseconds - the number of milliseconds you want to dispaly in the time

Same as toTime, but it also includes all the units and declaration.

Example:

sutTime.toDate(100000);

Will return "SUT 0.000 0:01:00".

toUnit

toUnit(milliseconds, position)

milliseconds - the number of milliseconds you want to convert to a given unit

position - position of the unit in the units array you provided in the definition of the time

Example:

sut.toUnit(50000000000, 0);

Will return 1.

unitToMilliseconds

unitToMilliseconds(count, unit)

milliseconds - the number of milliseconds you want to convert to a given unit

position - position of the unit in the units array you provided in the definition of the time

Opposite of toUnit, will return milliseconds to of the given unit.

Example:

sut.unitToMilliseconds(1, 0);

Will return 50000000000.

currentDateTime - coming in 0.2

If your time has an establishment date, then you can use this to display your current fictional date time.

sut.currentDateTime();

countdown - coming in 0.2

If your time has an establishment date, then you can create a countdown to a certain Earth date and time.

sut.countdown(new Date('2400-01-01').getMilliseconds());

About

Create your own fictional time!

License:MIT License


Languages

Language:TypeScript 95.0%Language:JavaScript 5.0%