RSS
 

交换物说明

29 Nov

余《——你这个白痴要的包书纸

余《——ghost hunt小说

终《——哥哥的漫画(8)

终《——二线+卡片+徽章(书30+卡15+邮费7.5+徽章10 = 62.5)

余《——你上次留在我家的一堆书

终《——速写本(10)

余《——丝瓜水(自己带瓶子)

余《——头花(10)

余《——永远的漫画(8)

鹅《——耳环

fby——》小说

太太《——超合金漫画

syu《——眼唇卸妆

余——》只有神知道的世界,片

余《——头花(10)

Lucky《——绝望本

 
 

组团信息整理

25 Nov

1、蝴蝶结:http://store.taobao.com/?shop_id=64228006【任何时间】

2、反省会组团:

http://yychk.taobao.com/?spm=1100033175739.000000019492563.00000006157508624.47&search=y&scid=4675279&scname=zazIy9a%2B16jH%2BA%3D%3D&checkedRange=true&queryType=cat&stp=47

3、地铁拟人续本:CF2,天窗地址:http://doujin.bgm.tv/subject/4308(我CF2去不了,阿终如果去就帮我带)

4、生如夏花2:元旦(果断通贩)

5、Rei子的花札计划:未知

6、放牛班组团:http://cattleclass.taobao.com/?spm=1100064332631.0000000161890842.000000062912573523.2&orderType=_hotsell&search=y

7、日用品店组团:http://store.taobao.com/shop/view_shop.htm?shop_id=33465788【任何时候】

8、一眼千年2,CP9后一周预定

9、http://item.taobao.com/item.htm?spm=1103vwEM.3-1YiXC.h-2v2QJw&id=10162268951& 包,见面前一起买的话可以组团

 
 

给阿余和阿终的mark

24 Nov

1、首先是地铁拟人本,作者之一的洗澡不出热水,会出旧条漫+新漫的本子。CF2可能【12。25,如果谁去帮我带~】

2、鹅的和风本计划:http://vote.weibo.com/vid=1028922&source=feed【我觉得最近那家伙很不在状态。。】

3、我会在反省会通20i2 》》 http://hanseikai.yychk.com/?p=2625 和ayaki的普奥本【求组团,在20i2和普奥本完售前,猫鱼本也在那儿通贩】

反省会地址:http://yychk.taobao.com/?spm=1100033175739.000000019492563.00000006157508624.47&search=y&scid=4675279&scname=zazIy9a%2B16jH%2BA%3D%3D&checkedRange=true&queryType=cat&stp=47

4、福尔摩斯二季预计1月下旬播出

5、J子的闪电十一人本:http://fx.taobao.com/u/NTY0ODM0NjE=/tlive/taodan_detail.htm?item_id=13362247077&tracelog=frsinazt【这个给阿终看,J子还有HP和猎人的周边,但是我没那么同HP,而J子画的猎人不是很和我口味】

6、Rei子的花札计划:http://vote.weibo.com/vid=1187188&source=feed_info【我会入】

7、放牛班求组团,我想买空折本:http://cattleclass.taobao.com/?spm=1100064332631.0000000161890842.000000062912573523.2&orderType=_hotsell&search=y【但是并没有那么执着】

8、生如夏花2估计元旦出【通贩求组团】

9、鐵道少女漫畫 中村明日美子,花园出汉化了,你们自己搜或者找syu

10、我还在等[中村春菊]世界第一初戀~横澤隆史の場合~的txt版

11、口袋妖怪真人版第三弹: 卡比兽来了。 http://t.cn/SP7l87 【如果失效,可以自行去优酷搜】

12、通灵王复刊,一起等连载

13、巴贝拉出薄饼了,有空一起去。

14、小花【友人X】现在帮人做通贩,店里的猫老师周边很萌:http://item.taobao.com/item.htm?id=13625231405

15、求人陪看回转企鹅罐【人物形象是妖怪少女那位作者的】,然后陪我一起猜真相和结局。

16、永远那本我还没有买【上次不够了那次】,顺便永远那本的出版社【如果真的是出版社】就是最近很多的盗版盗墓本那家。所以我觉得我可能有点心理洁癖,想等别的版本。。orz如果谁需要可以先带走我手上这本,我下次买别的东西的时候可以再说。【纠结】

