FluroDate

FluroDate

A static service that provides useful functions for working with dates and timestamps.

Methods

(static) dateFromID(id, format, timezone) → {String}

Source:
Parses an ObjectID and returns the date of creation
Example
var id = '5ca3d64dd2bb085eb9d450db' 
return dateFromID.formatDate(id, 'D M YYYY')
Parameters:
Name Type Description
id String The id of the object to parse
format String A string representing the format to output for formatting syntax see https://momentjs.com/docs/#/displaying/format/
timezone String The timezone to use if needing to translate the date to another timezone eg. Australia/Melbourne
Returns:
A human readable string
Type
String

(static) formatDate(date, format, timezone) → {String}

Source:
Parses a date and returns a human readable date string
Example
var date = new Date()
return FluroDate.formatDate(date, 'h:mma DDD MMM YYYY')

var dateString = '2019-04-18T23:00:00.000Z' 
return FluroDate.formatDate(dateString, 'D M YYYY', 'Australia/Melbourne')
Parameters:
Name Type Description
date Date | String The date or string to parse
format String A string representing the format to output for formatting syntax see https://momentjs.com/docs/#/displaying/format/
timezone String The timezone to use if needing to translate the date to another timezone eg. Australia/Melbourne
Returns:
A human readable string
Type
String

(static) isMultiDayEvent(event) → {Boolean}

Source:
Checks whether an event spans over multiple days
Example
return fluro.date.isMultiDayEvent({startDate:...})
Parameters:
Name Type Description
event Object A Fluro event object with a startDate and an endDate
Returns:
True or False if the event spans multiple days
Type
Boolean

(static) localDate(date, specifiedTimezone) → {Date}

Source:
A function that will return a date in context of a specified timezone If no timezone is specified then the default timezone of the current clock will be used. This will return dates that are incorrect on purpose. So that it can appear to the user as if they were in another timezone. As Javascript dates are always in the context of the timezone they are being viewed in, this function will give you a date that is technically not the Universal point in time of the date, but rather a time that reads in your timezone as if you were in the specified timezone.
Parameters:
Name Type Description
date Date Either a javascript date object, or a string timestamp representing a javascript date object
specifiedTimezone String The timezone to retrieve the date in eg. Australia/Melbourne
Returns:
A javascript date object transformed to match the specified timezone
Type
Date

(static) readableEventDate(event, style) → {String}

Source:
A helper function that can display a human-readable date for an event taking into consideration the context of the current time, the event's start and end time. This is often used as a string filter and what is relevant
Example
//Returns 5:30pm 1 May
FluroDate.readableEventDate({"startDate": "2019-05-01T07:30:00.000Z", "endDate":"2019-05-01T07:30:00.000Z"})
//Returns 5:30pm - 7:30pm 1 May
FluroDate.readableEventDate({"startDate": "2019-05-01T07:30:00.000Z", "endDate":"2019-05-01T09:30:00.000Z"})
//Returns 1 - 5 May 2015
FluroDate.readableEventDate({"startDate": "2015-05-01T07:30:00.000Z", "endDate":"2015-05-05T09:30:00.000Z"})
//1 May - 21 Jun 2019
FluroDate.readableEventDate({"startDate": "2019-05-01T07:30:00.000Z", "endDate":"2019-06-21T09:30:00.000Z"})
Parameters:
Name Type Description
event Object An object that has both a startDate and endDate property, Usually an event object from the Fluro API
style String Whether to return a 'short', 'medium' or 'long' date
Returns:
The human readable date for the event
Type
String

(static) readableEventTime(event) → {String}

Source:
A helper function that can display a human-readable time for an event taking into consideration the context of the current time, the event's start and end time. This is often used as a string filter
Example
//Returns 5:30pm
FluroDate.readableEventTime({"startDate": "2019-05-01T07:30:00.000Z", "endDate":null})
//Returns 5:30pm - 7:30pm
FluroDate.readableEventTime({"startDate": "2019-05-01T07:30:00.000Z", "endDate":"2019-05-01T09:30:00.000Z"})
Parameters:
Name Type Description
event Object An object that has both a startDate and endDate property, Usually an event object from the Fluro API
Returns:
The human readable time for the event
Type
String

(static) timeago(date) → {String}

Source:
Parses a date and returns a 'timeago' string
Example
var date = new Date()

//Returns 10 mins ago
return fluro.date.timeago(date)
Parameters:
Name Type Description
date Date | String The date or string to parse
Returns:
A human readable string
Type
String

(static) timezones() → {Array}

Source:
A function that returns all of the available timezones. Often used to populate a select box
Returns:
An array of all availble timezones.
Type
Array