Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sgaunet/calcdate

utility to make some basic operation on date
https://github.com/sgaunet/calcdate

date datetime time

Last synced: 5 days ago
JSON representation

utility to make some basic operation on date

Awesome Lists containing this project

README

        

[![Go Report Card](https://goreportcard.com/badge/github.com/sgaunet/calcdate)](https://goreportcard.com/report/github.com/sgaunet/calcdate)
[![Maintainability](https://api.codeclimate.com/v1/badges/d7c294390a2a3b7a99f6/maintainability)](https://codeclimate.com/github/sgaunet/calcdate/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/d7c294390a2a3b7a99f6/test_coverage)](https://codeclimate.com/github/sgaunet/calcdate/test_coverage)

# calcdate

calcdate is a utility to make some basic operation on date. It's useful when need to calculate a range of date in order to make database request.

```
Usage of calcdate:
-b string
Begin date (default "// ::")
-e string
End date
-i duration
Interval (Ex: 1m or 1h or 15s)
-ifmt string
Input Format (%YYYY/%MM/%DD %hh:%mm:%ss) (default "%YYYY/%MM/%DD %hh:%mm:%ss")
-ofmt string
Input Format (%YYYY/%MM/%DD %hh:%mm:%ss), use @ts for timestamp (default "%YYYY/%MM/%DD %hh:%mm:%ss")
-s string
Separator (default " ")
-tmpl string
Used only with -i option (default "{{ .BeginTime.Format \"%YYYY/%MM/%DD %hh:%mm:%ss\" }} - {{ .EndTime.Format \"%YYYY/%MM/%DD %hh:%mm:%ss\" }} {{ .BeginTime.Unix }} {{ .EndTime.Unix }}")
-tz string
Timezone (default "Local")
-v Get version
```

**Be careful, there is a breaking change after the version 0.5 (format is using % symbol).**

By default this is the current datetime that is printed.

```
$ ./calcdate
2020/09/14 23:15:10
```

# Some examples

```
$ ./calcdate -b //-1
2020/09/13 23:16:37
```

```
$ date && ./calcdate -b :-1: -e :-1:
lun. 14 sept. 2020 23:18:15 CEST
2020/09/14 23:17:00 2020/09/14 23:17:59
```

```
$ date && ./calcdate -b :-1:
lun. 14 sept. 2020 23:18:22 CEST
2020/09/14 23:17:22
```

```
$ date && ./calcdate -b :-1: -tz UTC
lun. 14 sept. 2020 23:19:08 CEST
2020/09/14 21:18:08
```

```
$ calcdate -b ":-5:" -e "::" -s "' and '"
2022/01/10 21:29:00' and '2022/12/31 23:59:59
```

```
date;calcdate -b ":-5:" -e "::59" -s "' and '"
lun. 10 janv. 2022 21:41:55 CET
2022/01/10 21:36:00' and '2022/01/10 21:41:59
```

In the below example, there is also a call to MinusOneSecond.

```
$ calcdate -b "2022/01/07 20:50:00" -e "2022/01/08 00:30:00" -i 5m -tmpl "{{ .BeginTime.Format \"%YYYY/%MM/%DD %hh:%mm:%ss\" }} - {{ .EndTime.Format \"%YYYY/%MM/%DD %hh:%mm:%ss\" }} {{ .BeginTime.Unix }} {{ .EndTime.Unix }} --- {{ (MinusOneSecond .EndTime).Format \" %hh:%mm:%ss \" }}"
2022/01/07 20:50:00 - 2022/01/07 20:55:00 1641585000 1641585300 --- 20:54:59
2022/01/07 20:55:00 - 2022/01/07 21:00:00 1641585300 1641585600 --- 20:59:59
2022/01/07 21:00:00 - 2022/01/07 21:05:00 1641585600 1641585900 --- 21:04:59
2022/01/07 21:05:00 - 2022/01/07 21:10:00 1641585900 1641586200 --- 21:09:59
2022/01/07 21:10:00 - 2022/01/07 21:15:00 1641586200 1641586500 --- 21:14:59
2022/01/07 21:15:00 - 2022/01/07 21:20:00 1641586500 1641586800 --- 21:19:59
2022/01/07 21:20:00 - 2022/01/07 21:25:00 1641586800 1641587100 --- 21:24:59
2022/01/07 21:25:00 - 2022/01/07 21:30:00 1641587100 1641587400 --- 21:29:59
2022/01/07 21:30:00 - 2022/01/07 21:35:00 1641587400 1641587700 --- 21:34:59
2022/01/07 21:35:00 - 2022/01/07 21:40:00 1641587700 1641588000 --- 21:39:59
2022/01/07 21:40:00 - 2022/01/07 21:45:00 1641588000 1641588300 --- 21:44:59
2022/01/07 21:45:00 - 2022/01/07 21:50:00 1641588300 1641588600 --- 21:49:59
2022/01/07 21:50:00 - 2022/01/07 21:55:00 1641588600 1641588900 --- 21:54:59
2022/01/07 21:55:00 - 2022/01/07 22:00:00 1641588900 1641589200 --- 21:59:59
2022/01/07 22:00:00 - 2022/01/07 22:05:00 1641589200 1641589500 --- 22:04:59
2022/01/07 22:05:00 - 2022/01/07 22:10:00 1641589500 1641589800 --- 22:09:59
2022/01/07 22:10:00 - 2022/01/07 22:15:00 1641589800 1641590100 --- 22:14:59
2022/01/07 22:15:00 - 2022/01/07 22:20:00 1641590100 1641590400 --- 22:19:59
2022/01/07 22:20:00 - 2022/01/07 22:25:00 1641590400 1641590700 --- 22:24:59
2022/01/07 22:25:00 - 2022/01/07 22:30:00 1641590700 1641591000 --- 22:29:59
2022/01/07 22:30:00 - 2022/01/07 22:35:00 1641591000 1641591300 --- 22:34:59
2022/01/07 22:35:00 - 2022/01/07 22:40:00 1641591300 1641591600 --- 22:39:59
2022/01/07 22:40:00 - 2022/01/07 22:45:00 1641591600 1641591900 --- 22:44:59
2022/01/07 22:45:00 - 2022/01/07 22:50:00 1641591900 1641592200 --- 22:49:59
2022/01/07 22:50:00 - 2022/01/07 22:55:00 1641592200 1641592500 --- 22:54:59
2022/01/07 22:55:00 - 2022/01/07 23:00:00 1641592500 1641592800 --- 22:59:59
2022/01/07 23:00:00 - 2022/01/07 23:05:00 1641592800 1641593100 --- 23:04:59
2022/01/07 23:05:00 - 2022/01/07 23:10:00 1641593100 1641593400 --- 23:09:59
2022/01/07 23:10:00 - 2022/01/07 23:15:00 1641593400 1641593700 --- 23:14:59
2022/01/07 23:15:00 - 2022/01/07 23:20:00 1641593700 1641594000 --- 23:19:59
2022/01/07 23:20:00 - 2022/01/07 23:25:00 1641594000 1641594300 --- 23:24:59
2022/01/07 23:25:00 - 2022/01/07 23:30:00 1641594300 1641594600 --- 23:29:59
2022/01/07 23:30:00 - 2022/01/07 23:35:00 1641594600 1641594900 --- 23:34:59
2022/01/07 23:35:00 - 2022/01/07 23:40:00 1641594900 1641595200 --- 23:39:59
2022/01/07 23:40:00 - 2022/01/07 23:45:00 1641595200 1641595500 --- 23:44:59
2022/01/07 23:45:00 - 2022/01/07 23:50:00 1641595500 1641595800 --- 23:49:59
2022/01/07 23:50:00 - 2022/01/07 23:55:00 1641595800 1641596100 --- 23:54:59
2022/01/07 23:55:00 - 2022/01/08 00:00:00 1641596100 1641596400 --- 23:59:59
2022/01/08 00:00:00 - 2022/01/08 00:05:00 1641596400 1641596700 --- 00:04:59
2022/01/08 00:05:00 - 2022/01/08 00:10:00 1641596700 1641597000 --- 00:09:59
2022/01/08 00:10:00 - 2022/01/08 00:15:00 1641597000 1641597300 --- 00:14:59
2022/01/08 00:15:00 - 2022/01/08 00:20:00 1641597300 1641597600 --- 00:19:59
2022/01/08 00:20:00 - 2022/01/08 00:25:00 1641597600 1641597900 --- 00:24:59
2022/01/08 00:25:00 - 2022/01/08 00:30:00 1641597900 1641598200 --- 00:29:59
```