Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Hurley authored and Aaron Hurley committed Jul 18, 2019
0 parents commit 3ee0566
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dayoftheyear
Super simple app that returns the day number of the year and what percentage of the year has been completed.
See it at http://dayoftheyear.cfapps.io
41 changes: 41 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"net/http"
"os"
"time"
)

func dayOfTheYear(w http.ResponseWriter, r *http.Request) {
pacific, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(err)
}

now := time.Now().In(pacific)
firstDayOfThisYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, pacific)
firstDayOfNextYear := time.Date(now.Year() + 1, 1, 1, 0, 0, 0, 0, pacific)
totalDaysOfThisYear := daysBetween(firstDayOfThisYear, firstDayOfNextYear)

dayOfThisYear := now.YearDay()
percentage := float64(dayOfThisYear) / float64(totalDaysOfThisYear)
daysUntilNextYear := totalDaysOfThisYear - dayOfThisYear

message := fmt.Sprintf("Today is Day: %d.\n", dayOfThisYear)
message += fmt.Sprintf("We are %.1f%% through the year.\n", percentage * 100)
message += fmt.Sprintf("There are %d days left in the year.", daysUntilNextYear)
w.Write([]byte(message))
}

func daysBetween(earlier, later time.Time) int {
return int(later.Sub(earlier).Hours() / 24)
}

func main() {
http.HandleFunc("/", dayOfTheYear)
port := os.Getenv("PORT")
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
panic(err)
}
}
10 changes: 10 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applications:
- name: dayoftheyear
memory: 32M
disk_quota: 32M
buildpacks:
- go_buildpack
env:
GOVERSION: go1
GOPACKAGENAME: github.com/aaronshurley/dayoftheyear

0 comments on commit 3ee0566

Please sign in to comment.