Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1038774 // BackupFileAge - calculates how old a backup file is in days from the file name

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10856L/60K).

1  
sclass BackupFileAge {
2  
  // minutes (last group) are optional
3  
  settable S pattern = "^(.*)\\.backup(2\\d\\d\\d)(\\d\\d)(\\d\\d)-(\\d\\d)(\\d*)$";
4  
  
5  
  settable S fileName;
6  
  
7  
  settable TimeZone timeZone = defaultTimeZone();
8  
  settable long currentTime = now();
9  
  
10  
  S originalName;
11  
  int year;
12  
  int month;
13  
  int day;
14  
  int hour;
15  
  int minute;
16  
  long time;
17  
  gettable double ageInDays;
18  
  
19  
  bool parse() {
20  
    var pat = regexp(pattern);
21  
    var matcher = pat.matcher(fileName);
22  
    if (!matcher.find()) false;
23  
    
24  
    originalName = matcher.group(1);
25  
    year = matcherInt(matcher, 2);
26  
    month = matcherInt(matcher, 3);
27  
    day = matcherInt(matcher, 4);
28  
    hour = matcherInt(matcher, 5);
29  
    minute = matcherInt(matcher, 6);
30  
    time = timestampFromYMDHM(year, month, day, hour, minute, timeZone);
31  
    ageInDays = ((currentTime-time)/1000.0/60/60/24;
32  
    true;
33  
  }
34  
}

Author comment

Began life as a copy of #1011269

download  show line numbers  debug dex  old transpilations   

Travelled to 1 computer(s): mqqgnosmbjvj

No comments. add comment

Snippet ID: #1038774
Snippet name: BackupFileAge - calculates how old a backup file is in days from the file name
Eternal ID of this version: #1038774/8
Text MD5: 9c1fc30477f690e1fd7ab47abcc467ee
Transpilation MD5: dd6da15bfd2d3d24cb5143f9bb12537a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2025-04-20 18:25:53
Source code size: 905 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 30 / 80
Version history: 7 change(s)
Referenced in: [show references]