17、上课上到12。18,上专八上到12。24,考试考到12。28

18、请在周末一起看本子~延期至元旦后

19、我在这家店买花牌和按摩,求组团:http://store.taobao.com/shop/view_shop.htm?shop_id=33465788【下周内皆可】

20、如果要在孔夫子上买书,可以让我用我的账号买,攒点信誉。。。http://www.kongfz.com/

21、K猫出了再录本,还有好几本再刷,详见其天窗地址:http://doujin.bgm.tv/club/kiercat

23、彩铅秀秀的短篇再录:http://viiice.com/2011/11/bouquet/

 
 

Summary of Last Week’s Work

12 Sep

1. When I use FCKeditor and use its ‘upload image’ function, it just reset all of the explorer’s session values in the process! I have to find out how this plugin acts, and figure out a solution.

2. I am just rewrite all the lib files of FCKeditor’s php demo into rails ones. It is just not completed.

3. The output of decoding for string of store information in the section of sending short message to customer is wrong. The possible cause is the incorrect database encoding. I now leave the problem for Mr. He. He will try to swift the encoding to GBK instead of Utf-8. If it works… it’s really lucky! Or I will not know what to do.

 
No Comments

Posted in 工作

 

闭关的决定

12 Sep

因为今天没有拿到专四成绩单所以受了刺激。

网上说应该是九月上旬出分数,不过下周就要九月中旬了,所以心情不好,决定闭关

算是半开半闭区间……闭关内计划:

1、复习专八考试:可能看时间许可就去读冲刺班,今天同学也提到了,也可能去请老师,大家一起。平时一方面巩固日常语法,提高词汇量,多听听力,多写东西(欢迎为我的狗屁不通纠错),然后是人文方面的东西因为比较没方向,可能也会买书去做。

2、减肥:我一直很强调我的减肥目标是不要浪费任何一条裤子,所以你们懂的。

3、学习德语:以前没有学过二外,学了德语以后觉得学语言其实很欢乐,有点后悔本科时候没有去学。目标是把上下册教材弄熟弄通,然后看些课外的东西。我觉得代词形容词动词包括句法都是比较有规律的东西,只有狗屁的名词的阴阳性我TMD背不出来,反正目前只求看过眼能猜出来。

4、游戏组:跟H一起做游戏,据说RPGMaker其实很简单,目前还未研究。

5、番组计划:我可能只看PMBW了。其他都留档以后看。

取消或推延的计划:

1、新年卡片

2、埋坑

3、手工制作

 
No Comments

Posted in 日常

 

用ruby写了转txt编码的程序。gbk-》utf8

12 Sep
#!/usr/bin/env ruby
#require 'rubygems'
#require 'active_record'
require 'iconv'

input_path = 'input/'
output_path = 'output/'
if !File.directory? input_path
  path = File.expand_path(input_path)
  Dir.mkdir(input_path)
end
if !File.directory? output_path
  path = File.expand_path(output_path)
  Dir.mkdir(output_path)
end

docs = Dir.glob(input_path + '*')
#puts docs.inspect
for doc in docs do
  puts doc
  if File.file? doc
    puts 'in here'
    report = ''
    report_utf8 = ''
    File.open( doc,'r') do |f|
      report = f.read
    end
    begin
      puts 'start!'

      #name = File.split(path)[1]
      filename = output_path + File.basename(doc)
      puts filename

      #begin
      #  conv = Iconv.new("GBK", "utf-8")
      #  report_utf8 = conv.iconv(report)
      #rescue
      #end
      begin
        conv = Iconv.new("utf-8", "GBK")
        report_utf8 = conv.iconv(report)
      rescue
        puts File.basename(doc) + ' error'
      end
      puts 'ok'

      if report_utf8 && report_utf8 != ''
        if File.file?(filename)
          File.delete(filename)
        end

        File.open( filename, 'w') do |f|
          f.write report_utf8
        end
      end
    rescue
    end
  end
end
 
No Comments

Posted in 工作

 

search and lookup app in store on web

29 May

I plan to help my colleague to develop a web application to collect the apps I want to buy or recommend.

The first step is to search and find the web page containing the app information.

Take the tool named SOUNDSNAP for example,

The first step is to search it in api and get return string.

