fizx-uberchronic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +0 -0
- data/ext/extconf.rb +14 -0
- data/ext/get_date.c +24 -0
- data/lib/uberchronic.rb +16 -0
- data/test/uberchronic_test.rb +16 -0
- data/uberchronic.gemspec +23 -0
- metadata +69 -0
data/README
ADDED
File without changes
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV["ARCHFLAGS"] = "-arch #{`uname -p` =~ /powerpc/ ? 'ppc' : 'i386'}"
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
6
|
+
|
7
|
+
LIBDIR = Config::CONFIG['libdir']
|
8
|
+
INCLUDEDIR = Config::CONFIG['includedir']
|
9
|
+
myincl = %w[/usr/local/include /opt/local/include /usr/include]
|
10
|
+
mylib = %w[/usr/local/lib /opt/local/lib /usr/lib]
|
11
|
+
|
12
|
+
find_header('time.h', INCLUDEDIR, *myincl) or abort "need time.h"
|
13
|
+
|
14
|
+
create_makefile('get_date')
|
data/ext/get_date.c
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#include <time.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include "ruby.h"
|
4
|
+
|
5
|
+
VALUE _parse(VALUE, VALUE);
|
6
|
+
VALUE c_get_date;
|
7
|
+
|
8
|
+
void Init_get_date()
|
9
|
+
{
|
10
|
+
c_get_date = rb_define_class("GetDate", rb_cObject);
|
11
|
+
rb_define_singleton_method(c_get_date, "parse", _parse, 1);
|
12
|
+
}
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
_parse(VALUE self, VALUE str){
|
16
|
+
char *cstr = STR2CSTR(str);
|
17
|
+
struct tm * parsed = getdate(cstr);
|
18
|
+
|
19
|
+
if(parsed == NULL) {
|
20
|
+
return Qnil;
|
21
|
+
} else {
|
22
|
+
return INT2NUM(mktime(parsed));
|
23
|
+
}
|
24
|
+
}
|
data/lib/uberchronic.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "chronic"
|
3
|
+
require File.dirname(__FILE__) + "/../ext/get_date"
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
module Uberchronic
|
7
|
+
def self.parse(str)
|
8
|
+
if stamp = GetDate.parse(str)
|
9
|
+
puts stamp.inspect
|
10
|
+
return Time.at(stamp)
|
11
|
+
else
|
12
|
+
return Chronic.parse(str)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../lib/uberchronic"
|
3
|
+
|
4
|
+
class UberchronicTest < Test::Unit::TestCase
|
5
|
+
def test_parsing
|
6
|
+
assert_same_day Time.parse("Dec 15 1999"), Uberchronic.parse("december 15 1999")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_junk
|
10
|
+
assert_nil Uberchronic.parse("junk")
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_same_day(a, b)
|
14
|
+
assert (a - b).abs < 60 * 60 * 24
|
15
|
+
end
|
16
|
+
end
|
data/uberchronic.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "uberchronic"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2009-04-14"
|
5
|
+
s.summary = "Like chronic, plus GNU getdate to cover edge cases"
|
6
|
+
s.email = "kyle@kylemaxwell.com"
|
7
|
+
s.homepage = "http://github.com/fizx/"
|
8
|
+
s.description = "Like chronic, plus GNU getdate to cover edge cases"
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.require_paths = ["lib", "ext"]
|
11
|
+
s.extensions = "ext/extconf.rb"
|
12
|
+
s.authors = ["Kyle Maxwell"]
|
13
|
+
s.files = %w[
|
14
|
+
ext/extconf.rb
|
15
|
+
ext/get_date.c
|
16
|
+
lib/uberchronic.rb
|
17
|
+
test/uberchronic_test.rb
|
18
|
+
uberchronic.gemspec
|
19
|
+
]
|
20
|
+
s.rdoc_options = ["--main", "README"]
|
21
|
+
s.extra_rdoc_files = ["README"]
|
22
|
+
s.add_dependency("chronic", ["> 0.0.0"])
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fizx-uberchronic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Maxwell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: chronic
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
description: Like chronic, plus GNU getdate to cover edge cases
|
26
|
+
email: kyle@kylemaxwell.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- ext/extconf.rb
|
35
|
+
- ext/get_date.c
|
36
|
+
- lib/uberchronic.rb
|
37
|
+
- test/uberchronic_test.rb
|
38
|
+
- uberchronic.gemspec
|
39
|
+
- README
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/fizx/
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
- ext
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Like chronic, plus GNU getdate to cover edge cases
|
68
|
+
test_files: []
|
69
|
+
|