Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .appveyor.yml

This file was deleted.

13 changes: 10 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
name: golangci-lint
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v6
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test
on:
push:
branches:
- master
pull_request:
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ['1.21.x', '1.22.x', 'stable']
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Set timezone (Windows)
if: runner.os == 'Windows'
run: tzutil /s "Eastern Standard Time"
- name: Set timezone (macOS)
if: runner.os == 'macOS'
run: sudo systemsetup -settimezone America/New_York
- name: Run tests (Linux/macOS)
if: runner.os != 'Windows'
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Run tests (Windows)
if: runner.os == 'Windows'
shell: bash
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...
- name: Run go vet
run: go vet ./...
- name: Upload coverage to Coveralls
if: matrix.os == 'ubuntu-latest' && matrix.go == 'stable'
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: coverage.txt
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test coverage
coverage.txt
*.out

# Binaries
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Go workspace file
go.work
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Tuesday: Ruby-Compatible Strftime for Go

[![Travis badge][travis-svg]][travis-url]
[![Golangci-lint badge][golangci-lint-svg]][golangci-lint-url]
[![Appveyor badge][appveyor-svg]][appveyor-url]
[![Coveralls badge][coveralls-svg]][coveralls-url]
[![Go Report Card badge][go-report-card-svg]][go-report-card-url]
[![Godoc badge][godoc-svg]][godoc-url]
[![MIT License][license-svg]][license-url]
[![Test badge][test-svg]][test-url]
[![Golangci-lint badge][golangci-lint-svg]][golangci-lint-url]
[![Coveralls badge][coveralls-svg]][coveralls-url]
[![Go Report Card badge][go-report-card-svg]][go-report-card-url]
[![Godoc badge][godoc-svg]][godoc-url]
[![MIT License][license-svg]][license-url]

This package provides a function `Strftime` that is compatible with Ruby's [`Time.strftime`](https://ruby-doc.org/core-2.4.1/Time.html#method-i-strftime).

Expand Down Expand Up @@ -35,23 +34,20 @@ It was developed for use with in [Liquid](https://github.com/osteele/liquid) and

MIT License

[coveralls-url]: https://coveralls.io/r/osteele/tuesday?branch=master
[coveralls-svg]: https://img.shields.io/coveralls/osteele/tuesday.svg?branch=master

[godoc-url]: https://godoc.org/github.com/osteele/tuesday
[godoc-svg]: https://godoc.org/github.com/osteele/tuesday?status.svg
[test-url]: https://github.com/osteele/tuesday/actions?query=workflow%3ATest
[test-svg]: https://github.com/osteele/tuesday/actions/workflows/test.yml/badge.svg

[golangci-lint-url]: https://github.com/osteele/tuesday/actions?query=workflow%3Agolangci-lint
[golangci-lint-svg]: https://github.com/osteele/tuesday/actions/workflows/golangci-lint.yml/badge.svg

[license-url]: https://github.com/osteele/tuesday/blob/master/LICENSE
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
[coveralls-url]: https://coveralls.io/r/osteele/tuesday?branch=master
[coveralls-svg]: https://img.shields.io/coveralls/osteele/tuesday.svg?branch=master

[go-report-card-url]: https://goreportcard.com/report/github.com/osteele/tuesday
[go-report-card-svg]: https://goreportcard.com/badge/github.com/osteele/tuesday

[travis-url]: https://travis-ci.com/osteele/tuesday
[travis-svg]: https://img.shields.io/travis/osteele/tuesday.svg?branch=master
[godoc-url]: https://godoc.org/github.com/osteele/tuesday
[godoc-svg]: https://godoc.org/github.com/osteele/tuesday?status.svg

[appveyor-url]: https://ci.appveyor.com/project/osteele/tuesday
[appveyor-svg]: https://ci.appveyor.com/api/projects/status/y9cyh4e30yjxshtm?svg=true
[license-url]: https://github.com/osteele/tuesday/blob/master/LICENSE
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/osteele/tuesday

go 1.16
go 1.21

require github.com/stretchr/testify v1.7.0

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
6 changes: 3 additions & 3 deletions strftime.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Strftime(format string, t time.Time) (string, error) {
pad, w = f.c, f.w
}
if len(width) > 0 {
w, _ = strconv.Atoi(width) // nolint: gas
w, _ = strconv.Atoi(width) // width is guaranteed to be digits by regex
}
switch flags {
case "-":
Expand Down Expand Up @@ -142,7 +142,7 @@ func convert(t time.Time, c rune, flags, width string) interface{} { // nolint:
case 'N':
ns := t.Nanosecond()
if len(width) > 0 {
w, _ := strconv.Atoi(width) // nolint: gas
w, _ := strconv.Atoi(width) // width is guaranteed to be digits by regex
if w <= 9 {
return fmt.Sprintf("%09d", ns)[:w]
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func convert(t time.Time, c rune, flags, width string) interface{} { // nolint:
return fmt.Sprintf("%02d:%02d:%02d", h, m, s)
case '+':
// date(1) (%a %b %e %H:%M:%S %Z %Y)
s, _ := Strftime("%a %b %e %H:%M:%S %Z %Y", t) // nolint: gas
s, _ := Strftime("%a %b %e %H:%M:%S %Z %Y", t)
return s
default:
return string([]rune{'%', c})
Expand Down
9 changes: 8 additions & 1 deletion strftime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ var conversionTests = []struct{ format, expect string }{
{"%9N", "123456789"},
{"%12N", "123456789000"},

// Edge cases for %N width
{"%10N", "1234567890"},
{"%15N", "123456789000000"},
{"%18N", "123456789000000000"},

// width
{"%1H", "15"},
{"%2H", "15"},
Expand Down Expand Up @@ -233,7 +238,9 @@ func readConversionTests() ([][]string, error) {
if err != nil {
return nil, err
}
defer f.Close() // nolint: errcheck
defer func() {
_ = f.Close() // Error during close on read-only file is not critical
}()

r := csv.NewReader(f)
recs, err := r.ReadAll()
Expand Down