gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

85c36bf48c86075e8834f57c849c33b2b2d41f9d - Matthew Ernisse - 1613057866

add epochseconds to date

view tree

view raw

diff --git a/cgi-bin/converter b/cgi-bin/converter
index 3eef4c1..ab82bde 100755
--- a/cgi-bin/converter
+++ b/cgi-bin/converter
@@ -28,6 +28,7 @@ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 '''
 import base64
+import datetime
 import os
 import secrets
 import sys
@@ -62,6 +63,10 @@ While I have taken care to be fairly reasonable with these things, please note t
 => random/base32	Random number, Base32 encoded
 => random/totp		Random number, encoded as a TOTP secret
 
+## Other Stuff
+
+=> unixdate		Unix timestamp to UTC date
+
 ## Suggestions?
 Want to see something here?  Feel free to drop me a line.
 => mailto:matt@going-flying.com
@@ -262,6 +267,10 @@ if __name__ == '__main__':
 			png.save(sys.stdout.buffer)
 			sys.stdout.flush()
 
+		# Unixdate
+		elif cgi.path_info == 'unixdate':
+			cgi.Response.Input('UNIX Timestamp?')
+			
 		else:
 			cgi.Response.Redirect(BACK_LINK)
 	else:
@@ -364,6 +373,24 @@ if __name__ == '__main__':
 				True
 			)
 
+		# Unixdate
+		elif cgi.path_info == 'unixdate':
+			ts = cgi.query_dequoted
+			try:
+				dt = datetime.datetime.fromtimestamp(float(ts))
+				t = dt.strftime('%A %d %B %Y %H:%M:%S UTC')
+
+			except Exception:
+				cgi.Response.Fail()
+				sys.exit()
+
+			cgi.Response.Ok('text/gemini')
+			output = f'# UNIX Timestamp {ts}\n'
+			output += f'{t}\n\n'
+			output += f'=> {BACK_LINK}	Back\n'
+			output += f'=> /	Home'
+			print(output)
+
 		else:
 			cgi.Response.NotFound()