The Search URL is:

http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=soundsnap&entity=software

Then you get the return string like:

{ ”resultCount”:33, ”results”: [{"version":"1.0", "kind":"software", "artistId":428212975, "artistName":"Black Arc Studios", "price":0.00, "description":"\u2605\u2605\u2605 Free for this weekend only! \u2605\u2605\u2605 \n\n\u2605\u2605\u2605 Featured on Gizmodo &
Lifehacker AU! \u2605\u2605\u2605 Let your voice do the photo taking!!! (Or any sound for that matter!)\n\nSoundSnap is a simple
camera app that lets you take pictures by detecting ANY sound you make!. Simply tap, speak or make any sound into the built-in
microphone and SoundSnap will quickly snap a picture!  Better yet make use of your earphone headset or Bluetooth headset as a
remote!\n\n\n************\nRemote Control\n************\n\n\u2022 SoundSnap allows you to use your device\u2019s built-in microphone
to pick up sound from a distance! Now there\u2019s even more reason to say \u201CCheese\u201D!\n\u2022 Use your earphone headset
\u2019s microphone as a remote release cable!\n\u2022 For those who need precise wireless control, take advantage of your Bluetooth
headset as wireless remote!\n\n\n************\nPerfect for a variety of situations\n************\n\n\u2022 Too cold to take off your
gloves? No problems, with SoundSnap you can still snap a photo using just your voice!\n\u2022 Take advantage of the high quality rear
camera for self-portraits! No more fiddling around trying to find where the button is.\n\u2022 Reduce accidental shaking of the
camera when taking photos by not having to touch the device at all! \n\u2022 Mount your iPhone/iPod on a tripod and use your earphone
headset\u2019s microphone as remote release cable! Perfect for great night shots!\n\u2022 Take the perfect group photo when no one is
around to assist. For even more precision and timing of a snap, use a Bluetooth headset as a wireless remote!\n\u2022 Need to be
discreet when taking a photo? No problems. STEALTH mode will black out the screen to make it seem as though the device is off!\n\n
\n************\nKey Features\n************\n\n\u2022 Tap, speak or make any sound to snap a photo!\n\u2022 Adjust the sensitivity of
the sound detection! - Optimize the app for quiet or noisy environments.\n\u2022 Use your headset as a remote cable release!\n\u2022
Use your Bluetooth headset as a wireless remote!\n\u2022 Timer Mode \u2013 Give yourself time to perfect your pose before taking that
snap!\n\u2022 Stealth mode \u2013 For those times when discretion is needed!\n\n\n************\nCompatibility\n************
\nSoundSnap is compatible with the iPhone 4, iPhone 3GS and iPod Touch (4th Generation).\nFor Apple\u2019s built-in tap-to-focus
function to be active, iOS 4.3 is required.\n\n\n************\nWebsite\n************\nhttp://www.blackarcstudios.com/soundsnap",
"genreIds":["6008", "6002"], “releaseDate”:”2011-04-07T07:00:00Z”, “sellerName”:”Black Arc Studios Private Limited”,
“currency”:”USD”, “trackId”:428212972, “trackName”:”SoundSnap”, “genres”:["Photography", "Utilities"], “releaseNotes”:”",
“primaryGenreName”:”Photography”, “primaryGenreId”:6008, “isGameCenterEnabled”:false, “supportedDevices”:["iPhone-3GS", "iPhone4",
"iPhone", "iPad23G", "iPad2Wifi", "iPodTouchourthGen", "iPhone-3G"], “wrapperType”:”software”,
“artworkUrl60″:”http://a1.mzstatic.com/us/r1000/013/Purple/eb/8f/9d/mzi.erfyikae.png”,
“artworkUrl100″:”http://a4.mzstatic.com/us/r1000/035/Purple/14/a7/7f/mzm.tqzjqmrh.png”,
“artistViewUrl”:”http://itunes.apple.com/us/artist/black-arc-studios/id428212975?uo=4″, “contentAdvisoryRating”:”4+”,
“trackCensoredName”:”SoundSnap”, “trackViewUrl”:“http://itunes.apple.com/us/app/soundsnap/id428212972?mt=8&uo=4“,
“languageCodesISO2A”:["DE", "EN", "ES", "FR", "IT", "JA", "KO", "ZH"], “fileSizeBytes”:”10089479″, ”screenshotUrls”:["http://a1.mzstatic.com/us/r1000/027/Purple/68/c9/5b/mzl.ctnqyntv.png",
"http://a2.mzstatic.com/us/r1000/050/Purple/3c/93/2d/mzl.qfsdkame.png",
"http://a2.mzstatic.com/us/r1000/029/Purple/37/cf/95/mzl.vugmtqaz.png"], “ipadScreenshotUrls”:[],
“sellerUrl”:”http://www.blackarcstudios.com/soundsnap”, “averageUserRatingForCurrentVersion”:5.0,
“userRatingCountForCurrentVersion”:4, “artworkUrl512″:”http://a4.mzstatic.com/us/r1000/035/Purple/14/a7/7f/mzm.tqzjqmrh.png”,
“trackContentRating”:”4+”, “averageUserRating”:5.0, “userRatingCount”:4},
…………………………………………
{“version”:”1.3″, “kind”:”software”, “artistId”:298593066, “artistName”:”A&G Soluzioni Digitali”, “price”:0.99, ”description”:”This is binaural preview of Peoplelikesound’s Vol.1, the SD card for X-spat player created by A&G Soluzioni Digitali
from the original soundscape compositions by PEOPLELIKESOUND. Press the \”Track 1\” or \”Track 2\” button to start loop playback.
Slide the \”Tilt Listener\” slider  to activate the Open AL spatialisation.  Press the \”info button\” to acquire more information.”,
“genreIds”:["6011", "6013"], “releaseDate”:”2010-01-28T11:49:26Z”, “sellerName”:”A&G Soluzioni Digitali srl”, “currency”:”USD”,
“trackId”:352734137, “trackName”:”PLS1Binaural”, “genres”:["Music", "Healthcare & Fitness"], “releaseNotes”:”Added Support for IOS
4.2″, “primaryGenreName”:”Music”, “primaryGenreId”:6011, “isGameCenterEnabled”:false, “supportedDevices”:["all"],
“wrapperType”:”software”, “artworkUrl60″:”http://a1.mzstatic.com/us/r1000/000/Purple/e1/8f/39/mzi.pkhljhvt.png”,
“artworkUrl100″:”http://a4.mzstatic.com/us/r1000/027/Purple/a1/fc/f3/mzi.hiqsxxto.jpg”,
“artistViewUrl”:”http://itunes.apple.com/us/artist/a-g-soluzioni-digitali/id298593066?uo=4″, “contentAdvisoryRating”:”4+”,
“trackCensoredName”:”PLS1Binaural”, “trackViewUrl”:”http://itunes.apple.com/us/app/pls1binaural/id352734137?mt=8&uo=4″,
“languageCodesISO2A”:["EN"], “fileSizeBytes”:”22972246″, ”screenshotUrls”:["http://a2.mzstatic.com/us/r1000/041/Purple/fd/f8/7b/mzl.oihqgzxg.png",
"http://a1.mzstatic.com/us/r1000/022/Purple/ed/34/1b/mzl.uanybuuh.png",
"http://a3.mzstatic.com/us/r1000/013/Purple/2c/be/ca/mzl.uvsrdgzi.png",
"http://a4.mzstatic.com/us/r1000/024/Purple/05/bb/c8/mzl.wqclmgrk.png",
"http://a1.mzstatic.com/us/r1000/018/Purple/38/29/f4/mzl.wicymqzc.png"], “ipadScreenshotUrls”:[],
“sellerUrl”:”http://www.aegweb.it/pli1.html”, “averageUserRatingForCurrentVersion”:null, “userRatingCountForCurrentVersion”:null,
“artworkUrl512″:”http://a4.mzstatic.com/us/r1000/027/Purple/a1/fc/f3/mzi.hiqsxxto.jpg”, “trackContentRating”:”4+”,
“averageUserRating”:null, “userRatingCount”:null}]}

