Blog

MDM Zinc – Class DateManager for ftp and filesystem

Ok, here is a class to be able to get the same date format for your files on your system and on the ftp (not the case for now)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 /*
* Class written by Xavier MARTIN (xxlm or zeflasher)
* http://dev.webbymx.net
* http://www.webbymx.net
* If you are using this class, I will be glad to receive a postcard of your place :)
* To do so please visit http://dev.webbymx.net and go in the about page to get my details...
*/

class net.webbymx.zinc.DateManager {
//  ftp to full date
  public static function ftpDate (d : String) : Date {
  //  spliting the string
    var tmpDateTime : Array = d.split (" ");
  //  working with time
    var hour : Number = parseInt (tmpDateTime [1].split (":")[0]);
    var minute : Number = parseInt (tmpDateTime [1].split (":")[1]);
    if (tmpDateTime [2] == "PM") hour += 12;
    if (hour == 24) hour = 0;
    var tmpArray : Array = tmpDateTime [0].split ("/");
    var buffer : String = tmpArray [0];
    tmpArray [0] = parseInt (tmpArray [1]);
    tmpArray [1] = parseInt (buffer) - 1;
    tmpArray [2].length > 2 ? tmpArray [2] = parseInt (tmpArray [2]) : tmpArray [2] = parseInt ("20" + tmpArray [2]);
    tmpArray [3] = hour;
    tmpArray [4] = minute;
    var tmpDate : Date = new Date (tmpArray [2] , tmpArray [1] , tmpArray [0] , tmpArray [3] , tmpArray [4]);
    return tmpDate;
  }
 
 
  public static function fileDate (d : String, t : String) : Date {
  //  spliting the string
    var tmpArray : Array = d.split ("/");
  //  dealing with time
    var clock : Array = t.split (":");
    var hour : Number = parseInt (clock [0]);
    if (hour == 24) hour = 0;
    var minute : Number = parseInt (clock [1]);
  //  setting up the array
    tmpArray [0] = parseInt (tmpArray [0]);
    tmpArray [1] = parseInt (tmpArray [1]) - 1;
    tmpArray [2] = parseInt (tmpArray [2]);
    tmpArray [3] = hour;
    tmpArray [4] = minute;
  //  sending back the date object
    var tmpDate : Date = new Date (tmpArray [2] , tmpArray [1] , tmpArray [0] , tmpArray [3] , tmpArray [4]);
    return tmpDate;
  }
}

[Download id not defined]

  • C

    It would be nice if there was some usage info for this classes, just need to spend hours trying to figure out what the methods are etc… Otherwise I am sure it works great.

  • C

    It would be nice if there was some usage info for this classes, just need to spend hours trying to figure out what the methods are etc… Otherwise I am sure it works great.

  • zeflasher

    I’ve done this code a long time ago, but I managed to find a post in the mdm forum having a small example
    http://www.mdmforum.com/forum/index.php?showtopic=14382&hl=

  • zeflasher

    I’ve done this code a long time ago, but I managed to find a post in the mdm forum having a small example
    http://www.mdmforum.com/forum/index.php?showtopic=14382&hl=

  • Turanligil

    Hello i work with Zend 3.0… in your DateManager exists a ftpDate Function -> d:String… how do you commit the date to the function …. when i use http://ftp.getFileDateTime i get “Aug 28 16:41” 

    HOW do you get the format dd/mm/yyyy in your d String? i get crazy 🙂 is it possible that this is a zinc 3.0 Bug at the getFileDateTime??? please help

  • Anonymous

    It’s been so long, I can’t remember but I know that the link in the comments links to an example. Also this class is used in a FTP manager class (which I’ve done also, available probably on the blog or on mdm forum under zeflasher).
    Sorry I can’t be more help.

    ++

  • Turanligil

    i saw this example… in the example for ftp is used the code on bottom. The Problem is, that yourFileArray[i][1] returns “Aug 26 16:41” and not “dd/mm/yyyy” like in your example 🙂 i don’t now WHY i have this format 🙁 bummer… i thought maybe you remember 🙂 thanks anyway…
    for (var i:Number = 0; i<yourFileArray.length; i++) {yourFileArray[i][1] = DateManager.ftpDate(yourFileArray[i][1]);}

  • Anonymous

    Hello Turanligil,

    Well this class has been created against the MDM Zinc API 2.5, so if you are using the 3.0 the function to get the date might return the date formated differently. I would think that they provide some options to format the date now… I will check tomorrow (12.30AM here) and let you know.

    Have a good day.

  • Anonymous

    Hello Turanligil,

    Well this class has been created against the MDM Zinc API 2.5, so if you are using the 3.0 the function to get the date might return the date formated differently. I would think that they provide some options to format the date now… I will check tomorrow (12.30AM here) and let you know.

    Have a good day.

  • Anonymous

    Hello Turanligil,

    Well this class has been created against the MDM Zinc API 2.5, so if you are using the 3.0 the function to get the date might return the date formated differently. I would think that they provide some options to format the date now… I will check tomorrow (12.30AM here) and let you know.

    Have a good day.

  • Anonymous

    Hello Turanligil,

    Well this class has been created against the MDM Zinc API 2.5, so if you are using the 3.0 the function to get the date might return the date formated differently. I would think that they provide some options to format the date now… I will check tomorrow (12.30AM here) and let you know.

    Have a good day.