Skip to content

Commit e7f1fc8

Browse files
authored
Merge pull request #1 from aj3sh/ad2bs-bs2ad
feat: combine ad2bs and bs2ad in one project
2 parents d75b4b3 + b01607c commit e7f1fc8

File tree

20 files changed

+322
-576
lines changed

20 files changed

+322
-576
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,27 @@
1-
name: CI
1+
name: Github CI
2+
23
on:
34
push:
4-
branches:
5-
- '**'
5+
branches: ['main']
66
pull_request:
7-
branches:
8-
- '**'
7+
98
jobs:
10-
lint:
9+
ci:
1110
runs-on: ubuntu-latest
1211
steps:
1312
- uses: actions/checkout@v4
13+
1414
- uses: actions/setup-go@v5
1515
with:
16-
go-version: '1.21'
17-
- uses: golangci/golangci-lint-action@c67416616c29c3c48d26b59c45cadb56966d80aa
16+
go-version: 1.22
17+
18+
- name: Lint Code
19+
uses: golangci/golangci-lint-action@v6
1820
with:
1921
args: --timeout=5m
20-
test:
21-
runs-on: ubuntu-latest
22-
needs: lint
23-
steps:
24-
- uses: actions/checkout@v4
25-
- uses: actions/setup-go@v5
26-
with:
27-
go-version: 1.21
28-
- run: go test -v ./...
29-
release:
30-
runs-on: ubuntu-latest
31-
needs: test
32-
permissions:
33-
contents: write
34-
steps:
35-
- uses: actions/checkout@v4
36-
- uses: actions/setup-go@v4
37-
with:
38-
go-version: 1.21
39-
- uses: sumanchapai/go-semantic-release-action@v1
40-
with:
41-
pre-release-post-dry-cmd: "cp .version cmd/.version"
42-
files-to-commit: "cmd/.version"
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Build
24+
run: make build
25+
26+
- name: Test
27+
run: make test

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Release"
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
23+
- name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v5
25+
if: startsWith(github.ref, 'refs/tags/')
26+
with:
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
.DS_Store

.goreleaser.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
project_name: ad2bs
2+
release:
3+
github:
4+
owner: opensource-nepal
5+
name: ad2bs
6+
7+
builds:
8+
- id: ad2bs
9+
main: cmd/ad2bs/main.go
10+
binary: ad2bs
11+
goos:
12+
- linux
13+
- darwin
14+
- windows
15+
- id: bs2ad
16+
main: cmd/bs2ad/main.go
17+
binary: bs2ad
18+
goos:
19+
- linux
20+
- darwin
21+
- windows
22+
23+
nfpms:
24+
- id: ad2bs
25+
license: GPL-3.0
26+
maintainer: Ajesh Sen Thapa<[email protected]>
27+
formats:
28+
- deb
29+
- rpm
30+
bindir: /usr/local/bin

.version

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# How to Contribute
2+
3+
## Development Steps
4+
5+
### Download the Dependencies
6+
7+
```bash
8+
make go-get
9+
```

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
build:
2+
go build -o dist/ad2bs cmd/ad2bs/main.go
3+
go build -o dist/bs2ad cmd/bs2ad/main.go
4+
5+
test:
6+
go test -v ./...
7+
8+
# Go specific make commands
9+
10+
go-get:
11+
go get ./...
12+
13+
go-clean:
14+
go clean -cache -modcache
15+
16+
.PHONY: build test go-get go-clean

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
Convert a given AD date in the format YYYY-MM-DD to BS date in the same format.
1+
# ad2bs
22

3-
To convert your birthday on 1999-10-29 AD to nepali, run\
4-
`ad2bs 1999-10-29`
3+
Converts a given AD date to BS date and BS date to AD.
54

6-
## Installing / Updating `ad2bs`
5+
## Usage
76

8-
### If you have go installed.
7+
**Converting AD to BS**
98

10-
Have go >= 1.21 installed. Clone the repo, then run `go install .`
9+
```bash
10+
ad2bs YYYY-MM-DD
11+
```
12+
13+
**Converting BS to AD**
14+
15+
```bash
16+
bs2ad YYYY-MM-DD
17+
```
18+
19+
Example:
20+
21+
```bash
22+
ad2bs 1999-10-29
23+
```
1124

12-
### If you don't have go installed, for macOS/Linux:
25+
## Installation
1326

1427
```sh
15-
rm -f `which ad2bs`
16-
curl -s https://raw.githubusercontent.com/opensource-nepal/ad2bs/main/scripts/install.txt | sh
28+
curl -s https://raw.githubusercontent.com/aj3sh/ad2bs/main/scripts/install.sh | sh
1729
```

cmd/.version

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/ad2bs/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
"time"
8+
9+
"github.com/opensource-nepal/go-nepali/nepalitime"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
ErrDateArgsMissing = errors.New("date argument is missing. format: YYYY-MM-DD")
15+
DateInputFormat = "2006-1-2"
16+
)
17+
18+
func validateArgs(cmd *cobra.Command, args []string) error {
19+
if len(args) != 1 {
20+
return ErrDateArgsMissing
21+
}
22+
_, err := time.Parse(DateInputFormat, args[0])
23+
if err != nil {
24+
return err
25+
}
26+
return nil
27+
}
28+
29+
func convertADToBS(cmd *cobra.Command, args []string) {
30+
enTime, _ := time.Parse(DateInputFormat, args[0])
31+
npTime, err := nepalitime.FromEnglishTime(enTime)
32+
if err != nil {
33+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
34+
return
35+
}
36+
npTimeFormat, _ := npTime.Format("%Y-%m-%d")
37+
fmt.Println(npTimeFormat)
38+
}
39+
40+
func main() {
41+
var ad2bsCmd = &cobra.Command{
42+
Use: "ad2bs",
43+
Short: "Convert AD date to BS",
44+
Args: validateArgs,
45+
Run: convertADToBS,
46+
}
47+
48+
if err := ad2bsCmd.Execute(); err != nil {
49+
os.Exit(1)
50+
}
51+
}

0 commit comments

Comments
 (0)