Get more detail information of how to understand the string in:

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

For me, only two things are important,

The first thing is trackId, which you can further used to compose the lookup url and info page url.

The second thing is trackViewUrl, which you can immediately used to link to the page for information.

Of course, the trackName and Black Arc Studios and price is also quite necessary.

 

Then, let’s come to the Lookup URL:

http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=428212972

You will get the return string like:

{ ”resultCount”:1, ”results”: [{"kind":"software", "artistId":428212975, "artistName":"Black Arc Studios", "price":0.00, "description":"\u2605\u2605\u2605 Free for this weekend only! \u2605\u2605\u2605 \n\n\u2605\u2605\u2605 Featured on Gizmodo &
Lifehacker AU! \u2605\u2605\u2605 Let your voice do the photo taking!!! (Or any sound for that matter!)\n\nSoundSnap is a simple
camera app that lets you take pictures by detecting ANY sound you make!. Simply tap, speak or make any sound into the built-in
microphone and SoundSnap will quickly snap a picture!  Better yet make use of your earphone headset or Bluetooth headset as a
remote!\n\n\n************\nRemote Control\n************\n\n\u2022 SoundSnap allows you to use your device\u2019s built-in microphone
to pick up sound from a distance! Now there\u2019s even more reason to say \u201CCheese\u201D!\n\u2022 Use your earphone headset
\u2019s microphone as a remote release cable!\n\u2022 For those who need precise wireless control, take advantage of your Bluetooth
headset as wireless remote!\n\n\n************\nPerfect for a variety of situations\n************\n\n\u2022 Too cold to take off your
gloves? No problems, with SoundSnap you can still snap a photo using just your voice!\n\u2022 Take advantage of the high quality rear
camera for self-portraits! No more fiddling around trying to find where the button is.\n\u2022 Reduce accidental shaking of the
camera when taking photos by not having to touch the device at all! \n\u2022 Mount your iPhone/iPod on a tripod and use your earphone
headset\u2019s microphone as remote release cable! Perfect for great night shots!\n\u2022 Take the perfect group photo when no one is
around to assist. For even more precision and timing of a snap, use a Bluetooth headset as a wireless remote!\n\u2022 Need to be
discreet when taking a photo? No problems. STEALTH mode will black out the screen to make it seem as though the device is off!\n\n
\n************\nKey Features\n************\n\n\u2022 Tap, speak or make any sound to snap a photo!\n\u2022 Adjust the sensitivity of
the sound detection! - Optimize the app for quiet or noisy environments.\n\u2022 Use your headset as a remote cable release!\n\u2022
Use your Bluetooth headset as a wireless remote!\n\u2022 Timer Mode \u2013 Give yourself time to perfect your pose before taking that
snap!\n\u2022 Stealth mode \u2013 For those times when discretion is needed!\n\n\n************\nCompatibility\n************
\nSoundSnap is compatible with the iPhone 4, iPhone 3GS and iPod Touch (4th Generation).\nFor Apple\u2019s built-in tap-to-focus
function to be active, iOS 4.3 is required.\n\n\n************\nWebsite\n************\nhttp://www.blackarcstudios.com/soundsnap",
"version":"1.0", "genreIds":["6008", "6002"], “releaseDate”:”2011-04-07T07:00:00Z”, “sellerName”:”Black Arc Studios Private Limited”,
“currency”:”USD”, “trackId”:428212972, “trackName”:”SoundSnap”, “genres”:["Photography", "Utilities"], “releaseNotes”:”",
“primaryGenreName”:”Photography”, “primaryGenreId”:6008, “isGameCenterEnabled”:false, “supportedDevices”:["iPodTouchourthGen",
"iPhone", "iPhone4", "iPhone-3G", "iPhone-3GS", "iPad23G", "iPad2Wifi"], “wrapperType”:”software”,
“artworkUrl60″:”http://a1.mzstatic.com/us/r1000/013/Purple/eb/8f/9d/mzi.erfyikae.png”,
“artworkUrl100″:”http://a4.mzstatic.com/us/r1000/035/Purple/14/a7/7f/mzm.tqzjqmrh.png”,
“artistViewUrl”:”http://itunes.apple.com/us/artist/black-arc-studios/id428212975?uo=4″, “contentAdvisoryRating”:”4+”,
“trackCensoredName”:”SoundSnap”, “trackViewUrl”:”http://itunes.apple.com/us/app/soundsnap/id428212972?mt=8&uo=4″,
“languageCodesISO2A”:["DE", "EN", "ES", "FR", "IT", "JA", "KO", "ZH"], “fileSizeBytes”:”10089479″, ”screenshotUrls”:["http://a1.mzstatic.com/us/r1000/027/Purple/68/c9/5b/mzl.ctnqyntv.png",
"http://a2.mzstatic.com/us/r1000/050/Purple/3c/93/2d/mzl.qfsdkame.png",
"http://a2.mzstatic.com/us/r1000/029/Purple/37/cf/95/mzl.vugmtqaz.png"], “ipadScreenshotUrls”:[],
“sellerUrl”:”http://www.blackarcstudios.com/soundsnap”, “averageUserRatingForCurrentVersion”:5.0,
“userRatingCountForCurrentVersion”:4, “artworkUrl512″:”http://a4.mzstatic.com/us/r1000/035/Purple/14/a7/7f/mzm.tqzjqmrh.png”,
“trackContentRating”:”4+”, “averageUserRating”:5.0, “userRatingCount”:4}]}

