[DONE] Tick -> Date conversion

Added by vl about 6 years ago

Currently, the date is displayed in Tick.

Could be nice to have an url like this:

http://www.example.com/date.php?tick=15615123581

that will return the human readable title.

We'll integrate it in the official website.

Update: It's now included in the ServerTick API


Replies (13)

RE: [WIP] Tick -> Date conversion - Added by zorglub about 6 years ago

Converter

 1<?php
 2
 3/* Basic constants */
 4/* 1 IG hour = 3 IRL minutes = 1800 ticks */
 5define('RYTIME_HOUR_TICKS', 1800);
 6define('RYTIME_DAY_HOURS', 24);
 7define('RYTIME_SEASON_DAYS', 90);
 8define('RYTIME_MONTH_DAYS', 30);
 9define('RYTIME_CYCLE_MONTHS', 12);
10define('RYTIME_JY_CYCLES', 4);
11define('RYTIME_WEEK_DAYS', 6);
12/* 0 = spring, 1 = summer, 2 = automn, 3 = winter */
13define('RYTIME_CYCLE_SEASONS', 4);
14/* Spring = season 0, starts on 61th day of JY */
15define('RYTIME_START_SPRING', 61);
16
17define('RYTIME_START_JY', 2525);
18
19/* Helpers */
20define('RYTIME_CYCLE_DAYS',RYTIME_CYCLE_MONTHS * RYTIME_MONTH_DAYS);
21define('RYTIME_JY_DAYS', RYTIME_CYCLE_DAYS * RYTIME_JY_CYCLES);
22define('RYTIME_JY_MONTHS', RYTIME_CYCLE_MONTHS * RYTIME_JY_CYCLES);
23
24/**
25 * Takes a server tick and returns a computed array
26 */
27function ryzom_time_compute($tick) {
28  $out = array();
29  $out["servertick"] = $tick;
30
31  $time_in_hours = $tick / RYTIME_HOUR_TICKS;
32  $day = $time_in_hours / RYTIME_DAY_HOURS;
33
34  $out["jena_year"] = floor($day / RYTIME_JY_DAYS + RYTIME_START_JY);
35  $out["day_of_jy"] = $day % RYTIME_JY_DAYS;
36  $out["month_of_jy"] = floor($out["day_of_jy"] / RYTIME_MONTH_DAYS);
37
38  $out["cycle"] = floor($out["day_of_jy"] / RYTIME_CYCLE_DAYS);
39  $out["day_of_cycle"] = $day % RYTIME_CYCLE_DAYS;
40  $out["month_of_cycle"] = $out["month_of_jy"] % RYTIME_CYCLE_MONTHS;
41
42  $out["day_of_month"] = $out["day_of_jy"] % RYTIME_MONTH_DAYS;
43  $out["day_of_week"] = $day % RYTIME_WEEK_DAYS;
44
45  $out["season"] = (($day + RYTIME_JY_DAYS - RYTIME_START_SPRING) % RYTIME_JY_MONTHS) % RYTIME_CYCLE_SEASONS;
46  $out["day_of_season"] = ($day - RYTIME_START_SPRING) % (RYTIME_SEASON_DAYS);
47
48  $out["time_of_day"] = $time_in_hours % RYTIME_DAY_HOURS;
49  return $out;
50}
51
52/** 
53 * Takes a computed ryzom time array and returns a SimpleXMLElement
54 */
55function ryzom_time_xmlize($rytime) {
56  $out = new SimpleXMLElement("<ryzom_time />");
57  foreach($rytime as $key => $value) {
58    $out->addChild($key, $value);
59  }
60  return $out;
61}
62
63/**
64 * Take a computed ryzom time array and returns the formatted date
65 * (Official 2004 Format without trailing JY)
66 */
67function ryzom_date_format($rytime) {
68  $RYTIME_MONTHS =
69    array(0 => 'Winderly', 1 => 'Germinally', 2 => 'Folilally', 3 => 'Floris',
70          4 => 'Medis', 5 => 'Thermis', 6 => 'Harvestor', 7 => 'Frutor',
71          8 => 'Fallenor', 9 =>  'Pluvia', 10 =>  'Mystia', 11 => 'Nivia');
72  $RYTIME_DAYS = array(0 => 'Prima', 1 => 'Dua', 2 => 'Tria', 
73                     3 => 'Quarta', 4 => 'Quinteth', 5 =>'Holeth');
74
75  # Day, Month DayOfMonth, CycleNth CA JY
76  return sprintf("%s, %s %d, %de CA %d",
77                 $RYTIME_DAYS[$rytime["day_of_week"]], 
78                 $RYTIME_MONTHS[$rytime["month_of_cycle"]], 
79         $rytime["day_of_month"],
80         $rytime["cycle"] + 1 /* 0-index */,
81         $rytime["jena_year"]);
82}
83
84/* Example
85  $time = file_get_contents('http://atys.ryzom.com/servertick/index.php?shardid=ani');
86  $rytime = ryzom_time_compute($time);
87  echo ryzom_date_format($rytime);
88  echo ryzom_time_xmlize($rytime)->asXML();
89*/
90?>

