MagicNumbers

  • Tags : domainclass
  • Latest : 0.2.3
  • Last Updated: 27 February 2012
  • Grails version : 1.1 > *
  • Authors : null
4 votes
Dependency :
compile ":magic-numbers:0.2.3"

Documentation

Summary

Installation

grails install-plugin magic-numbers

Description

MagicNumbers Plugin

Author: Bjoern Wilmsmann, MetaSieve

This plugin adds numerous time calculation convenience methods to both the Integer and Long classes.

Usage

This plugin is inspired by Ruby on Rails' ActiveSupport library.

It adds several time and byte calculation methods that for example allow you to do cool things like:

2.minutes
1.hour
4.weeks
2.months.fromNow
6.years.ago
3.fortnights.ago.toDate()
640.kilobytes

The following fields have been added:

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • fortnights
  • months
  • fromNow
  • ago
  • kilobytes
  • megabytes
  • gigabytes
  • terabytes
  • petabytes
  • exabytes
The following methods have been added:
  • toDate()
  • toSeconds()
  • ordinalize()
Each of the time span fields returns the milliseconds that time span takes (e.g. 60000 for 2.minutes). The byte fields return the number of bytes for kilobytes, megabytes etc. As 1.minute looks much nicer than 1.minutes each field is available in a singular version, too.

fromNow / ago return the milliseconds since the epoch of the current date plus / minus the given time span.

The toDate() method returns a new Date instance from the milliseconds since the epoch.

The toSeconds() methods yields the respective number of seconds (instead of milliseconds) for each value.

The ordinalize() method returns on ordinal number for a cardinal number like:

  • '1st' for 1.ordinalize()
  • '2nd' for 2.ordinalize()
  • '105th' for 105.ordinalize()

Plugin version history

See http://jira.codehaus.org for more information