Parse it and get more information about the app.

Last, when you get the trackId, you can compose the url of info page like:

http://itunes.apple.com/app/id428212972

 
6 Comments

Posted in 工作

 

最近做的布艺的东西

21 May

最初是打算按照阿花的图做虎兔的手偶,结果很顺便地打算做千代她爸。结果到现在什么都没有做,只做了千代她爸……

 
No Comments

Posted in 日常

 

新年新计划,每年都天窗。

17 Feb

虽然说现在说计划有点晚,但是我这次是下定决心的!【狗P……】

第一件事请就是考试,专四的事情,相关话题就是每天做【TMD】练习。书已经都买了,阅读完形听力语法写作都有,反正我一向推崇题海战术。基础归基础,能力归能力,但是考试靠的还有习惯和手感……【境界吧!】

第二件事情就是【TMD】减肥,因为过一个年【老子】又胖了!而且好死不死买了条S的裙子【找抽啊!】决定以此为目标减肥。【去死吧!】相关话题就是每天做运动【要命啊!】决定每天早上做广播体操,每天晚上跑步。跑步每天增加10步,100步起算。

第三件事情就是埋坑【无所谓了】,过年的时候只埋了6927算是情人节应景什么的。最近写文废话越来越多……求超展开!不过考据也很重要……求超展开!相关话题就是每日考据【我了个去】或者每日看书。我发现还是看纸质的书保护眼镜【TMD废话!】所以在想以后轻轨上是看书还是看动画【救命啊!】

