Author Topic: psdate - Converting dates between Yliakan and Gregorian calendars  (Read 835 times)

derula

  • Hydlaa Citizen
  • *
  • Posts: 405
  • My main: Jamona Shikon
    • View Profile
    • Ugly Horst Tld.
So I stumbled across neko's post here, and well there you go: Download script or visit online version. Please note that the results of the online version are based on the UTC time zone. There's obviously no IC timezones, thus I chose to use UTC, as it's a quasi-Standard by now. The local version uses local time zone, ATM.

Installation

If you do not want to install or download anything, please use the online version. It has the same features as the downloadable one but no prerequisites have to be installed.

If you want to use the script version, first, you need to install Ruby if you haven't done that yet. That will also allow you to use some other useful pieces of crap written by me (all available here in the Mods forum...)

Save the file somewhere on your computer, rename it to psdate or something (psdate.rb if you want to) and start it either like this,

Code: [Select]
./<filename>
after you set the executable bit (*nix), or like that,

Code: [Select]
ruby <filename>
(I will only use the first form in below examples with the filename psdate)

What will be shown if you run this simple command or open up the online version is the current date in Yliakum.

Advanced usage

If you call the script like this

Code: [Select]
./psdate -h
-or-
./psdate --help

it'll tell you about its other features:

Code: [Select]
Call: psdate [OPTION] [+FORMAT]
Returns the current date in Yliakum in the supplied FORMAT or converts an Yliakum date back to an IRL date.
 
Option can be one of the following:
 
  -d STRING      Return date according to STRING, not "today"
  -r MONTH/DAY   Convert the specified Yliakum date into a real date
 
FORMAT determines the output of an Yliakum date. The following statements can be used:
 
  %%   literal %
  %b   abbreviated month name ("Uno" through "Ynd")
  %B   the full month name ("Unodin" through "Yndoli")
  %d   day of the month (01 through 39)
  %D   counted day of the month (1st through 39th)
  %j   day of the year (001 through 366)
  %m   month of the year (01 through 12)

When using -r, this option is ignored and the date is returned in a default date format.

(For the online version, click here, and you'll get a similar message)

Basically that's two other features, one to convert an "arbitrary" date (other than "today") into a PS date, the other to transform a PS date back into an IRL date. Examples:

Code: [Select]
./psdate -r 5/12
http://psstatus.uglyhorst.de/date.php?reverse=5/12

will tell you which real date 12th Quintahl (fifth month) is on.

Code: [Select]
./psdate -d 12/13
http://psstatus.uglyhorst.de/date.php?date=12/13

will tell you what day December 13th will be in PS.

(the -d command accepts more different formats than -r, which just accepts the one specified above (MONTH/DAY). Errors on some strange formats though. Accepted formats most likely differ between the two versions.)

You can also have fun with changing the format of the output, e.g.

Code: [Select]
./psdate +%m-%d
http://psstatus.uglyhorst.de/date.php?format=%m-%d

would result in something like

Code: [Select]
Kra-29
Have fun guys.

(this is not thoroughly tested and might still contain leap year bugs - so tell me if you find it's off by one!)
« Last Edit: December 26, 2011, 03:31:29 pm by derula »

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: psdate - Converting dates between Yliakan and Gregorian calendars
« Reply #1 on: August 17, 2010, 01:43:09 am »
We definitely need that available as web form, for those who don't intend to install Ruby on an Operating System which doesn't include it out of the box. ;)

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

derula

  • Hydlaa Citizen
  • *
  • Posts: 405
  • My main: Jamona Shikon
    • View Profile
    • Ugly Horst Tld.
Re: psdate - Converting dates between Yliakan and Gregorian calendars
« Reply #2 on: August 17, 2010, 06:37:15 am »
We definitely need that available as web form, for those who don't intend to install Ruby on an Operating System which doesn't include it out of the box. ;)

My webspace doesn't support Ruby... so I ported it to PHP. Reminded me how much I hate PHP and why I did it in Ruby in the first place. Here's the link, right next to my status script :P It's basically the same program, but "advanced usage" works a bit differently. Click here to get to the help page.

Also, I've fixed an off-by-one issue that occurred with the -r option. Download fixed Ruby version here, if you care (PHP version includes the fix too of course).
« Last Edit: August 17, 2010, 06:50:12 am by derula »

Orgonwukh

  • Hydlaa Citizen
  • *
  • Posts: 254
    • View Profile
Re: psdate - Converting dates between Yliakan and Gregorian calendars
« Reply #3 on: August 17, 2010, 12:39:56 pm »
Nice idea, derula, but not totally new ;)

See http://www.hydlaaplaza.com/smf/index.php?topic=36553.msg415796#msg415796

Careful, my first settings request concerning that topic was removed without warning (you might be walking on thin ice playing with Planeshift date and time). In that post, I also was told by the settings team that dates and time in Planeshift will not be implemented in the near future. So I stopped developing that idea (among others). That was months ago however.
Maybe you find something useful in my code, good luck with your project.  :thumbup:

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: psdate - Converting dates between Yliakan and Gregorian calendars
« Reply #4 on: August 18, 2010, 01:06:01 am »
As long as the result is only referenced in planning events, it is just as valid as the date conversion on the calendar events pages.

Just the time in-game is not in any continuous relation to the time in real life.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

derula

  • Hydlaa Citizen
  • *
  • Posts: 405
  • My main: Jamona Shikon
    • View Profile
    • Ugly Horst Tld.
Re: psdate - Converting dates between Yliakan and Gregorian calendars
« Reply #5 on: August 29, 2010, 04:27:39 am »
it is just as valid as the date conversion on the calendar events pages.

That was the aim. Date / time in PS is inconsistent and unpredictable anyway. It's just so you are able to specify a date in RP announcements; "Blabla will take place on [Oct 24th]" just looks ugly.

I've decided to use UTC as a reference point instead of Central European time. Also, if you enter a time with time zone, the date will be converted to UTC first. Let me clarify. Say, you live in UTC-6 and want to host an event in 11pm, local time, on October 24th. Usually, you would look for

Code: [Select]
http://psstatus.uglyhorst.de/date?date=10/24
and that's reasonable. The reply will be "Azhord 26th". However, in UTC, your event will take place on Azhord 27th. If you want to be sure to get the right answer, you can type something like

Code: [Select]
http://psstatus.uglyhorst.de/date?date=10/24,23:00,-0600
i.e., date and time of the event and your local time zone. If you do this, we can count on PS dates to be in UTC at all times. (I couldn't figure out how to type the meridian in correctly; either convert to 24h-format or try to understand this better than me).

Also (actual point of this posting) I found a leap year bug and fixed it in both online and offline versions. I can't guarantee it was the only leap year bug though; we'll see :)

Edit: O btw here's the link to the fixed offline version.

Edit: Fixed some more bugs. The reverse conversion method didn't really work well; in the online version, it was rather horrible. Also: fixed handling of "st"/"nd"/"rd"/"th" counting suffixes. Get the offline version here.

Edit: Fixed the online version to return only dates in in the range 1..32. Also: added options to retrieve week of year and day of week.
« Last Edit: November 19, 2010, 05:00:03 pm by derula »