RE: [WIP] Tick -> Date conversion - Added by vl about 6 years ago

Thanks,

I added it in ServerTick API.

But I have strange value like "Prima, Winderly 0, 1e CA 2525" or in xml, I have <day_of_season>-61</day_of_season>

RE: [WIP] Tick -> Date conversion - Added by barbaros about 6 years ago

"day_of_month" needs a +1, like "cycle".

  # Day, Month DayOfMonth, CycleNth CA JY
  return sprintf("%s, %s %d, %de CA %d",
                 $RYTIME_DAYS[$rytime["day_of_week"]], 
                 $RYTIME_MONTHS[$rytime["month_of_cycle"]], 
         $rytime["day_of_month"] + 1,
         $rytime["cycle"] + 1 /* 0-index */,
         $rytime["jena_year"]);

  ----

  define('LEANON_OFFSET', -14.95*24*60*60*10);

Further there seems to be an offset, at least for Leanon.
To match the dates used by the event team, you will need to substract this from the servertick.

RE: [WIP] Tick -> Date conversion - Added by kervala about 6 years ago

Animation team never had access to real Ryzom date given by devs (they only used the server tick but didn't know the real Atys date corresponding to september 16th 2004), so I think they will have to adapt to it.

RE: [WIP] Tick -> Date conversion - Added by vl about 6 years ago

We plan to display the real atys time in game so we have to use the real computed tick or we'll have trouble.
So if the event invented some date, we'll have to break to fix the delta by RP. For example inventing a story :)

RE: [DONE] Tick -> Date conversion - Added by barbaros about 6 years ago

That explains it.

Here is a new version to fix the month_of_jy, season and day_of_season.
I've also removed all the zero-index from XML output to follow ISO standard, this allows easy display without adding +1 to most of the values.

<?php

/* Basic constants */
/* 1 IG hour = 3 IRL minutes = 1800 ticks */
define('RYTIME_HOUR_TICKS', 1800);
define('RYTIME_DAY_HOURS', 24);
define('RYTIME_SEASON_DAYS', 90);
define('RYTIME_MONTH_DAYS', 30);
define('RYTIME_CYCLE_MONTHS', 12);
define('RYTIME_JY_CYCLES', 4);
define('RYTIME_WEEK_DAYS', 6);
/* 0 = spring, 1 = summer, 2 = automn, 3 = winter */
define('RYTIME_CYCLE_SEASONS', 4);
/* Spring = season 0, starts on 61th day of JY */
define('RYTIME_START_SPRING', 61);

define('RYTIME_START_JY', 2525);

/* Helpers */
define('RYTIME_CYCLE_DAYS',RYTIME_CYCLE_MONTHS * RYTIME_MONTH_DAYS);
define('RYTIME_JY_DAYS', RYTIME_CYCLE_DAYS * RYTIME_JY_CYCLES);
define('RYTIME_JY_MONTHS', RYTIME_CYCLE_MONTHS * RYTIME_JY_CYCLES);

/**
 * Takes a server tick and returns a computed array
 */
function ryzom_time_compute($tick) {
  $out = array();
  $out["servertick"] = $tick;

  $time_in_hours = $tick / RYTIME_HOUR_TICKS;
  $day = $time_in_hours / RYTIME_DAY_HOURS;

  $out["jena_year"] = floor($day / RYTIME_JY_DAYS + RYTIME_START_JY);
  $out["day_of_jy"] = $day % RYTIME_JY_DAYS + 1;
  $out["month_of_jy"] = ceil($out["day_of_jy"] / RYTIME_MONTH_DAYS);

  $out["cycle"] = floor($out["day_of_jy"] / RYTIME_CYCLE_DAYS) + 1;
  $out["day_of_cycle"] = $day % RYTIME_CYCLE_DAYS + 1;
  $out["month_of_cycle"] = $out["month_of_jy"] % RYTIME_CYCLE_MONTHS;

  $out["day_of_month"] = $out["day_of_jy"] % RYTIME_MONTH_DAYS;
  $out["day_of_week"] = $day % RYTIME_WEEK_DAYS + 1;

  $out["season"] = (($day + RYTIME_JY_DAYS - RYTIME_START_SPRING) / RYTIME_SEASON_DAYS) % RYTIME_CYCLE_SEASONS + 1;

  $out["day_of_season"] = ($day + RYTIME_JY_DAYS - RYTIME_START_SPRING) % RYTIME_SEASON_DAYS + 1;

  $out["time_of_day"] = $time_in_hours % RYTIME_DAY_HOURS;
  return $out;
}

/** 
 * Takes a computed ryzom time array and returns a SimpleXMLElement
 */
function ryzom_time_xmlize($rytime) {
  $out = new SimpleXMLElement("<ryzom_time />");
  foreach($rytime as $key => $value) {
    $out->addChild($key, $value);
  }
  return $out;
}

/**
 * Take a computed ryzom time array and returns the formatted date
 * (Official 2004 Format without trailing JY)
 */
function ryzom_date_format($rytime) {
  $RYTIME_MONTHS =
    array(0 => 'Winderly', 1 => 'Germinally', 2 => 'Folilally', 3 => 'Floris',
          4 => 'Medis', 5 => 'Thermis', 6 => 'Harvestor', 7 => 'Frutor',
          8 => 'Fallenor', 9 =>  'Pluvia', 10 =>  'Mystia', 11 => 'Nivia');
  $RYTIME_DAYS = array(0 => 'Prima', 1 => 'Dua', 2 => 'Tria', 
                     3 => 'Quarta', 4 => 'Quinteth', 5 =>'Holeth');

  # Day, Month DayOfMonth, CycleNth CA JY
  return sprintf("%dh - %s, %s %d, %de CA %d",
    $rytime["time_of_day"],
    $RYTIME_DAYS[ $rytime["day_of_week"] - 1 ], 
    $RYTIME_MONTHS[ $rytime["month_of_cycle"] - 1 ], 
    $rytime["day_of_month"],
    $rytime["cycle"],
    $rytime["jena_year"]);
}

/* Example
  $time = file_get_contents('http://atys.ryzom.com/servertick/index.php?shardid=ani');
  $rytime = ryzom_time_compute($time);
  echo ryzom_date_format($rytime);
  echo ryzom_time_xmlize($rytime)->asXML();
*/
?>

RE: [DONE] Tick -> Date conversion - Added by zorglub about 6 years ago

Hi,

I had noticed that season was wrong because of a mismatch between JY_MONTHS and CYCLE_MONTHS in the modulo.

However, the other problem is the START_SPRING that was badly interpreted. T he year actuelly begins on Winderly 1, so the 61 days should not be applied only in season computation, but as a global offset on the tick.

I think the 0-index should be used internally and only modified when displaying the XML if we really don't want it in the XML because it makes the computations more complex (+1/-1 everywhere).

RE: [DONE] Tick -> Date conversion - Added by zorglub about 6 years ago

Here is a new proposal that takes this into account: * Fix computation of $out["season"] * Apply global 61 days tick offset * No more specific season offset
This now matches the IG season

I have kept the 0-index for the moment. Aren't computer guys more used to this ?

 1<?php
 2/* Basic constants */
 3/* 1 IG hour = 3 IRL minutes = 1800 ticks */
 4define('RYTIME_HOUR_TICKS', 1800);
 5define('RYTIME_DAY_HOURS', 24);
 6define('RYTIME_SEASON_DAYS', 90);
 7define('RYTIME_MONTH_DAYS', 30);
 8define('RYTIME_CYCLE_MONTHS', 12);
 9define('RYTIME_JY_CYCLES', 4);
10define('RYTIME_WEEK_DAYS', 6);
11/* 0 = spring, 1 = summer, 2 = automn, 3 = winter */
12define('RYTIME_CYCLE_SEASONS', 4);
13/* Tick is offset on server of 61 days. */
14define('RYTIME_TICK_OFFSET', 61 * RYTIME_DAY_HOURS * RYTIME_HOUR_TICKS);
15
16define('RYTIME_START_JY', 2525);
17
18/* Helpers */
19define('RYTIME_CYCLE_DAYS',RYTIME_CYCLE_MONTHS * RYTIME_MONTH_DAYS);
20define('RYTIME_JY_DAYS', RYTIME_CYCLE_DAYS * RYTIME_JY_CYCLES);
21define('RYTIME_JY_MONTHS', RYTIME_CYCLE_MONTHS * RYTIME_JY_CYCLES);
22
23/**
24 * Takes a server tick and returns a computed array
25 */
26function ryzom_time_compute($tick) {
27    $out = array();
28    $out["server_tick"] = $tick;
29
30    $time_in_hours = ($tick-RYTIME_TICK_OFFSET) / RYTIME_HOUR_TICKS;
31    $day = $time_in_hours / RYTIME_DAY_HOURS;
32
33    $out["jena_year"] = floor($day / RYTIME_JY_DAYS + RYTIME_START_JY);
34    $out["day_of_jy"] = $day % RYTIME_JY_DAYS;
35    $out["month_of_jy"] = floor($out["day_of_jy"] / RYTIME_MONTH_DAYS);
36
37    $out["cycle"] = floor($out["day_of_jy"] / RYTIME_CYCLE_DAYS);
38    $out["day_of_cycle"] = $day % RYTIME_CYCLE_DAYS;
39    $out["month_of_cycle"] = $out["month_of_jy"] % RYTIME_CYCLE_MONTHS;
40
41    $out["day_of_month"] = $out["day_of_jy"] % RYTIME_MONTH_DAYS;
42    $out["day_of_week"] = $day % RYTIME_WEEK_DAYS;
43
44    $out["season"] = ($day / RYTIME_SEASON_DAYS) % RYTIME_CYCLE_SEASONS;
45    $out["day_of_season"] = $day % RYTIME_SEASON_DAYS;
46
47    $out["time_of_day"] = $time_in_hours % RYTIME_DAY_HOURS;
48    return $out;
49}
50
51/**
52 * Takes a computed ryzom time array and returns a SimpleXMLElement
53 */
54function ryzom_time_xmlize($rytime) {
55    $out = new SimpleXMLElement('<ryzom_time/>');
56    foreach($rytime as $key => $value) {
57        $out->addChild($key, $value);
58    }
59    return $out;
60}
61
62/**
63 * Take a computed ryzom time array and returns the formatted date
64 * (Official 2004 Format without trailing JY)
65 */
66function ryzom_date_format($rytime) {
67  $RYTIME_MONTHS =
68      array(0 => 'Winderly', 1 => 'Germinally', 2 => 'Folilally', 3 => 'Floris',
69            4 => 'Medis', 5 => 'Thermis', 6 => 'Harvestor', 7 => 'Frutor',
70            8 => 'Fallenor', 9 =>  'Pluvia', 10 =>  'Mystia', 11 => 'Nivia');
71  $RYTIME_DAYS = array(0 => 'Prima', 1 => 'Dua', 2 => 'Tria',
72                       3 => 'Quarta', 4 => 'Quinteth', 5 =>'Holeth');
73
74  # Day, Month DayOfMonth, CycleNth CA JY
75  return sprintf("%sh - %s, %s %d, %de CA %d",
76                 $rytime["time_of_day"],
77                 $RYTIME_DAYS[$rytime["day_of_week"]],
78                 $RYTIME_MONTHS[$rytime["month_of_cycle"]],
79                 $rytime["day_of_month"] + 1,
80                 $rytime["cycle"] + 1 /* 0-index */,
81                 $rytime["jena_year"]);
82}
83
84/* Example */
85  $time = file_get_contents('http://atys.ryzom.com/servertick/index.php?shardid=ani');
86  $rytime = ryzom_time_compute($time);
87  echo ryzom_date_format($rytime);
88  echo ryzom_time_xmlize($rytime)->asXML();
89/**/
90?>

Diff to currently in prod:

 1--- time0.php    2009-04-15 11:42:46.000000000 +0200
 2+++ time2.php    2009-04-15 11:41:35.000000000 +0200
 3@@ -10,8 +10,8 @@
 4 define('RYTIME_WEEK_DAYS', 6);
 5 /* 0 = spring, 1 = summer, 2 = automn, 3 = winter */
 6 define('RYTIME_CYCLE_SEASONS', 4);
 7-/* Spring = season 0, starts on 61th day of JY */
 8-define('RYTIME_START_SPRING', 61);
 9+/* Tick is offset on server of 61 days. */
10+define('RYTIME_TICK_OFFSET', 61 * RYTIME_DAY_HOURS * RYTIME_HOUR_TICKS);
11
12 define('RYTIME_START_JY', 2525);
13
14@@ -27,7 +27,7 @@
15     $out = array();
16     $out["server_tick"] = $tick;
17
18-    $time_in_hours = $tick / RYTIME_HOUR_TICKS;
19+    $time_in_hours = ($tick-RYTIME_TICK_OFFSET) / RYTIME_HOUR_TICKS;
20     $day = $time_in_hours / RYTIME_DAY_HOURS;
21
22     $out["jena_year"] = floor($day / RYTIME_JY_DAYS + RYTIME_START_JY);
23@@ -41,8 +41,8 @@
24     $out["day_of_month"] = $out["day_of_jy"] % RYTIME_MONTH_DAYS;
25     $out["day_of_week"] = $day % RYTIME_WEEK_DAYS;
26
27-    $out["season"] = (($day + RYTIME_JY_DAYS - RYTIME_START_SPRING) % RYTIME_JY_MONTHS) % RYTIME_CYCLE_SEASONS;
28-    $out["day_of_season"] = ($day - RYTIME_START_SPRING) % (RYTIME_SEASON_DAYS);
29+    $out["season"] = ($day / RYTIME_SEASON_DAYS) % RYTIME_CYCLE_SEASONS;
30+    $out["day_of_season"] = $day % RYTIME_SEASON_DAYS;
31
32     $out["time_of_day"] = $time_in_hours % RYTIME_DAY_HOURS;
33     return $out;

RE: [DONE] Tick -> Date conversion - Added by barbaros about 6 years ago

Well, with my limited access I can't verify this and have to believe it :)
It works and now this matches the dates of the animation team.

As for the zero index. Personaly I think, if you are going to calculate on the values you will do so with the servertick.
The other values should be ready for output, like linking the XML with a CSS stylesheet.

We should add the month/day name into the XML to have that complete.

RE: [DONE] Tick -> Date conversion - Added by nimetu about 6 years ago

First time i see this date format 'Day, Month DayOfMonth, CycleNth CA JY'. i hope it's not official... for arispotle anyway hehe.
old article "Glimpse of production - 2005-04-25", there was ingame atys date displayed, unfortunately not accessible anymore ;-(

btw, JY/AC (uiJenaYear/uiAtysianCycle in game files) translates to
en: JY/AC
fr: AJ/CA
de: JJ/AZ

RE: [DONE] Tick -> Date conversion - Added by kervala about 6 years ago

I know this format, but it was never published, even on ATS (I don't remember seeing it).

So there was no official format for dates.

I think the new format is more human readable (it was used on several french documents) and it could be possible it was created by Paul 'Mr. Lore' Monk.

RE: [DONE] Tick -> Date conversion - Added by vl about 6 years ago

I applied the zorglub diff in prod

(1-13/13)