第四件事是有关绘图【更加浮云了……】反正我是临摹党【求超展开!】最近因为想配衣服下载了很多米娜,于是开始画米娜的衣服。【浮云啊!】相关话题就是每天画一件衣服。【P啊!】

第五件事就是求脱团!就算遭到报复我也要求脱团啊!

【完毕……】

 
No Comments

Posted in 日常

 

datetime是个讨厌的东西

29 Jul

datetime是个讨厌的东西

最近基本上就在纠结这个问题了。
第一个问题是,invalid date
第二个问题是,如何传参
第三个问题是,时区

一、

关于第一个问题,当在rails中使用date_select控件的时候,以下为例

true%>
true%>

将会得到参数

"end_at"=>{"my_date(1i)"=>"2010", "my_date(2i)"=>"7", "my_date(3i)"=>"29"}, "start_at"=>{"my_date(1i)"=>"2010", "my_date(2i)"=>"2", "my_date(3i)"=>"31"}

这里存在的问题是,因为产生的控件是一个简单控件,不带有script,所以,当你选择年月日的时候,后续选择不过因为闰年或者月份的不同而改变。也就是说,你可以选择一个2月31日的日期,而它忠实地将这个参数传回。

我曾经写过一个函数来处理这些参数,将它变成一个日期的变量,如下:

def self.hash_to_date(obj,prefix)
Date.new(obj["#{prefix}(1i)"].to_i,obj["#{prefix}(2i)"].to_i,obj["#{prefix}(3i)"].to_i)
end

而这所遇到的问题是,当它接收到一个2月31日时会直接出错。

之后我使用了一个名为DatePicker的插件,它的输出结果为形如‘2010-10-10’的字符串,而合法的字符串通过to_date函数也能直接变成时间。
但这个插件在某些浏览器下并不正常,因为,我也允许手动输入时间串。
这样就同样有了如上所述的invalid date的情况,除非使用更加严格的验证函数。

