Page 1 of 1

Library Token for Dates (Gregorian Calendar)

Posted: Tue Oct 29, 2019 5:38 am
by Merudo
This framework can do basic operations with dates of the Gregorian ("real life") calendar. Leap years are fully accounted for.

B.C. years (years prior to year 1) are not currently supported, but all subsequent years are.

Features:
- Get the moon phase and weekday of a date
- Add days to a date
- Get the difference in days between two dates

Date formats supported:

YYYY-M-D (ISO 8601), ex: 2019-10-29
M/D/YYYY (US date), ex: 10/29/2019

Functions available:

- date.getMoon(asText, date): returns the Moon phase of the date. If asText is 1, returns name of phase, otherwise returns phase on a 0 to 8 scale (4: Full Moon).
- date.getWeekday(date): returns the day of the week for the date
- date.dateDifference(date1, date2): returns the number of days between two dates
- date.isDate(date): returns 1 if the date is valid, and 0 otherwise

- date.addDays(days, date): return the date occuring after X days
- date.addWeeks(weeks, date): return the date occuring after X weeks
- date.addMonths(months, date): return the date occuring after X months
- add.addYears(years, date): return the date occuring after X years

- getDay(asText, date): returns the day. If asText is 1, returns it with the text suffix such as "21st" instead of 21.
- getMonth(asText, date): returns the month. If asText is 1, returns the name of the month such as "February"
- getYear(date): returns the year

You can set a "CurrentDate" for your game world with date.setCurrentDate. Once set, omitting the "date" parameter with the previous functions will return information about the current date.

To add days/weeks/months/years to the current date and update it, you can use the following functions:

- addDaysToCurrent(days)
- addWeeksToCurrent(weeks)
- addMonthsToCurrent(months)
- addYearsToCurrent(years)

Examples:

Code: Select all

[r: date.getMoon(1, "2019-12-12")]
returns "Full"

Code: Select all

[h: date.setCurrentDate("1921-3-13")]
[r: date.getWeekday()], [r: date.getMonth(1)] [r: date.getDay(1)] of [r: date.getYear()]
returns "Sunday, March 13th of 1921"

Code: Select all

[h: date.setCurrentDate("1921-3-13")]
[r: date.addYears(3)],
[r: date.getYear()],
[r: date.getMonth(1)]
returns 1924-3-13, 1921, March

Code: Select all

[h: date.setCurrentDate("1921-3-13")]
[h: date.addYearsToCurrent(3)]
[r: date.getDate()]
returns 1924-3-13

Also available: calendar
calendar.png
calendar.png (64.91 KiB) Viewed 6545 times
Updates:
Spoiler
Update
1.5.1 (04/13/2020)
- Add option to delete event from date.modifyEventInput

1.5 (03/18/2020)
- New Event system added! The events will show up in the calendar. Use addEventInput to add an event, deleteEventInput to delete it, and modifyEventInput to edit it.

1.4 (03/03/2020)
- Add function "date.showCalendar2", to display a javascript calendar with improved speed.

1.3.1 (11/11/2019)
- Fix addDays and addDaysToCurrent not working correctly when the number of days is negative.
- Add function "date.showCalendar", showing the calendar of the current month.
- Add function "addTimeToCurrent", to add time to the current date through an Input window.
- Add function "date.setDate", to set a new current date through an Input window.
- Add function "date.setCalendar", to set a new current date through the calendar.

1.2
- Add functions date.addWeeks/Months/Years.
- Add functions date.addDaysToCurrent/WeeksToCurrent/MonthsToCurrent/YearsToCurrent

1.1
- Add function date.isDate(date)

1.01
- Fix inverted moon phases for pre-1900 dates
Installation:

Add the token to one of your maps, and reload the campaign.

updated version 1.5.2: viewtopic.php?p=277883#p277883

Download:

Re: Library Token for Dates (Gregorian Calendar)

Posted: Tue Oct 29, 2019 7:57 am
by Nin
Thanks for sharing.

Re: Library Token for Dates (Gregorian Calendar)

Posted: Tue Oct 29, 2019 10:08 am
by BearFather
I like this idea, one question does it support going back to say year 600? Or is only the data from a certain year on?

Re: Library Token for Dates (Gregorian Calendar)

Posted: Tue Oct 29, 2019 4:59 pm
by Merudo
BearFather wrote:
Tue Oct 29, 2019 10:08 am
I like this idea, one question does it support going back to say year 600? Or is only the data from a certain year on?
It should work for all A.D. years.

B.C. years are not currently supported.

Re: Library Token for Dates (Gregorian Calendar)

Posted: Tue Oct 29, 2019 6:01 pm
by Full Bleed
Thanks for sharing.

I haven't gotten a good look at this yet... but I was wondering how easy this will be to adapt to existing campaign worlds?

For example, my default Campaign world is Greyhawk: https://calendars.wikia.org/wiki/Greyhawk_Calendar

Re: Library Token for Dates (Gregorian Calendar)

Posted: Thu Oct 31, 2019 5:40 am
by Merudo
Full Bleed wrote:
Tue Oct 29, 2019 6:01 pm
Thanks for sharing.

I haven't gotten a good look at this yet... but I was wondering how easy this will be to adapt to existing campaign worlds?

For example, my default Campaign world is Greyhawk: https://calendars.wikia.org/wiki/Greyhawk_Calendar
Most of the code would have to be redone. Also, I do not know if there is a way for the Greyhawk dates to be written in the M/D/Y or Y-M-D format. How do you deal with Growfest / Richfest / Brewfest?

Re: Library Token for Dates (Gregorian Calendar)

Posted: Thu Oct 31, 2019 5:23 pm
by Full Bleed
Merudo wrote:
Thu Oct 31, 2019 5:40 am
Most of the code would have to be redone. Also, I do not know if there is a way for the Greyhawk dates to be written in the M/D/Y or Y-M-D format. How do you deal with Growfest / Richfest / Brewfest?
Yeah, those are essentially 7 day interim months. So the month field would have to be string compatible or a decimal:

.5 Needfest
3.5 Growfest
6.5 Richfest
9.5 Brewfest

I, honestly, don't track the calendar in my games very often (more often using broad generalizations)... but that's more because I don't have a good tool to do it. I just wondered how flexible/compatible your core would be to the various game system calendars out there. That calendars.wikia.org site I linked has lots of examples of cool calendars.

Campaign worlds have a habit of showcasing multiple moons, too. ;)

Re: Library Token for Dates (Gregorian Calendar)

Posted: Mon Mar 30, 2020 1:55 am
by digiacom
Just want to share that I adapted this library token to work with the Eberron calendar and I *love* it :) About to try to upgrade from 1.3.1 and very excited for events!

Re: Library Token for Dates (Gregorian Calendar)

Posted: Thu Apr 02, 2020 8:56 am
by bubblobill
Has anyone adapted this for use by the other 6 billion people on the planet?

Re: Library Token for Dates (Gregorian Calendar)

Posted: Mon Mar 08, 2021 3:48 pm
by wolph42
Small update by Wolph42 and Melek: added 'gm only' function to the dates. Simple checkbox you can turn on or off, showing the event to gms only.
Lib_date1.5.2.rptok
(29.02 KiB) Downloaded 57 times