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
4 changes: 2 additions & 2 deletions interface/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@polywrap/datetime-interface",
"description": "Polywrap Datetime Interface",
"version": "1.0.0-pre.0",
"version": "0.10.0",
"scripts": {
"build": "npx polywrap build",
"deploy": "npx polywrap deploy -o deployment.json"
},
"devDependencies": {
"polywrap": "0.10.0-pre.8"
"polywrap": "0.10.3"
},
"publishConfig": {
"access": "public"
Expand Down
126 changes: 120 additions & 6 deletions interface/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,122 @@
type Module {
"""
Returns the numeric value corresponding to the current time—the
number of milliseconds elapsed since January 1, 1970 00:00:00 UTC,
with leap seconds ignored.
"""
currentTimestamp: BigInt!
"""
Returns a Datetime object representing the current date and time.
"""
now: Datetime

"""
Calculates the difference between the Datetime instance and another Datetime instance provided as the 'other' parameter.
Returns a new Datetime object representing the absolute difference between the two.
"""
diff(other: Datetime!): Datetime!

"""
Formats the provided Datetime object into a String according to the formatting rules specified by the 'fmt' parameter.
"""
format(datetime: Datetime!, fmt: String): String!

"""
Parses a string representing a date and time, according to the formatting rules specified by the 'fmt' parameter, into a Datetime object.
"""
parse(datetimeStr: String!, fmt: String): Datetime!

"""
Adds a specified Duration to the Datetime instance, and returns a new Datetime object representing the result.
"""
add(duration: Duration!): Datetime!

"""
Subtracts a specified Duration from the Datetime instance, and returns a new Datetime object representing the result.
"""
subtract(duration: Duration!): Datetime!

"""
Converts the Datetime instance into a Unix timestamp (the number of seconds that have elapsed since 1970-01-01 00:00:00 UTC, excluding leap seconds) and returns it.
"""
toUnixTimestamp: UInt!

"""
Creates a new Datetime object from a Unix timestamp (the number of seconds that have elapsed since 1970-01-01 00:00:00 UTC, excluding leap seconds).
"""
fromUnixTimestamp(timestamp: UInt!): Datetime
}

"""
Defines the structure of a date and time object in the Gregorian calendar.
"""
type Datetime {
"""
The year component of the date.
"""
year: Int!

"""
The month component of the date. Ranges from 1 to 12.
"""
month: Int!

"""
The day component of the date. Ranges from 1 to 31.
"""
day: Int!

"""
The hour component of the time. Ranges from 0 to 23.
"""
hour: Int!

"""
The minute component of the time. Ranges from 0 to 59.
"""
minute: Int!

"""
The second component of the time. Ranges from 0 to 59.
"""
second: Int!

"""
The millisecond component of the time. Ranges from 0 to 999.
"""
millisecond: Int!
}

"""
Defines the structure of a duration of time.
"""
type Duration {
"""
The number of years in the duration.
"""
years: Int

"""
The number of months in the duration.
"""
months: Int

"""
The number of days in the duration.
"""
days: Int

"""
The number of hours in the duration.
"""
hours: Int

"""
The number of minutes in the duration.
"""
minutes: Int

"""
The number of seconds in the duration.
"""
seconds: Int

"""
The number of milliseconds in the duration.
"""
milliseconds: Int
}
1 change: 0 additions & 1 deletion interface/polywrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ project:
type: interface
source:
schema: ./polywrap.graphql
resources: ./resources
61 changes: 48 additions & 13 deletions interface/resources/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HTTP Wrapper Interface
# Datetime Wrapper Interface

| Version | URI | WRAP Version |
|-|-|-|
Expand All @@ -7,26 +7,61 @@
## Interface
```graphql
type Module {
"""
Returns the numeric value corresponding to the current time—the
number of milliseconds elapsed since January 1, 1970 00:00:00 UTC,
with leap seconds ignored.
"""
currentTimestamp: BigInt!
# Create a new datetime object for the current date and time.
now: Datetime

# Get the difference between two datetime objects.
diff(other: Datetime!): Datetime!

# Format the datetime object into a string.
format(datetime: Datetime!, fmt: String): String!

# Parse a string into a datetime object.
parse(datetimeStr: String!, fmt: String): Datetime!

# Add a duration to the datetime.
add(duration: Duration!): Datetime!

# Subtract a duration from the datetime.
subtract(duration: Duration!): Datetime!

# Get the Unix timestamp of the datetime.
toUnixTimestamp: UInt!

# Create a new datetime object from a Unix timestamp.
fromUnixTimestamp(timestamp: UInt!): Datetime
}

type Datetime {
year: Int!
month: Int!
day: Int!
hour: Int!
minute: Int!
second: Int!
millisecond: Int!
}

type Duration {
years: Int
months: Int
days: Int
hours: Int
minutes: Int
seconds: Int
milliseconds: Int
}
```

## Usage
```graphql
#import { Module } into Datetime from "ens/wraps.eth:datetime@1.0.0"

type Module implements Datetime_Module {}
#import * from "ens/wraps.eth:datetime@1.0.0"
```

And implement the `currentTimestamp` method within your programming language of choice.
And implement the interface methods within your programming language of choice.

## Source Code
[Link](https://github.com/polywrap/datetime)
[Link](https://github.com/polywrap/std/datetime)

## Known Implementations
[Link](https://github.com/polywrap/datetime/tree/master/implementations)
[Link](https://github.com/polywrap/datetime/tree/master/implementations)
Loading