---
title: Ordinal date
jupyter:
  jupytext:
    text_representation:
      extension: .qmd
      format_name: quarto
      format_version: '1.0'
      jupytext_version: 1.16.4
  kernelspec:
    display_name: Python 3 (ipykernel)
    language: python
    name: python3
---

```{python}
#| tags: [py, func, unix2date]
def unix2date(unix):
    dote = unix / 86400 + 719468
    socy = (
        dote if dote >= 0
        else dote - 146096
    ) // 146097
    dotc = dote - socy * 146097
    yotc = (dotc
        - dotc // 1460
        + dotc // 36524
        - dotc // 146096
    ) // 365
    return [
        int(yotc + socy * 400),
        dotc - (yotc * 365
            + yotc // 4
            - yotc // 100
    )]
unix2date(1728000000)
unix2date(1890000000)
```

I use different programming languages to convert UNIX time in various
places on my site. More specifically, I use a
[Python](https://en.wikipedia.org/wiki/Python_%28programming_language%29#:~:text=a%20high%2Dlevel%2C%20general%2Dpurpose%20programming%20language)
[post-render
script](https://quarto.org/docs/projects/scripts.html#pre-and-post-render)
([date.py](../../asset/date.py)) for the dates on the [page that lists
all of the articles on my site](../../list), a
[Lua](https://en.wikipedia.org/wiki/Lua_(programming_language)#:~:text=a%20lightweight%2C%20high%2Dlevel%2C%20multi%2Dparadigm%20programming%20language%20designed%20mainly%20for%20embedded%20use%20in%20applications)
[filter](https://quarto.org/docs/extensions/filters.html)
([date.lua](../../asset/date.lua)) for the PUBLISHED date at the top of
each article, and an [include-after-body
file](https://quarto.org/docs/output-formats/html-basics.html#includes)
that sources a
[JavaScript](https://en.wikipedia.org/wiki/JavaScript#:~:text=a%20programming%20language%20and%20core%20technology%20of%20the%20Web)
file ([stamp.js](../../asset/stamp.js)) for the date in the above.
[citation](http://localhost:4207/dec/date/#citation) information at the
bottom of each article.


<script type='ojs-module-contents'>
eyJjb250ZW50cyI6WyAgeyJtZXRob2ROYW1lIjoiaW50ZXJwcmV0IiwiaW5saW5lIjoidHJ1ZSIsInNvdXJjZSI6Imh0bC5odG1sYDxzcGFuPiR7c3R5bGVkVGlja1RpbWV9PC9zcGFuPmAiLCAiY2VsbE5hbWUiO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