Time Stamper Class

Append a time prefix or suffix to FileNames

This class is used to produce prefix or suffix to be appended before or after file name (for one of many situations where files differ only by a date and time stamp embedded in the file name).
This script is part of the Poor Man's SMS project that you can download here, or get more info there.

File Name : TimeStamperCLS.js
Requirement : none
Author : Branimir Petrovic
Submitted : 19/09/2002
Category : Class

To use a class, follow this syntax :
var MyObjClass = new MyClass;
WScript.Echo(MyObjClass.MyMethod());
//  FileName:   TimeStamperCLS.js
//////////////////////////////////////////////////////////////////////
if (WScript.ScriptName == "TimeStamperCLS.js") demo_TimeStamperCLS();

// ======================== CLASS ====================================
function TimeStamperCLS() {
//  Author:     Branimir Petrovic
//  Date:       9 January 2002
//  Version:    1.1.0
//
//  Revision History:
//      9 January 2002      V 1.0.0
//      13 January  2002    V 1.1.0     Added getVersion() method
//
//
//  This class is used to produce prefix or suffix to be appended
//  before or after file name (for one of many situations where files
//  differ only by a date and time stamp embedded in the file name).
//
//  Methods:
//      - getClassName()
//      - getVersion()              //  Returns version string "1.1.0"
//      - getNow([oDate])
//      - getYYYYMMDD([oDate])
//      - getHHMMSS([oDate])
//      - getFullAsPostfix([oDate])
//      - getFullAsPrefix([oDate])
//
//  Note:
//      All methods accept object of type Date in which case time stamps
//      are based on this object's value. If methods are called without
//      any param, then each call will create new Date object and return
//      its "stringified" value.

    //  --- Private Data Members ---
    var SELF = "TimeStamperCLS";
    var VERSION = "1.1.0";
    var oDate;

    //  --- Public Methods ---
    this.getClassName = function () {return SELF; }
    this.getVersion = function () { return VERSION; }
    this.getNow = getNow;
    this.getYYYYMMDD = getYYYYMMDD;
    this.getHHMMSS = getHHMMSS;
    this.getFullAsPostfix = getFullAsPostfix;
    this.getFullAsPrefix = getFullAsPrefix;


    //  ---------------- Functions Implementing Public Methods -------
    function getNow(oD) {
        // duplicates VBScript's getNow() functionality, returns string
        if (isDate(oD)) oDate = oD;
        else oDate = new Date();

        var sNow =  padWithZero(oDate.getDate());
        sNow += " " + toNamedMonth(oDate.getMonth()+1); 
        sNow += " " + oDate.getFullYear() + "  ";
        sNow += padWithZero(oDate.getHours()) + ":";
        sNow += padWithZero(oDate.getMinutes()) + ":";
        sNow += padWithZero(oDate.getSeconds());
        return sNow; // >>>
    }   
    //  --------------------------------------------------------------
    function getYYYYMMDD(oD) {
        if (isDate(oD)) oDate = oD;
        else oDate = new Date();

        var sNow = oDate.getFullYear();
        sNow += padWithZero(oDate.getMonth()+1);
        sNow += padWithZero(oDate.getDate());
        return sNow;
    }
    //  --------------------------------------------------------------
    function getHHMMSS(oD) {
        if (isDate(oD)) oDate = oD;
        else oDate = new Date();

        var sNow = padWithZero(oDate.getHours());
        sNow += padWithZero(oDate.getMinutes());
        sNow += padWithZero(oDate.getSeconds());
        return sNow;
    }
    //  --------------------------------------------------------------
    function getFullAsPostfix(oD) {
        //  returns date as _20010808_174905
        if (isDate(oD)) oDate = oD;
        else oDate = new Date();

        return "_" + getYYYYMMDD(oDate) + "_" + getHHMMSS(oDate);
    }
    //  --------------------------------------------------------------
    function getFullAsPrefix(oD) {
        //  returns date as 20010808_174905_
        if (isDate(oD)) oDate = oD;
        else oDate = new Date();

        return getYYYYMMDD(oDate) + "_" + getHHMMSS(oDate) + "_";
    }

    //  ---------------- Private helper functions --------------------
    function toNamedMonth(iMonth) {
        switch (iMonth) {
            case 1: return "January";
            case 2: return "February";
            case 3: return "March";
            case 4: return "April";
            case 5: return "May";
            case 6: return "Jun";
            case 7: return "July";
            case 8: return "August";
            case 9: return "September";
            case 10: return "October";
            case 11: return "November";
            case 12: return "December";
            default: return iMonth;
        }
    }
    //  --------------------------------------------------------------
    function padWithZero(iNum) {
        if (iNum<10) iNum = "0" + iNum;
        return iNum.toString();
    }   
    //  --------------------------------------------------------------
    function isDate(oDate) { try { return oDate.constructor==Date; } catch(e) { return false; } }

}   // ======================== END OF CLASS =========================


//  ==================================================================
function demo_TimeStamperCLS() {
    var oTS = new TimeStamperCLS();
    var sMsg = "oTS.getNow() -> \t\t" + oTS.getNow() + "\n";
    sMsg += "oTS.getYYYYMMDD() -> \t" + oTS.getYYYYMMDD() + "\n";
    sMsg += "oTS.getHHMMSS() -> \t" + oTS.getHHMMSS() + "\n";
    sMsg += "oTS.getFullAsPostfix() -> \t" + oTS.getFullAsPostfix() + "\n";
    sMsg += "oTS.getFullAsPrefix() -> \t" + oTS.getFullAsPrefix() + "\n";
    WScript.Echo(sMsg);
}
//  ==================================================================
Server Info
Remote Info
Compress

Batchs
BootSector
Droit
Accessoire GFA
On Now
Ecran plasma
Système d'exploitation
Son
Unités
Scripting
Multilingue
Site Web
Bruit et son
Architecture Google


4K
Color picker
TaskList
Backup files
Mini Port Scanner
Website To CHM
PixyDemo
Web password recovery
4KWebServer
Kill Popup
VBE decoder
Script Optimizer
Database Password Recovery
Class
Ini
EMail validator
Graphical Class
MP3 Info
Pinger Class
IP ranger class
SoftwareMetering
Path Validator
Time Stamper Class
LoggerCLS
HTA
Keyword Ranking
DOM Explorer
HTA-Notepad
PixyPortManager
Other
flashMessage
Kill Popup
VBE decoder (fixed)
Error Codes
Maze generator
Char counter
HTML To Word
ICQ Choose User
ScreenSaver Password decoder
Mp3Playlister - singleList
Long Filename To Short
Trace Math
Dump Hexa File
Self modifying script
Mp3Playlister - multiList
HTANoid
PixyWebServer
Python
Progress indication

©2002 Jean-Luc Antoine. All Rights Reserved. Scripts or any other material on this website may not be redistributed or put as part of ANY collection (script archives, CDs etc) without prior written permission. Permission granted to use and modify any of the scripts found on InterClasse.com