然而有一点是可以肯定的,当你所选的内容将被存入数据库的时候,rails能够很好的处理它。
我翻找了很久并没有找到它是如何处理的,所以做了一个折中的做法,新建一个model,专门处理时间。

起初,我设想,这个model有且只有一个字段,也就是时间,名为my_date。最简单的方法是使用attr_accessor。
然后,attr_accessor似乎无法处理datetime这种复杂的数据类型,是故一直报错:1 error(s) on assignment of multiparameter attributes
并且,因为没有相关表,必须tableless掉,于是也可能有一定影响,深入未考。

后来我想到了tableless时候的做法。
我可以首先tableless掉,然后添加一个column。
这段代码我在上次探索tableless的时候已经找到了,其内容如下:

class ConvertDate < ActiveRecord::Base
def self.columns
@columns ||= [];
@columns << ActiveRecord::ConnectionAdapters::Column.new('my_date', nil,
'datetime', true)
end
end

使用的方式为:view依旧如之前所示,在controller中处理如下:

@start_date = ConvertDate.new(params[:start_at]).my_date
@end_date = ConvertDate.new(params[:end_at]).my_date

这样就解决的得到合法时间的问题。

二、

关于第二个问题,如果使用rails的date_select控件,那么,可以看到,参数多而杂,而如果使用之前提到的DatePicker则参数相对简单。
如果在一次post中,复杂的参数也许并不如何,但是,如果在get中,特别是在结合了排序和翻页之类的功能,参数列表就会显得长而繁杂。

所以我在考虑是否在两者间进行转化,通过class函数来判断:
如果是hash,直接new,如果是string,先进行转化。
而在传参之前,也可以尝试将hash转化为string,然后向后传。
不过这一点,我还没有深入来做。

三、

关于时区问题,因为在enviroment.rb中配置了:

config.time_zone = 'Beijing'

所以就会产生时区问题。

当建立一条记录的时候,当你包含了time_stamp,你就会发现,数据库中存储的是utc时间,当你使用user.created_at取出的时候,则会得到一个包含时区信息的时间类型,时间与你所期望的吻合。

然后来看一下其他几个函数
首先是to_date和to_datetime
日期部分的合法模式是2010.1.1或2010/1/1或2010-1-1
时间部分为0:0:0

还有一些简单的时间操作为 + 1.year/month/day/hour/minute/second
可以‘+’也可以‘-’,后面可以加s,也可以不加,不过要注意,数字和点和量词连写,并且前后空格,否则容易出错。

当我们使用to_date函数一下子无法看出时区信息,那么我们加上几个小时
那么就会发现to_date产生后运算后的时间是8时区,而,如果使用to_datetime则是0时区

同样对于Date.new的结果也是8时区的,而DateTime.new的结果是0时区的。

最后才是最纠结的问题,一个我一直没有发现的大问题。
例如,当数据库的utc时间为4,也么8时区时间是12,于是我们尝试用8时区的11点和13点来筛选数据,发现一切出乎了想象。

>> User.last
=> #
>> User.last.created_at
=> Thu, 29 Jul 2010 12:23:06 CST +08:00

>> b='2010.7.29'.to_date + 11.hour
=> Thu Jul 29 11:00:00 +0800 2010
>> c='2010.7.29'.to_date + 13.hour
=> Thu Jul 29 13:00:00 +0800 2010

>> User.last(:conditions=>['created_at > ?',b])
=> nil
>> User.last(:conditions=>['created_at #
>> User.last(:conditions=>['created_at > ?',c])
=> nil
>> User.last(:conditions=>['created_at #

我曾经认为是用12点多,和11点13点这三个时间比较,结果发现它才没有那么智能。
也就是说,大于11点,无,小于11点,有,大于13点,无,小于13点,有。
也就是说,其实它是用4点多和11点和13点在比较。

解决这个问题的方法,要么:
1、不设时区,在显示时转换
2、使用to_date和Date.new,并在选择的时候使用selected_time.utc来转换时区

另外,补充
Date只有today,没有now
DateTime只有now,没有today
两个的yesterday都是8时区。

于是,纠结暂完。

 
13 Comments

Posted in 工作

 
Page 1 of 212