Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ New features:
Bugfixes:

Other improvements:
- Added tests (#20 by @ntwilson)
- Added tests (#20 by @ntwilson)
- Added quick start (#22 by @maxdeviant)

## [v5.0.0](https://github.com/purescript-contrib/purescript-now/releases/tag/v5.0.0) - 2021-02-26

Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,43 @@ spago install now

## Quick start

The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the [docs directory](./docs).
The functions provided by `now` can be used to get the current date and time from the current machine's system clock.

Here are two example functions that print out the current year and time:

```purs
import Prelude
import Data.DateTime
import Data.Enum
import Effect
import Effect.Console
import Effect.Now

printCurrentYear :: Effect Unit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know how this example is.

I tried to err on the side of being slightly more verbose and trying to work with the dates rather than just showing the functions being called in the REPL:

> nowDate
(Date (Year 2021) August (Day 27))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s good — it’s better to show them in context and typical use vs. just their output.

printCurrentYear = do
currentDate <- nowDate
let
currentYear = fromEnum $ year currentDate :: Int
log $ "The current year is " <> show currentYear

printCurrentTime :: Effect Unit
printCurrentTime = do
currentTime <- nowTime
let
currentHour = fromEnum $ hour currentTime :: Int
currentMinute = fromEnum $ minute currentTime :: Int
log $ "The current time is " <> show currentHour <> ":" <> show currentMinute
```

We can then try these functions out in a REPL:

```
> printCurrentYear
The current year is 2021

> printCurrentTime
The current time is 1:54
```

## Documentation

Expand Down