Skip to content

Commit

Permalink
rewrite TibiaDataDate function (#240)
Browse files Browse the repository at this point in the history
fix #239
  • Loading branch information
tobiasehlert authored Aug 1, 2023
1 parent d400b58 commit 4575ea3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
36 changes: 21 additions & 15 deletions src/TibiaDataUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,28 @@ func TibiaDataDate(date string) string {

// var time parser
var tmpDate time.Time
var err error

// parsing and setting format of return
switch dateLength := len(date); {
case dateLength == 5:
// date that contains special formatting only used in date a world was created
tmpDate, _ = time.Parse("01/06", date)
// we need to return earlier as well, since we don't have the day
return tmpDate.UTC().Format("2006-01")
case dateLength == 11:
// dates that contain first 3 letters in month
tmpDate, _ = time.Parse("Jan 02 2006", date)
case dateLength > 11:
// dates that contain month fully written
tmpDate, _ = time.Parse("January 2 2006", date)
default:
log.Printf("Weird format detected: %s", date)
// date formats to parse
dateFormats := map[string][]string{
"YearMonthDay": {"January 2 2006", "Jan 02 2006"},
"YearMonth": {"January 2006", "Jan 2006", "2006-01", "01/06"},
}

for _, layout := range dateFormats["YearMonthDay"] {
tmpDate, err = time.Parse(layout, date)
if err == nil {
// If the parse succeeds, format the date as "2006-01-02"
return tmpDate.UTC().Format("2006-01-02")
}
}

for _, layout := range dateFormats["YearMonth"] {
tmpDate, err = time.Parse(layout, date)
if err == nil {
// If the parse succeeds, format the date as "2006-01"
return tmpDate.Format("2006-01")
}
}

return tmpDate.UTC().Format("2006-01-02")
Expand Down
2 changes: 1 addition & 1 deletion src/static/testdata/worlds/world/Endebra.html
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@
<div class="Border_2">
<div class="Border_3">
<div class="BoxContent" style="background-image:url(https://static.tibia.com/images/global/content/scroll.gif);">
<form action="?subtopic=worlds" method="post"><div class="TableContainer"> <table class="Table1" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">World Selection</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td style="vertical-align:middle;" class="LabelV150">World Name:</td><td style="width:170px;"><select size="1" name="world" style="width:165px;"><option value="Adra">Adra</option><option value="Alumbra">Alumbra</option><option value="Antica">Antica</option><option value="Ardera">Ardera</option><option value="Astera">Astera</option><option value="Bastia">Bastia</option><option value="Batabra">Batabra</option><option value="Belobra">Belobra</option><option value="Bona">Bona</option><option value="Cadebra">Cadebra</option><option value="Calmera">Calmera</option><option value="Celebra">Celebra</option><option value="Celesta">Celesta</option><option value="Collabra">Collabra</option><option value="Damora">Damora</option><option value="Descubra">Descubra</option><option value="Dibra">Dibra</option><option value="Endebra" selected="selected">Endebra</option><option value="Endera">Endera</option><option value="Endura">Endura</option><option value="Epoca">Epoca</option><option value="Famosa">Famosa</option><option value="Fera">Fera</option><option value="Ferobra">Ferobra</option><option value="Firmera">Firmera</option><option value="Gentebra">Gentebra</option><option value="Gladera">Gladera</option><option value="Harmonia">Harmonia</option><option value="Havera">Havera</option><option value="Honbra">Honbra</option><option value="Illusera">Illusera</option><option value="Impulsa">Impulsa</option><option value="Inabra">Inabra</option><option value="Kalibra">Kalibra</option><option value="Karna">Karna</option><option value="Libertabra">Libertabra</option><option value="Lobera">Lobera</option><option value="Luminera">Luminera</option><option value="Lutabra">Lutabra</option><option value="Marbera">Marbera</option><option value="Marcia">Marcia</option><option value="Menera">Menera</option><option value="Monza">Monza</option><option value="Mudabra">Mudabra</option><option value="Mykera">Mykera</option><option value="Nefera">Nefera</option><option value="Nossobra">Nossobra</option><option value="Ocebra">Ocebra</option><option value="Olima">Olima</option><option value="Ombra">Ombra</option><option value="Optera">Optera</option><option value="Pacera">Pacera</option><option value="Peloria">Peloria</option><option value="Premia">Premia</option><option value="Quelibra">Quelibra</option><option value="Quintera">Quintera</option><option value="Refugia">Refugia</option><option value="Reinobra">Reinobra</option><option value="Seanera">Seanera</option><option value="Secura">Secura</option><option value="Serdebra">Serdebra</option><option value="Solidera">Solidera</option><option value="Suna">Suna</option><option value="Talera">Talera</option><option value="Tembra">Tembra</option><option value="Thyria">Thyria</option><option value="Trona">Trona</option><option value="Utobra">Utobra</option><option value="Velocera">Velocera</option><option value="Velocibra">Velocibra</option><option value="Velocita">Velocita</option><option value="Venebra">Venebra</option><option value="Versa">Versa</option><option value="Visabra">Visabra</option><option value="Vunira">Vunira</option><option value="Wintera">Wintera</option><option value="Wizera">Wizera</option><option value="Xandebra">Xandebra</option><option value="Yonabra">Yonabra</option><option value="Zenobra">Zenobra</option><option value="Zuna">Zuna</option><option value="Zunera">Zunera</option></select></td><td style="text-align:left;"><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Submit" /></div></div></td></tr> </table> </div> </td> </tr> </table></div></form><br /><div class="TableContainer"> <table class="Table1" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">World Information</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td class="LabelV200">Status:</td><td><div class="ServerInformationIconContainer_Worlds" style="top: 40px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_location_bra.png" alt="Server Location" /></div><div class="ServerInformationIconContainer_Worlds" style="top: 100px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_pvp_type_optional.gif" alt="Server PVP Type" /></div><div class="ServerInformationIconContainer_Worlds" style="top: 160px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_tournament_restricted.png" alt="Tournament Type" /></div>Online</td></tr><tr><td class="LabelV200">Players Online:</td><td>0</td></tr><tr><td class="LabelV200">Online Record:</td><td>89 players (on Apr&#160;23&#160;2020,&#160;03:30:30&#160;CEST)</td></tr><tr><td class="LabelV200">Creation Date:</td><td>05/19</td></tr><tr><td class="LabelV200">Location:</td><td>South America</td></tr><tr><td class="LabelV200">PvP Type:</td><td>Optional PvP</td></tr><tr><td class="LabelV200">Premium Type:</td><td>premium</td></tr><tr><td class="LabelV200">Transfer Type:</td><td>blocked</td></tr><tr><td class="LabelV200">World Quest Titles:</td><td>This game world currently has no title.</td></tr><tr><td class="LabelV200">BattlEye Status:</td><td>Protected by BattlEye since its release.</td></tr><tr><td class="LabelV200">Tournament World Type:</td><td>Restricted Store</td></tr> </table> </div> </td> </tr> </table></div><br /><br /><center><form action="https://www.tibia.com/community/?subtopic=worlds" method="post" style="padding:0px;margin:0px;"><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></center> </div>
<form action="?subtopic=worlds" method="post"><div class="TableContainer"> <table class="Table1" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">World Selection</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td style="vertical-align:middle;" class="LabelV150">World Name:</td><td style="width:170px;"><select size="1" name="world" style="width:165px;"><option value="Adra">Adra</option><option value="Alumbra">Alumbra</option><option value="Antica">Antica</option><option value="Ardera">Ardera</option><option value="Astera">Astera</option><option value="Bastia">Bastia</option><option value="Batabra">Batabra</option><option value="Belobra">Belobra</option><option value="Bona">Bona</option><option value="Cadebra">Cadebra</option><option value="Calmera">Calmera</option><option value="Celebra">Celebra</option><option value="Celesta">Celesta</option><option value="Collabra">Collabra</option><option value="Damora">Damora</option><option value="Descubra">Descubra</option><option value="Dibra">Dibra</option><option value="Endebra" selected="selected">Endebra</option><option value="Endera">Endera</option><option value="Endura">Endura</option><option value="Epoca">Epoca</option><option value="Famosa">Famosa</option><option value="Fera">Fera</option><option value="Ferobra">Ferobra</option><option value="Firmera">Firmera</option><option value="Gentebra">Gentebra</option><option value="Gladera">Gladera</option><option value="Harmonia">Harmonia</option><option value="Havera">Havera</option><option value="Honbra">Honbra</option><option value="Illusera">Illusera</option><option value="Impulsa">Impulsa</option><option value="Inabra">Inabra</option><option value="Kalibra">Kalibra</option><option value="Karna">Karna</option><option value="Libertabra">Libertabra</option><option value="Lobera">Lobera</option><option value="Luminera">Luminera</option><option value="Lutabra">Lutabra</option><option value="Marbera">Marbera</option><option value="Marcia">Marcia</option><option value="Menera">Menera</option><option value="Monza">Monza</option><option value="Mudabra">Mudabra</option><option value="Mykera">Mykera</option><option value="Nefera">Nefera</option><option value="Nossobra">Nossobra</option><option value="Ocebra">Ocebra</option><option value="Olima">Olima</option><option value="Ombra">Ombra</option><option value="Optera">Optera</option><option value="Pacera">Pacera</option><option value="Peloria">Peloria</option><option value="Premia">Premia</option><option value="Quelibra">Quelibra</option><option value="Quintera">Quintera</option><option value="Refugia">Refugia</option><option value="Reinobra">Reinobra</option><option value="Seanera">Seanera</option><option value="Secura">Secura</option><option value="Serdebra">Serdebra</option><option value="Solidera">Solidera</option><option value="Suna">Suna</option><option value="Talera">Talera</option><option value="Tembra">Tembra</option><option value="Thyria">Thyria</option><option value="Trona">Trona</option><option value="Utobra">Utobra</option><option value="Velocera">Velocera</option><option value="Velocibra">Velocibra</option><option value="Velocita">Velocita</option><option value="Venebra">Venebra</option><option value="Versa">Versa</option><option value="Visabra">Visabra</option><option value="Vunira">Vunira</option><option value="Wintera">Wintera</option><option value="Wizera">Wizera</option><option value="Xandebra">Xandebra</option><option value="Yonabra">Yonabra</option><option value="Zenobra">Zenobra</option><option value="Zuna">Zuna</option><option value="Zunera">Zunera</option></select></td><td style="text-align:left;"><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Submit" /></div></div></td></tr> </table> </div> </td> </tr> </table></div></form><br /><div class="TableContainer"> <table class="Table1" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">World Information</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td class="LabelV200">Status:</td><td><div class="ServerInformationIconContainer_Worlds" style="top: 40px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_location_bra.png" alt="Server Location" /></div><div class="ServerInformationIconContainer_Worlds" style="top: 100px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_pvp_type_optional.gif" alt="Server PVP Type" /></div><div class="ServerInformationIconContainer_Worlds" style="top: 160px;"><img class="ServerInformationIcon" src="https://static.tibia.com/images/global/content/option_server_tournament_restricted.png" alt="Tournament Type" /></div>Online</td></tr><tr><td class="LabelV200">Players Online:</td><td>0</td></tr><tr><td class="LabelV200">Online Record:</td><td>89 players (on Apr&#160;23&#160;2020,&#160;03:30:30&#160;CEST)</td></tr><tr><td class="LabelV200">Creation Date:</td><td>May 2019</td></tr><tr><td class="LabelV200">Location:</td><td>South America</td></tr><tr><td class="LabelV200">PvP Type:</td><td>Optional PvP</td></tr><tr><td class="LabelV200">Premium Type:</td><td>premium</td></tr><tr><td class="LabelV200">Transfer Type:</td><td>blocked</td></tr><tr><td class="LabelV200">World Quest Titles:</td><td>This game world currently has no title.</td></tr><tr><td class="LabelV200">BattlEye Status:</td><td>Protected by BattlEye since its release.</td></tr><tr><td class="LabelV200">Tournament World Type:</td><td>Restricted Store</td></tr> </table> </div> </td> </tr> </table></div><br /><br /><center><form action="https://www.tibia.com/community/?subtopic=worlds" method="post" style="padding:0px;margin:0px;"><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></center> </div>
</div>
</div>
<div class="Border_1" style="background-image:url(https://static.tibia.com/images/global/content/border-1.gif);"></div>
Expand Down
Loading

0 comments on commit 4575ea3

Please sign in to comment.